singspiel Posted January 23, 2004 Share Posted January 23, 2004 I am creating a magazine page within Oscommerce, to encourage sales in my site. I would like to be able to pull in information from the database, such as the price individually per product. This page would be static apart from these live fields so that if i change the price in the admin and it changes it on this page also. I was trying to start with something like:- <?php $result = mysql_query( "SELECT products_price FROM products WHERE products_id = 42"); ?> <p><?php echo"$result" ?> I have already called in application_top for native osc commands, but I don't know how to display just the price from products_id number 42 for example. Any help would be greatly appreciated. Nev Link to comment Share on other sites More sharing options...
mtimdog Posted January 23, 2004 Share Posted January 23, 2004 $result=mysql_fetch_array(mysql_query(...)); echo $result[products_price]; or extract($result); echo $products_price; Link to comment Share on other sites More sharing options...
singspiel Posted January 28, 2004 Author Share Posted January 28, 2004 Thats Great thanks. Is there a way that I can pull in all the prices for example, and pull the right one and the right time. e.g <?php $result=mysql_fetch_array(mysql_query("SELECT products_price FROM products)); ?> <p> Product One's Price is <?php echo $result[products_price WHERE products_id = 1]"; ?></p> <p><p> Product Two's Price is <?php echo $result[products_price WHERE products_id = 2]"; ?></p> Or something that actually works unlike my example. Thanks in advance Nev Link to comment Share on other sites More sharing options...
mtimdog Posted January 28, 2004 Share Posted January 28, 2004 You could store all of them in an array and use the id as the key. <?$result=mysql_query("select products_price, products_id from products");while ($fetcher=mysql_fetch_array($result)){$prices[$fetcher['products_id']]=$fetcher['products_price'];} then echo $prices[put_id_here];?> Note: this only gets the price stored in the products table. It doesn't get specials prices, prices for attributes, etc. Link to comment Share on other sites More sharing options...
singspiel Posted February 4, 2004 Author Share Posted February 4, 2004 Excellent, that works a treat. But in my haste i think I have gone the wrong route because the price we are pulling is the raw database price that doesn't have the tax and currency applied etc etc, we need the same prices as would show within a normal product page. So I need to use OSC's native functions to pull the price, any ideas? Thanks for your advice so far, I have learnt a lot about basic php. Nev Link to comment Share on other sites More sharing options...
mtimdog Posted February 4, 2004 Share Posted February 4, 2004 Look at the code to pull the price on the product_info.php page. Copy the sql query and take out what you don't need. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.