osiris1603 Posted June 12, 2008 Share Posted June 12, 2008 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 https://forums.phpfreaks.com/topic/109867-solved-link-with-php-data-calling-within-echo/ Share on other sites More sharing options...
xtopolis Posted June 12, 2008 Share Posted June 12, 2008 Possibly a typo, but to start, you're missing a "{" after else it seems. Also, try breaking it down so that you don't have so much after }else{ right away... then gradually add a bit until it breaks. Link to comment https://forums.phpfreaks.com/topic/109867-solved-link-with-php-data-calling-within-echo/#findComment-563771 Share on other sites More sharing options...
conker87 Posted June 12, 2008 Share Posted June 12, 2008 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 https://forums.phpfreaks.com/topic/109867-solved-link-with-php-data-calling-within-echo/#findComment-563772 Share on other sites More sharing options...
osiris1603 Posted June 12, 2008 Author Share Posted June 12, 2008 conker87 Thank you very much for your code and help, it works the way I have been trying to achieve! If there is a reputation system on this forum I will give you some. Thank you very, very much! Link to comment https://forums.phpfreaks.com/topic/109867-solved-link-with-php-data-calling-within-echo/#findComment-563796 Share on other sites More sharing options...
conker87 Posted June 12, 2008 Share Posted June 12, 2008 That's alright, glad I could be of service. Don't forget to hit the 'Topic Solved' button. Link to comment https://forums.phpfreaks.com/topic/109867-solved-link-with-php-data-calling-within-echo/#findComment-563829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.