Jump to content

Some help to modify this code please...


roldahayes

Recommended Posts

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'---------------------

?>

Link to comment
https://forums.phpfreaks.com/topic/192145-some-help-to-modify-this-code-please/
Share on other sites

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
}

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.