I have developed a search facility on my site which is now working as intended and produces pages of relevent records from the search. On the resuly pages I have created href links for records that I wish to use to forward users to a detailed html page for their item. I am planning on doing this using adetail.php script where the id will be taken and used to identify the corresponding file. Only problem is I've never done this before do I just post the id in and change the header part accordingly?
PHP Detail page help
Collapse
X
-
Hi.
If I am understanding you correctly, you only need to create a <a> link that points to your addetail.php, including the ID of the item you want to view.
Then, in the addetail.php, you use the $_GET super-global to get the ID and get the item information.
For example: (doing this in one page, but you get the idea)
[code=php]
<?php
# Get and validate the itemID
$itemID = $_GET['itemID'];
if($itemID != abs($itemID) or $itemID <= 0) {
echo("<p>Item ID is invalid.</p>");
}
else {
# Get and display data from MySQL
$result = mysql_query("SE LECT * FROM myTable WHERE id = $itemID");
while($row = mysql_fetch_ass oc($result)) {
echo "<b>Item details:</b><br>";
foreach($row as $key => $value) {
echo " - $key = $value<br>";
}
}
}
?>
<a href="thisPage. php?itemID=1">S how details</a>
[/code] -
Originally posted by AtliHi.
If I am understanding you correctly, you only need to create a <a> link that points to your addetail.php, including the ID of the item you want to view.
Then, in the addetail.php, you use the $_GET super-global to get the ID and get the item information.
For example: (doing this in one page, but you get the idea)
[code=php]
<?php
# Get and validate the itemID
$itemID = $_GET['itemID'];
if($itemID != abs($itemID) or $itemID <= 0) {
echo("<p>Item ID is invalid.</p>");
}
else {
# Get and display data from MySQL
$result = mysql_query("SE LECT * FROM myTable WHERE id = $itemID");
while($row = mysql_fetch_ass oc($result)) {
echo "<b>Item details:</b><br>";
foreach($row as $key => $value) {
echo " - $key = $value<br>";
}
}
}
?>
<a href="thisPage. php?itemID=1">S how details</a>
[/code]
It is kind of what I'm aiming for. In my previuos post you were kind enough to help out with also, I had a search form accessing my database to extract all relevent records for criteria. I have a link established for each search output which is..
[code=php]
echo "<div id=\"right\"><i mg src=\"".$info['image']."\"><a href=\"detail.p hp\">".$info['title']."</a></div>\n";
[/code]
but it's linking it through detail.php I need to establish. What to put in detail.php?Comment
-
If you'd put the code I posted (leave out the link tho) into your details.php, you could change your links to this, in order to get it working:
[code=php]
echo "<div id=\"right\"><i mg src=\"".$info['image']."\"><a href=\"detail.p hp?itemID=". $info['id']. "\">".$info['title']."</a></div>\n";
[/code]
Assuming that your $info array includes the ID of the item to show.Comment
Comment