我正在尝试使用php&使用Dreamweaver的SQL。我没有网络开发的编码经验。
我创建了一个显示数据库搜索结果的页面。现在出现的结果将放在URL&我认为可以做到的唯一方法是,如果我能够将搜索结果存储在变量&在URL中连接它。但我无法这样做,因为我不知道如何传递出现的搜索结果。
谢谢
<?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> </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>
答案 0 :(得分:1)
您希望循环搜索结果并使用$ row []获取存储在该字段名称下的值。这是一个例子
$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
你在webpage.php中使用$ _GET ['variable']来获取变量。
编辑:如果您可以发布一些已经尝试过的代码,那将非常有用。