Jump to content

[SOLVED] Link with php data calling within echo


osiris1603

Recommended Posts

I wrote this code which works fine until I enter the else echo content of which is a link that contains more PHP coding:

 

<?
$buynow = "SELECT availability FROM productlist WHERE id = 60";
$buylink = mysql_query ($buynow);
while ($get_info = mysql_fetch_row($buylink)){ 
foreach ($get_info as $buynowlink) 
if ( $buynowlink == "SORRY, CURRENTLY NOT IN STOCK" ) {
echo "<DEL>Buy Now</DEL>";
}
else
              echo "<script type=\"text/javascript\">document.write('<a href=\"cart.php?action=add_item&cartid=<? echo $PHPSESSID; ?>&product=Excel Bells Large&price=<?
$cost = \"SELECT price FROM productlist WHERE id = 60\"; 
$price = mysql_query ($cost); 
while ($get_info = mysql_fetch_row($price)){
foreach ($get_info as $productprice) 
print \"$productprice\";
}
?>&qty=1\" rel=\"facebox[.thickstyle]\">Buy Now</a>');</script>
<noscript><a href=\"add_item_njs.php?cartid=<? echo $PHPSESSID; ?>&product=<?
$product = \"SELECT productname FROM productlist WHERE id = 60\"; 
$nameofproduct = mysql_query ($product); 
while ($get_info = mysql_fetch_row($nameofproduct)){
foreach ($get_info as $productname) 
print \"$productname\";
}
?>&price=<?
$cost = \"SELECT price FROM productlist WHERE id = 60\"; 
$price = mysql_query ($cost); 
while ($get_info = mysql_fetch_row($price)){
foreach ($get_info as $productprice) 
print \"$productprice\";
}
?>&qty=1\">Buy Now</a></noscript>";
}
?>

 

As you can see there is <? ?> within the links which call data from the database such as price etc. which is needed. However when I try this out it does not give any output as the <? ?> within the echo is not allowing it to (i think?).

 

Does anyone know how I can solve this?

 

Many thanks in advance!

Why are you escaping variable start/end quotes and quotes outside of the tags?

 

Use <?php ?> too, real men use full tags.

 

Edit:

That's best I can do it, I'm too sure if its correct though.

 

<?php
$buynow = "SELECT availability FROM productlist WHERE id = 60";
$buylink = mysql_query ($buynow);
while ($get_info = mysql_fetch_row($buylink))
{ 
	foreach ($get_info as $buynowlink)
		{
			if ( $buynowlink == "SORRY, CURRENTLY NOT IN STOCK" )
				{
					echo "<DEL>Buy Now</DEL>";
				}
			else
				{
					echo "<script type=\"text/javascript\">document.write('<a href=\"cart.php?action=add_item&cartid={$PHPSESSID}&product=Excel Bells Large&price=";
					$cost = "SELECT price FROM productlist WHERE id = 60";
					$price = mysql_query ($cost);
					while ($get_info = mysql_fetch_row($price))
						{
							foreach ($get_info as $productprice) 
								{
									print "$productprice";
								}
							echo "&qty=1\" rel=\"facebox[.thickstyle]\">Buy Now</a>');</script><noscript><a href=\"add_item_njs.php?cartid={$PHPSESSID}&product=";
							$product = "SELECT productname FROM productlist WHERE id = 60";
							$nameofproduct = mysql_query ($product); 
							while ($get_info = mysql_fetch_row($nameofproduct))
								{
									foreach ($get_info as $productname)
										{
											print "$productname";
										}
									echo "&price=";
									$cost = "SELECT price FROM productlist WHERE id = 60";
									$price = mysql_query ($cost);
									while ($get_info = mysql_fetch_row($price))
										{
											foreach ($get_info as $productprice) 
												{
													print "$productprice";
												}
										}
									echo "&qty=1\">Buy Now</a></noscript>";
								}
						}
				}
		}
}
?>

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.