2013-12-16 32 views
0

我不完全確定我甚至正確地問了這個問題。我缺乏術語,我對此表示歉意。你看,我有兩個PHP腳本,我試圖學習如何PHP和MySQL一起工作。在我的第一個PHP腳本order.php中,我從我的數據庫中提取信息並將其顯示在頁面上。在每個拉出的項目下,都有一個「更多信息」按鈕。我的目標是讓用戶點擊任何特定項目的「更多信息」,當他們這樣做時,被重定向到列出THAT項目信息的新頁面。使用第一個腳本中的「更多信息」按鈕將數據拉入第二個腳本

到目前爲止,我有更多信息按鈕鏈接到一個更多的info.php腳本,它使用urlencode檢索項目描述,並在moreinfo.php上顯示它。

我需要的是在「order.php」上的「更多信息」按鈕拉取項目描述,名稱和價格。

我試着加入:

. urlencode($row['description']) . urlencode($row['price']) . 

下面的代碼,並將其拉中的信息,但我不能分開吧。這是我迄今爲止所做的一切的代碼。

require("database.php"); //connect to the database 

$start = (isset($_GET['start']) ? (int)$_GET['start'] : 0); //setting the get function to a variable so I can display data on same page 

$result = mysqli_query($con,"SELECT * FROM menuitem LIMIT $start, 3"); 
    if (!$result) { 
     printf("Error: %s\n", mysqli_error($con)); 
     exit(); 
    } 

echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'> 
<tr align='center'> 
<th></th> 
<th>Menu Items</th> 
<th>Description</th> 
<th>Price</th> 
<th>Add to Order</th> 
</tr>"; 

while($row = mysqli_fetch_array($result)) 
{ 
    echo "<tr>"; 
    echo "<td align='center'><img height='100' width='100' src=\"" . $row['picturepath'] . "\" /></td>"; 

    echo '<td align="center">' . $row['name'] . '</td>'; 
    /*echo '<td align="center"><input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) .' \';" /></td>';*/ 
    echo '<td align="center"><input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) . urlencode($row['price']) .' \';" /></td>'; 

    echo "<td align='center'>" . $row['price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 

目前,它是拉動描述和價格一起,我不知道如何分成不同的表。如果任何人甚至可以給我一個谷歌的關鍵字,我會很樂意查閱我自己的信息,或盡我所能研究它,以使其工作。

這裏是moreinfo.php

$start = (!empty($_GET['start']) ? $_GET['start'] : false); 

<html><table width='100%' border='0'><tr><td height="200"></td></tr></table></html> 

<?php 
echo "<table width='90%' border='0' cellpadding='10' cellspacing='5' align='center'>" 
echo "<tr align='center'> 
     <td width='60%' align='left'>" . $start . "</td> 
     <td width='40%' align='left'>" "</td> 
     </tr>"; 
echo "</table>"; 
?> 

回答

0

看看其他網站是如何做同樣的事情。 IE StackOverflow。在主頁上,有一個問題清單。當你點擊一個問題時,會出現該問題以及與其相關的所有數據。

這個問題的鏈接是http://stackoverflow.com/questions/20622290

URL末尾的數字就是數據庫中的這個問題ID,或者是這個問題的一些數字表示。

我會建議將您的物品的ID添加到您的網址的末尾。 IE,http://example.com/moreinfo.php?id=5

其中5是您想要查看的項目的ID。這將允許您從數據庫中獲取這些項目信息,並且您將能夠顯示它。

相關問題