0

这是显示记录的 view.php 文件。我使用了更新和删除记录查询。Dreamweaver 不包含内置的替换记录查询。如何更换记录?我需要查询替换行。/////////////

 <?php require_once('Connections/db_sms.php'); ?>
    <?php
    if (!isset($_SESSION)) {
      session_start();
    }
    $MM_authorizedUsers = "";
    $MM_donotCheckaccess = "true";

    // *** Restrict Access To Page: Grant or deny access to this page
    function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
      // For security, start by assuming the visitor is NOT authorized. 
      $isValid = False; 

      // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
      // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
      if (!empty($UserName)) { 
        // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
        // Parse the strings into arrays. 
        $arrUsers = Explode(",", $strUsers); 
        $arrGroups = Explode(",", $strGroups); 
        if (in_array($UserName, $arrUsers)) { 
          $isValid = true; 
        } 
        // Or, you may restrict access to only certain users based on their username. 
        if (in_array($UserGroup, $arrGroups)) { 
          $isValid = true; 
        } 
        if (($strUsers == "") && true) { 
          $isValid = true; 
        } 
      } 
      return $isValid; 
    }

    $MM_restrictGoTo = "login.php";
    if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
      $MM_qsChar = "?";
      $MM_referrer = $_SERVER['PHP_SELF'];
      if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
      if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
      $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
      $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
      header("Location: ". $MM_restrictGoTo); 
      exit;
    }
    ?>
    <?php require_once('Zend/Date.php');?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    $currentPage = $_SERVER["PHP_SELF"];



    $maxRows_rsStudent = 3;
    $pageNum_rsStudent = 0;
    if (isset($_GET['pageNum_rsStudent'])) {
      $pageNum_rsStudent = $_GET['pageNum_rsStudent'];
    }
    $startRow_rsStudent = $pageNum_rsStudent * $maxRows_rsStudent;

    mysql_select_db($database_db_sms, $db_sms);
    $query_rsStudent = "SELECT s_id, first_name, last_name, gender, dob, father_name, email, address, city, student_photo FROM tbl_student ORDER BY first_name ASC";
    $query_limit_rsStudent = sprintf("%s LIMIT %d, %d", $query_rsStudent, $startRow_rsStudent, $maxRows_rsStudent);
    $rsStudent = mysql_query($query_limit_rsStudent, $db_sms) or die(mysql_error());
    $row_rsStudent = mysql_fetch_assoc($rsStudent);

    if (isset($_GET['totalRows_rsStudent'])) {
      $totalRows_rsStudent = $_GET['totalRows_rsStudent'];
    } else {
      $all_rsStudent = mysql_query($query_rsStudent);
      $totalRows_rsStudent = mysql_num_rows($all_rsStudent);
    }
    $totalPages_rsStudent = ceil($totalRows_rsStudent/$maxRows_rsStudent)-1;

    $queryString_rsStudent = "";
    if (!empty($_SERVER['QUERY_STRING'])) {
      $params = explode("&", $_SERVER['QUERY_STRING']);
      $newParams = array();
      foreach ($params as $param) {
        if (stristr($param, "pageNum_rsStudent") == false && 
            stristr($param, "totalRows_rsStudent") == false) {
          array_push($newParams, $param);
        }
      }
      if (count($newParams) != 0) {
        $queryString_rsStudent = "&" . htmlentities(implode("&", $newParams));
      }
    }
    $queryString_rsStudent = sprintf("&totalRows_rsStudent=%d%s", $totalRows_rsStudent, $queryString_rsStudent);
    ?>

    <?php


    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
           if ($theValue == "")
          {
              $theValue = "NULL";
          }
          else
          {
              $zendDate = new Zend_Date($theValue, "M/d/yyyy");
              $theValue = "'" . $zendDate->toString("yyyy-MM-dd") . "'";
          }
            break;

        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    ?>
    <style type="text/css">
    body,td,th {
        color: #000;
        font-family: "Courier New", Courier, monospace;
        font-size: 18px;
    }
    body {
        background-color: #FFF;
    }
    a:link {
        text-decoration: none;
    }
    a:visited {
        text-decoration: none;
        color: #606;
    }
    a:hover {
        text-decoration: underline;
        color: #066;
    }
    a:active {
        text-decoration: none;
        color: #600;
    }
    </style>

    <body bgcolor="#D6D6D6" text="#FFFFFF" link="#330000" vlink="#006666" alink="#660000"><h1>
      <style type="text/css">
    #header {
        font-family: "Times New Roman", Times, serif;
        font-size: 24px;
        font-style: normal;
        line-height: normal;
        font-weight: normal;
        text-transform: none;
        color: #066;
        background-color: #FFF;
        background-image: url(../images/contest.jpg);
        background-repeat: no-repeat;
        background-size: auto;
        box-sizing: content-box;
        margin-bottom: 400px;
    }
    body,td,th {
        font-family: "Courier New", Courier, monospace;
        color: #000;
    }
    body {
        background-color: #FFF;
    }
      </style>
    </h1>
     <?php /* include('include/header.php');*/?> 

    <h3>&nbsp;</h3>
    <h3>There are <?php echo $totalRows_rsStudent ?> Students.</h3>
    <p>&nbsp;
      <?php if ($pageNum_rsStudent > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_rsStudent=%d%s", $currentPage, 0, $queryString_rsStudent); ?>">First</a> <a href="<?php printf("%s?pageNum_rsStudent=%d%s", $currentPage, max(0, $pageNum_rsStudent - 1), $queryString_rsStudent); ?>">Previous</a>
        <?php } // Show if not first page ?>
      <?php if ($pageNum_rsStudent < $totalPages_rsStudent) { // Show if not last page ?>
      <a href="<?php printf("%s?pageNum_rsStudent=%d%s", $currentPage, min($totalPages_rsStudent, $pageNum_rsStudent + 1), $queryString_rsStudent); ?>">Next</a> <a href="<?php printf("%s?pageNum_rsStudent=%d%s", $currentPage, $totalPages_rsStudent, $queryString_rsStudent); ?>">Last</a>
      <?php } // Show if not last page ?>
    </p>
    <table width="400" border="0">

    </table>
    <form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
    <table width="2139" border="0">

        <tr>
          <th width="326" bgcolor="#009999" scope="col"><strong>First Name</strong></th>
          <th width="315" bgcolor="#009999" scope="col"><strong>Last Name</strong></th>
          <th width="282" bgcolor="#009999" scope="col"><strong>Gender</strong></th>
          <th width="183" bgcolor="#009999" scope="col"><blockquote>
            <p> <strong>BirthDate</strong></p>
          </blockquote></th>
          <th width="337" bgcolor="#009999" scope="col"><strong>Father's Name</strong></th>
          <th width="271" bgcolor="#009999" scope="col"><strong>Email</strong></th>
          <th width="95" bgcolor="#009999" scope="col"><strong>Address</strong></th>
          <th width="150" bgcolor="#009999" scope="col"><strong>City</strong></th>
          <th width="150" bgcolor="#009999" scope="col"><blockquote>
            <p>Photo</p>
          </blockquote></th>
          <th width="150" bgcolor="#009999" scope="col">&nbsp;</th>
          <th width="7" bgcolor="#009999" scope="col">&nbsp;</th>
          <th width="131" scope="col">&nbsp;</th>
        </tr>
         <?php do { ?>
       <?php 
                $zendDate = new Zend_Date($row_rsStudent['dob']);
              ?>

        <tr>
          <td bgcolor="#333333"><blockquote>
            <p><a href="update.php?s_id=<?php echo $row_rsStudent['s_id']; ?>"><?php echo $row_rsStudent['first_name']; ?></a></p>
          </blockquote></td>
          <td bgcolor="#333333"><blockquote>
            <p><?php echo $row_rsStudent['last_name']; ?></p>
          </blockquote></td>
          <td bgcolor="#333333"><blockquote>
            <p><?php echo $row_rsStudent['gender']; ?></p>
          </blockquote></td>
          <td bgcolor="#333333"> 
              <?php echo $zendDate->toString("d/M/yyyy"); ?></td>
          <td bgcolor="#333333"><blockquote>
            <p><?php echo $row_rsStudent['father_name']; ?></p>
          </blockquote></td>
          <td bgcolor="#333333"><blockquote>
            <p><?php echo $row_rsStudent['email']; ?></p>
          </blockquote></td>



          <td bgcolor="#333333"><blockquote>
            <p><em><strong><a href="delete.php?s_id=<?php echo $row_rsStudent['s_id']; ?>"></a></strong></em><?php echo $row_rsStudent['address']; ?></p>
          </blockquote></td>
          <td bgcolor="#333333"><blockquote>
            <p><em><strong><a href="delete.php?s_id=<?php echo $row_rsStudent['s_id']; ?>"></a></strong></em><?php echo $row_rsStudent['city']; ?></p>
          </blockquote></td>
          <td bgcolor="#333333"><blockquote>
            <p><img src="<?php echo "thumbnails/".$row_rsStudent['student_photo']; ?>"/> </p>
          </blockquote></td>
          <td bgcolor="#FFFFFF"><blockquote>
            <p><em><strong><a href="delete.php?s_id=<?php echo $row_rsStudent['s_id']; ?>">Delete</a></strong></em></p>
          </blockquote></td>
        </tr>
        <?php } while ($row_rsStudent = mysql_fetch_assoc($rsStudent)); ?>
      </table>
      <p><strong><a href="insert.php">Insert New Record</a></strong></p>
      <p>&nbsp;</p>
    </form>
    <?php
    mysql_free_result($rsStudent);
    ?>

