stackumhi Posted October 14, 2009 Share Posted October 14, 2009 Trying to make "business name" a link but it makes all 4 rows a link. I have tried moving the closing </a> around but still not working. Thanks for any help. while($row = mysql_fetch_array($result)) { echo "<a href='view-listing.php?contact_id= " .$row['contact_id']. "'/>" .stripslashes($row['business_name']). "<br/>"; echo $row['address']. "<br/>"; echo $row['city']. ', '. $row['state']. ' '.$row['zip']."<br/>"; echo format_phone($row['phone']); echo "<br/><br/>"; } Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/ Share on other sites More sharing options...
Maq Posted October 14, 2009 Share Posted October 14, 2009 You never terminate it - . I see you tried to self terminate it but then it wouldn't have a value. Take out the forward slash and end it after business_name. Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936946 Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 The anchor tag is not self closing: <a href="some link" /> This is invalid HTML! Anchor tag does not close itself! <a href="some link">Link text</a> This is correct HTML. Anchor tag needs a closing tag. By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Double quotes tell PHP to parse the string for PHP variables, classes, etc. If you remove all those variables and classes from the string, then you're telling PHP to parse a string that doesn't have anything to parse in it! You're wasting processing cycles parsing a string that you already know has nothing to parse because you've explicitly removed all the PHP from those strings! Use single quotes instead, it saves processing time! Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936947 Share on other sites More sharing options...
dreamwest Posted October 14, 2009 Share Posted October 14, 2009 while($row = mysql_fetch_array($result)) { "<a href='view-listing.php?contact_id= " .$row['contact_id']. "'/>" .stripslashes($row['business_name']). "</a><br/>"; echo $row['address']. "<br/>"; echo $row['city']. ', '. $row['state']. ' '.$row['zip']."<br/>"; echo format_phone($row['phone']); echo "<br/><br/>"; } Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936952 Share on other sites More sharing options...
Maq Posted October 14, 2009 Share Posted October 14, 2009 By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Because variables will interpolate within double quotes so you don't have to use concatenation. This way is cleaner and faster (AFAIK). I actually prefer this format: echo "stripslashes({$row['business_name']}) "; Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936960 Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Because variables will interpolate within double quotes so you don't have to use concatenation. This way is cleaner and faster (AFAIK). I actually prefer this format: echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>stripslashes({$row['business_name']})</a><br/>"; Except that he already concatenated his string as I point out in the post you quoted. Its wasting processing cycles. Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936963 Share on other sites More sharing options...
mrMarcus Posted October 14, 2009 Share Posted October 14, 2009 By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Because variables will interpolate within double quotes so you don't have to use concatenation. This way is cleaner and faster (AFAIK). I actually prefer this format: echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>stripslashes({$row['business_name']})</a><br/>"; that won't work .. i'm assuming you meant to: echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>".stripslashes({$row['business_name']})."</a><br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936964 Share on other sites More sharing options...
stackumhi Posted October 14, 2009 Author Share Posted October 14, 2009 Thanks everyone for the VERY fast response. Maq...Thanks for the quote advise. I am always open for suggestions for improving my code. Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936965 Share on other sites More sharing options...
Maq Posted October 14, 2009 Share Posted October 14, 2009 By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Because variables will interpolate within double quotes so you don't have to use concatenation. This way is cleaner and faster (AFAIK). I actually prefer this format: echo "stripslashes({$row['business_name']}) "; that won't work .. i'm assuming you meant to: echo "".stripslashes({$row['business_name']})." "; Actually no, I just had a brain lapse and thought you could execute a PHP function in a string. But yeah, that's the way I would have done it. By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all? Because variables will interpolate within double quotes so you don't have to use concatenation. This way is cleaner and faster (AFAIK). I actually prefer this format: echo "stripslashes({$row['business_name']}) "; Except that he already concatenated his string as I point out in the post you quoted. Its wasting processing cycles. I understand that, I wasn't disagreeing even though it seemed like it. I was giving an alternative that he may find easier. Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936972 Share on other sites More sharing options...
mrMarcus Posted October 14, 2009 Share Posted October 14, 2009 Actually no, I just had a brain lapse and thought you could execute a PHP function in a string. But yeah, that's the way I would have done it.i figured as much .. i just pointed it out for the sake of the thread starter. Quote Link to comment https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/#findComment-936975 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.