Jump to content

need help displaying html link only when there is MySQL data


webguync

Recommended Posts

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

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
}

<?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

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.