-2

I'd like to know is there a function that reads the url from the browser after that running a code; for example I've this php code:

echo "<a href='mypage.php?product=123456'>Search Result</a>";

when hovering on the link the url should be like this:

http://yourdomain.com/mypage.php?product=123456

I want to retrieve data from the database of the search result that have a row contains:

123456

but let me explain to you; let's say those are the search results

  • 1
  • 2
  • 3
  • 4
  • 5

when hovering on the first result the url in the browser will be like this:

http://www.yourdomain.com/mypage.php?product=1

I want to display all the data from the table that have a row which contains "1" by clicking on the result

thanks for helping me.

4

2 回答 2

2

你可以通过,

$id = $_GET['product'];

而不是触发查询来检索数据

$stmt = $pdo->prepare('SELECT * FROM table WHERE id = :id');
$stmt->execute(array(':id' => $id));
于 2013-06-07T09:32:09.290 回答
0

要一劳永逸地把它放在床上:

第一页:

//create the links:
$html=""
$sql="SELECT id,description FROM table";
$result=$mysqlidb->query($sql);
while($row=$result->fetch_assoc())
    {
    $html.=sprintf("<a href='mypage.php?product=%s'>%s</a><br>",$row['id'],$row['description']);
    }
echo $html;

第二页(mypage.php)

$product=mysqli_real_escape_string($mysqlidb,$_GET['product']);
$sql="SELECT * FROM table WHERE id='$product'"; //or use prepared statement but in this case this is faster;
$result=$mysqlidb->query($sql);
$row=$result->fetch_assoc();

$row 现在包含您需要的信息,可以使用 sprintf 将其插入到您的 html 格式中,如下所示:

$html=sprintf("<SPAN id='1'>%s</SPAN><SPAN id='2'>%s</SPAN>...",$row['somestuff'],$row['otherstuff']);

它的外观将取决于您如何格式化各种 html 输出。

于 2013-06-07T10:58:55.923 回答