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!

Link to comment
Share on other sites

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>";
								}
						}
				}
		}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.