dongqiao1151 2014-02-09 16:11
浏览 60
已采纳

将sql搜索的搜索结果传递给变量

I am trying to make a webpage using php & sql using Dreamweaver. I have no coding experience in web development.

I have made a page which displays search results from database. Now this result which comes up is to be placed in a URL & the only way I have thought that this can be done is if I am able to store the search result in a variable & concatenate it in the URL. But I am unable to do so as I have no idea how to pass the search result which comes up.

Thanks

<?php require_once('Connections/check_mag.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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
    $name_Recordset1 = 12;
    $name_Recordset1 = $_GET['searchinput'];
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";
if (isset($_GET['searchinput'])) {
  $colname_Recordset1 = $_GET['searchinput'];
}
mysql_select_db($database_check_mag, $check_mag);
$query_Recordset1 = sprintf("SELECT * FROM consignments WHERE `reference no` = %s", GetSQLValueString($colname_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $check_mag) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
  <tr>
    <td>date</td>
    <td>tracking no</td>
    <td>reference no</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['date']; ?></td>
      <td><?php echo $row_Recordset1['tracking no']; ?></td>
      <td><?php echo $row_Recordset1['reference no']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p>&nbsp;</p>

<a href="http://mywebsite.com/page?name=<?php echo $name_Recordset1; ?>"></a>

<?php
$trackingcode =  $_GET["searchinput"];
echo $trackingcode;
$name = $_GET['tracking no']; 
echo $name; 
?>
<a href="http://www.xyz.com/content/in/en/express/tracking.shtml?brand=xyz&AWB=<?php echo  $trackingcode ?>"><?php echo $trackingcode?></a>
<br/>


</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongwu5743 2014-02-09 16:22
    关注

    You want loop through your search results and use $row[] to get the value stored under that field name. Here is an example

    $con=mysqli_connect("host","name","pass","database"); 
    
    // Connect   
    
    $sql="SELECT * FROM table_name";
    $result=mysqli_query($con, $sql);
    
    // Perform mysqli_query and store result
    
    while ($row = $result->fetch_assoc()) {
        $variable = $row['field_name'];
    }
    
    // Loop through and store value in variable
    
    $url = "http://www.webpage.php?variable=" . $variable";
    
    // Store variable in URL
    

    And you use $_GET['variable'] in webpage.php to get the variable.

    EDIT: It would be really helpful if you could post some code of what you have already tried.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测