I'm not entirely sure I'm even asking this correctly. I have a lack of terminology, and I apologize for that up front. You see, I have two php scripts, and I'm trying to learn how php and MySQL work together. In my first php script, order.php, I pull information from my database and display it on the page. Under each item that is pulled, there is a "more info" button. My goal is to have a user click on "more info" for any particular item, and when they do, be redirected to a new page that lists THAT items information.
So far, I have the "more info" button linking to a moreinfo.php script, and it is retrieving THAT items description using urlencode, and displaying it on moreinfo.php.
What I need, is to have the "more info" button on "order.php" pull THAT items description, name, and price.
I've tried adding:
. urlencode($row['description']) . urlencode($row['price']) .
to the code below, and it pulls in the information, but I can't separate it. Here is my code for everything so far.
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
", 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>";
Currently, it is pulling the description and price together, and I have no idea how to separate into different tables. If anyone can even give me a keyword to google, I would gladly look up the info on my own, or do whatever I can to research it to get it working.
Here is the 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>";
?>
Look at how other sites do the same thing. IE StackOverflow. On the main page, there is a list of questions. When you click a question, that question appears and all data associated with it.
The link to this particular question is http://stackoverflow.com/questions/20622290
.
The number at the end of the URL is this questions ID in the database, or some numerical representation of this question anyways.
I would suggest adding the ID of your item to the end of your URLs. IE, http://example.com/moreinfo.php?id=5
.
Where 5
is the ID of that item you want to see. This will allow you to grab that items information from the database and you will be able to display it.