//////// 我的 db_sms 连接文件 ///////

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_db_sms = "localhost";
$database_db_sms = "db_sms";
$username_db_sms = "root";
$password_db_sms = "";
$db_sms = mysql_pconnect($hostname_db_sms, $username_db_sms, $password_db_sms) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

////////

这是 db_sms.sql 文件

phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 06, 2012 at 05:07 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `db_sms`
--
CREATE DATABASE `db_sms` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `db_sms`;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_admin`
--

CREATE TABLE IF NOT EXISTS `tbl_admin` (
  `admin_id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  PRIMARY KEY (`admin_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `tbl_admin`
--

INSERT INTO `tbl_admin` (`admin_id`, `username`, `password`) VALUES
(1, 'root', 'root');

-- --------------------------------------------------------

--
-- Table structure for table `tbl_student`
--

CREATE TABLE IF NOT EXISTS `tbl_student` (
  `s_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `gender` varchar(50) NOT NULL,
  `dob` date NOT NULL,
  `father_name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `student_photo` varchar(255) NOT NULL,
  PRIMARY KEY (`s_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

--
-- Dumping data for table `tbl_student`
--

INSERT INTO `tbl_student` (`s_id`, `first_name`, `last_name`, `gender`, `dob`, `father_name`, `email`, `address`, `city`, `student_photo`) VALUES
(3, 'Zara', 'Mansoor', 'Female', '0000-00-00', 'mmmm', 'zara@xyz.com', 'dddd', 'dddd', 'pic_1074.jpg'),
(4, 'Narima', 'Khaleeq', 'Female', '0000-00-00', 'khaleeq', 'uswa@xyz.com', 'wwww', 'wwww', ''),
(13, 'bina', 'ali', 'Female', '0000-00-00', 'ali', 'b@y.com', 'pakistan', 'taxila', ''),
(6, 'maryam', 'khan', 'Female', '1987-08-15', 'javed', 'abc@xyz.com', 'fff', 'ffff', ''),
(8, 'mohan', 'jjjj', 'Male', '0000-00-00', 'jjjjjj', 'rabia@yyy.com', 'sddwd', 'ddf', ''),
(17, 'Kalsoom', 'Mint', 'Female', '0000-00-00', 'bbb', 'kk@abc.com', 'sss', 'uuu', ''),
(15, 'rrrr', 'tttt', 'Male', '0000-00-00', '3eee', 'aa@fff.com', 'eee', 'eee', ''),
(16, 'jhjhjj', 'Khan', 'Female', '0000-00-00', 'ddwdw', 'ewdwd@dhwk.com', 'ddqd', 'ddewf', '');
4

1 回答 1

0

Byreplace record 你的意思是改变一些已经插入数据库的行吗?然后

UPDATE ... SET ...=... WHERE ...=...

命令是你要找的

于 2012-12-06T05:19:59.123 回答