PDA

View Full Version : Getting product Name and Price from DB


rickytheraccoon
September 27th, 2003, 04:18 PM
Let's say I have a preview page that displays 8 items, each with the product name, price, and a brief description.

Right now I have it coded to where the name and price are entered automatically from a text file, but I realized since these variables are exactly the same as the ones entered into the squirrelcart database, it would be a lot more efficient to call them from that. (I know this is what the squirrelcart does normally anyways but I have basically taken out all of the dynamic category driven navigation and incorporated the needed elements in html).

So my question is what code do I insert into my preview pages to "get" the variables for $name, $price, and $breif_description from the DB. I've been looking through the show_products func and came across:

function get_product($prod_rn) {

$product = get_records("Products","*","record_number = '$prod_rn'");
return $product[0];
}


But I'm not sure exactly what this is returning and how I can echo the variables after it does get them. Any advice would be greatly appreciated.

Mike

Jamie
October 10th, 2003, 11:46 AM
First, you would need the record number of the item in the DB. Once you have that, do this:

<?
// assume record number is 123
$product = get_records("Products","*","record_number = 123");

/* this function is designed to return all records satisfying the where statement....so it returns each record in an array, indexed numerically like so:

$product[0] - first record
$product[1] - second record
etc...

because you are only grabbing one record, you need to reference $product[0], like so
*/

$product = $product[0];

/* now, all the field values for this item are stored in the $product array, like this:
$product['Name'] - name of product
$product['Description'] - description of product
etc....

so, to output the info, do this
*/

print "Product name is ".$product['Name']."<br>";
?>

-Jamie