| | |
Small catalog problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2006
Posts: 69
Reputation:
Solved Threads: 1
hi, i am trying to make a simple catalog website without checkout. the user clicks on a product he want and it's displaced on another page...simple. the first page (the one with the product list) has the following code...
on the next page (viewprod.php) i have no idea what to put on the page to call up the product clicked. i know i read it in my books but i cant find it anywhere...can someone help?
Thanks
p.s. sorry if this is a dumb question
PHP Syntax (Toggle Plain Text)
<?php $sql = "SELECT * FROM products"; $result = mysql_query($sql); if (!$result) { echo "Error - query: $sql - " . mysql_error(); exit; } while ($row = mysql_fetch_array($result)) { echo "<p class='rc_textAreatext'><a href='viewprod.php?id=" . $row['prod_name']. "'>" . $row['prod_name'] . "</a> - " . $row['description'] . " $" .$row['price'] . "</p>"; } ?>
on the next page (viewprod.php) i have no idea what to put on the page to call up the product clicked. i know i read it in my books but i cant find it anywhere...can someone help?
Thanks
p.s. sorry if this is a dumb question
Place a hidden field in your script relating to the item in the record set that you are calling, and use something like this:
on your viewprod.php get the value of the item passed in the URL
then show the values from the record set on the screen
php Syntax (Toggle Plain Text)
<a href="viewprod.php?ID=<?php echo $rs['ID']; ?>"target="_blank"><strong>View</strong></a>
php Syntax (Toggle Plain Text)
$colname_rs_ID = "-1"; if (isset($_GET['ID'])) { $colname_rs_ID = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']); } mysql_select_db($database, $conn); $query_rs_ID = sprintf("SELECT * FROM your_db_table WHERE ID = %s", $colname_rs_ID); $rs_ID = mysql_query($query_rs_ID, $conn) or die(mysql_error()); $row_rs_ID = mysql_fetch_assoc($r_ID); $totalRows_rs_ID = mysql_num_rows($rs_ID);
php Syntax (Toggle Plain Text)
<input type="hidden" name="ID" value="<?php echo $row_rs_ID['ID']; ?>" /> <?php echo $row_rs_ID['ID']; ?>
I keep hitting "escape", but I'm still here!!!!
:}
:}
just use the get method to retrieve the info from the previous page;
php Syntax (Toggle Plain Text)
//I suppose you have the connection here.... $id=$_GET['id']; $sql = "SELECT * FROM products WHERE id='$id'"; $result = mysql_query($sql); if (!$result) { echo "Error - query: $sql - " . mysql_error(); exit; } $id=mysql_result($result,0,"id"); $name=mysql_result($result,0,"prod_name"); $desc=mysql_result($result,0,"description"); $price=mysql_result($result,0,"price"); echo "ID:".$id."<br>"; echo "NAME:".$name."<br>"; echo "DESCRIPTION:".$desc."<br>"; echo "PRICE:".$price."<br>";
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
•
•
•
•
PHP Syntax (Toggle Plain Text)
while ($row = mysql_fetch_array($result)) { echo "<p class='rc_textAreatext'><a href='viewprod.php?id=" . $row['prod_name']. "'>" . $row['prod_name'] . "</a> - " . $row['description'] . " $" .$row['price'] . "</p>"; }
after that, in your product page do:
if(isset($_GET['id']))
{
$id = $_GET['id'];
// show details for this ID
}
else
{
echo "Sorry!!! We don't have this product!"
}
•
•
Join Date: May 2006
Posts: 69
Reputation:
Solved Threads: 1
•
•
•
•
just use the get method to retrieve the info from the previous page;
php Syntax (Toggle Plain Text)
//I suppose you have the connection here.... $id=$_GET['id']; $sql = "SELECT * FROM products WHERE id='$id'"; $result = mysql_query($sql); if (!$result) { echo "Error - query: $sql - " . mysql_error(); exit; } $id=mysql_result($result,0,"id"); $name=mysql_result($result,0,"prod_name"); $desc=mysql_result($result,0,"description"); $price=mysql_result($result,0,"price"); echo "ID:".$id."<br>"; echo "NAME:".$name."<br>"; echo "DESCRIPTION:".$desc."<br>"; echo "PRICE:".$price."<br>";
•
•
Join Date: May 2006
Posts: 69
Reputation:
Solved Threads: 1
@ryan_vietnow
i have tried the code out but i have one question. Whats the point of adding the "0" to
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 5 on MySQL result index 3 in D:\AppServ\www\Study_Practice\Test_Sites\Shopping Cart\showitem.php on line 22
i'm just wondering is all. from what i get, the point of the "0" is to tell mysql which row to start searching. if i'm mistaken pls correct me
i have tried the code out but i have one question. Whats the point of adding the "0" to
($result,0,"id"); and the other lines? i erased the "0" when i was testing the code and there seemed to be no difference. when i changed the number to 5 or something else i get the folloting error:Warning: mysql_result() [function.mysql-result]: Unable to jump to row 5 on MySQL result index 3 in D:\AppServ\www\Study_Practice\Test_Sites\Shopping Cart\showitem.php on line 22
i'm just wondering is all. from what i get, the point of the "0" is to tell mysql which row to start searching. if i'm mistaken pls correct me
yes,that is correct,"0" is the row(which means first)
where the result of the query will be displaying.
if I put there 1,it means that the data from the 2nd row will be displayed.
where the result of the query will be displaying.
if I put there 1,it means that the data from the 2nd row will be displayed.
![]() |
Similar Threads
- Tutorial: Understanding ASP classes (ASP)
- Windows Update problem (Windows Vista and Windows 7)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- not-a-virusadware (Viruses, Spyware and other Nasties)
- more "home search assistent" fun... (Viruses, Spyware and other Nasties)
- My site is not keeping peoples intrests (Website Reviews)
Other Threads in the PHP Forum
- Previous Thread: problem solved sort of
- Next Thread: Dynamic content and printer pages
| Thread Tools | Search this Thread |
ajax apache api array beginner binary broken cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip java javascript joomla limit link login loop mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop regex remote script search server sessions sms soap source space sql strip_tags subversion support! survey syntax system table template tutorial update upload url validation validator variable video web window.onbeforeunload=closeme; xml youtube





