webguync Posted August 11, 2009 Share Posted August 11, 2009 Hi, I need to display an html link only when there is information, being displayed from a MySQL table, else display just text. $Name is one of the fields in the MySQL table and the part to display the data works fine. It's the display or not display link part that I am having trouble with. I am trying this, but get an error. <?php if (!isset($name)) { ?> <tr><td>No Data</td></tr> <?php } else { <tr><td><a href="mylink.html">Link Goes Here</a></td></tr> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/169821-need-help-displaying-html-link-only-when-there-is-mysql-data/ Share on other sites More sharing options...
SetToLoki Posted August 11, 2009 Share Posted August 11, 2009 Hi, I need to display an html link only when there is information, being displayed from a MySQL table, else display just text. $Name is one of the fields in the MySQL table and the part to display the data works fine. It's the display or not display link part that I am having trouble with. I am trying this, but get an error. <?php if (!isset($name)) { ?> <tr><td>No Data</td></tr> <?php } else { <tr><td><a href="mylink.html">Link Goes Here</a></td></tr> <?php } } ?> without seeing more of your code and database structure not sure what I'll get what you're asking for right could try if (strlen($name) == 0) { no data } else { show link } or if($name == "") { no link } else { link } Link to comment https://forums.phpfreaks.com/topic/169821-need-help-displaying-html-link-only-when-there-is-mysql-data/#findComment-895906 Share on other sites More sharing options...
MatthewJ Posted August 11, 2009 Share Posted August 11, 2009 <?php if (!isset($name)) { ?> <tr><td>No Data</td></tr> <?php } else { ?> <tr><td><a href="mylink.html">Link Goes Here</a></td></tr> <?php } ?> If the code you had just wasn't echoing right, it was closed off wrong Link to comment https://forums.phpfreaks.com/topic/169821-need-help-displaying-html-link-only-when-there-is-mysql-data/#findComment-895909 Share on other sites More sharing options...
webguync Posted August 11, 2009 Author Share Posted August 11, 2009 ok, i believe that was the problem, thanks. Link to comment https://forums.phpfreaks.com/topic/169821-need-help-displaying-html-link-only-when-there-is-mysql-data/#findComment-895946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.