MySQL/PHP中的记录集链接

MySQL/PHP中的记录集链接,php,mysql,hyperlink,Php,Mysql,Hyperlink,我有一个PHP页面ship_info.PHP,显示数据库中特定船舶的信息。每艘船都按其唯一的船号进行排序 我需要在页面上获得链接,以按字母顺序转到上一个或下一个船舶。有人建议我使用一个名为gotoship.php的单独php文件。所以现在我在上一个链接上有了这个链接: <!--go to previous ship--> <div class="arrow_shipinfo_left"> <a href="gotoship.php?action=prev

我有一个PHP页面ship_info.PHP,显示数据库中特定船舶的信息。每艘船都按其唯一的船号进行排序

我需要在页面上获得链接,以按字母顺序转到上一个或下一个船舶。有人建议我使用一个名为gotoship.php的单独php文件。所以现在我在上一个链接上有了这个链接:

  <!--go to previous ship-->
  <div class="arrow_shipinfo_left">
  <a href="gotoship.php?action=previous&amp;current_ship_id=<?php echo $row_ship_image_info['ship_id']; ?>">
<img src="images/arrow_left.png" width="51" height="57" alt="back" border="none"/>
  </a>
  </div>
因此,我最终得到了一个类似“gotoship.php?action=previous¤t\u ship\u id=7”的链接。我不能让gotoship.php正常工作,有人能告诉我哪里出了问题吗。现在我得到一个数组到字符串的转换错误。我需要链接到这样一个页面shipinfo.php?ship_id=7

我的gotoship.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;
}
}

mysql_select_db($database_ships, $ships);
$query_ships = "SELECT TOP 1        ships.ship_id FROM   ship_information  INNER   JOIN (         SELECT ship_name FROM ship_information WHERE ship_id = $_GET'current_ship_id'        ) As current_ship     ON ships.ship_name < current_ship.ship_name ORDER BY ships.ship_name ASC";
$ships = mysql_query($query_ships, $ships) or die(mysql_error());
$row_ships = mysql_fetch_assoc($ships);
$totalRows_ships = mysql_num_rows($ships);
echo $current_ship_id;
 echo "<br><br>";
?>

这对sql注入是开放的。你应该阅读这意味着什么,你应该考虑切换到PDO或至少MySQL。只要查询本身正确,该查询就会根据GET?ship_id=[此处的id]中提供的id选择一个ship


这对sql注入是开放的。你应该阅读这意味着什么,你应该考虑切换到PDO或至少MySQL。只要查询本身正确,该查询就会根据GET?ship_id=[此处的id]中提供的id选择一个ship


嘿,擎天柱,谢谢你,非常彻底的代码。。。我现在得到这个错误,虽然。。。您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,了解在第1行的“1 ships.ship\u id FROM ship\u information internal JOIN SELECT ship\u name FRO”附近使用的正确语法。。。。。你认为这是我想要达到的目标的正确途径吗。多谢各位much@user2406993-你的问题是错误的。我不能解决这个问题。剩下的答案是回答你最初的问题。嘿,擎天柱,谢谢你,非常彻底的代码。。。我现在得到这个错误,虽然。。。您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,了解在第1行的“1 ships.ship\u id FROM ship\u information internal JOIN SELECT ship\u name FRO”附近使用的正确语法。。。。。你认为这是我想要达到的目标的正确途径吗。多谢各位much@user2406993-你的问题是错误的。我不能解决这个问题。剩下的答案是回答你最初的问题。
mysql_select_db($database_ships, $ships);
$query_ships = "
SELECT ships.ship_id
FROM ship_information
INNER JOIN (
    SELECT ship_name 
    FROM ship_information 
    WHERE ship_id = '$_GET[ship_id]')
    AS current_ship
    ON ships.ship_name < current_ship.ship_name 
ORDER BY ships.ship_name ASC";
$ships = mysql_query($query_ships, $ships) or die(mysql_error());
$row_ships = mysql_fetch_assoc($ships);
$totalRows_ships = mysql_num_rows($ships);
echo $current_ship_id;
echo "<br><br>";