roldahayes Posted February 15, 2010 Share Posted February 15, 2010 Hi, The following code displays a "buy" button that relates to a certain item stored in a database. I'm trying to modify the code so the price is automatically displayed next to the buy button. The column name for the price is Price_ExVat but nothing that I try seems to work. Any suggestions would be great. //the folowing lines contain the code that should be used with each link that you want to create change the values of $strProd_REF $strCar_ID as you need to //--------------'LINK CODE'--------------------- $strProd_REF = "VGA89"; $strCar_ID = "all"; $sqlSelect = "SELECT Prod_ID FROM products WHERE Prod_REF = '" . $strProd_REF . "' AND Car_ID = '" . $strCar_ID . "' "; // assign the basic sqlquery $sqlquery = $sqlSelect; //get the result set $result = mysql_query($sqlquery); while ($row = mysql_fetch_assoc($result)) { echo "<a href=\"basket.php?src=".urlencode($_SERVER['REQUEST_URI'])."&productID=" . $row["Prod_ID"] . "\"><img src=images/addtobasket.jpg width=55 height=28 border=0></a>"; //end make while } $row = ""; mysql_free_result($result); //--------------'END LINK CODE'--------------------- ?> Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/ Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 You are only selecting Prod_ID from the table select Prod_ID, Price_ExVat ... may be helpful Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012630 Share on other sites More sharing options...
roldahayes Posted February 15, 2010 Author Share Posted February 15, 2010 Hi, I know I need to do that, I just pasted the code in it's original format to show what I was starting with. I think it might be to do with how I've tried to echo the result as it just comes back blank... Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012641 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 You need to include the Price_ExVat column in your SELECT statement, eg: $sqlSelect = "SELECT Prod_ID, Price_ExVat ...etc Now in your while loop echo out $row['Price_ExVat'] where you want the price to be displayed. Like so while ($row = mysql_fetch_assoc($result)) { echo "£{$row['Price_ExVat']} <a href=\"basket.php?src=".urlencode($_SERVER['REQUEST_URI'])."&productID=" . $row["Prod_ID"] . "\"><img src=\"images/addtobasket.jpg\" width=\"55\" height=\"28\" border=\"0\"></a>"; //end make while } Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012650 Share on other sites More sharing options...
roldahayes Posted February 15, 2010 Author Share Posted February 15, 2010 Excellent! It was indeed the way I was using the echo that caused the problem! One last question, I need to have the price and the button displayed in a table with 2 columns. Can the echo have <td> inserted into it to achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012652 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 Yes ofcourse. Look at this FAQ post for an example. Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012675 Share on other sites More sharing options...
roldahayes Posted February 15, 2010 Author Share Posted February 15, 2010 Excellent! Many thanks for your help! That has saved literally HOURS of time updating prices on pages in the future! Quote Link to comment https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/#findComment-1012678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.