2014-02-09 30 views
0

我正在尝试使用php &使用Dreamweaver的sql制作网页。我在Web开发中没有编码经验。将sql seach的搜索结果传递给变量

我制作了一个显示数据库搜索结果的页面。现在这个结果将被放置在一个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>&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> 
+0

我建议你看看Laravel,简单的网页开发令人难以置信。 –

+0

你有没有试过我的答案呢? – user2397282

回答

1

你要遍历您的搜索结果,并使用$行[]下得到该字段名称存储的值。这里是一个例子

$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']来获得变量。

编辑:这将是非常有用的,如果你可以张贴你已经尝试过的一些代码。

+0

我的搜寻结果将只显示单排三列日期,追踪号码及编号 –

+0

如果您只有一行,此功能仍然有效。 – user2397282

+0

是否需要填写$ con的详细信息?我有一个包含所有这些细节的PHP文件。有没有办法使用这些信息?我想这会增加安全性 –