Jump to content

Help with simple IF statement


leightr

Recommended Posts

Can someone point out what is wrong with this?

 

{
if ($street == null) {
echo 'No Directions'; }
ELSE {
  echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>";
  }
  }
  echo "</tr>";

 

It should say No Directions if $street is null. However it doesnt. It just echo's echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; instead.

Link to comment
Share on other sites

That did not work..  :'(

 

That isn't helpful.  What do you mean?

 

What do you mean by null - the string 'null', the value zero, and empty variable?  How and where does $street get its value?

Link to comment
Share on other sites

Sorry. I forgot to paste the code ...  :o

 

Anyways, when I used isset nothing happened, it just did the same as the first code I pasted.

 

Here is more of the code:

$practice = mysql_query("SELECT * FROM schedules WHERE teamid='$username' AND gametype='Practice'");
echo "<h1>Scheduled Practice Games</h1>";
echo "<table border='1'>
<tr>
<th>Game Type</th>
<th>Game Location</th>
<th>Game Time</th>
<th>Game Date</th>
<th>Op. Team</th>
<th>View Map</th>
</tr>";
while($row = mysql_fetch_array($practice))
  {
  echo "<tr>";
  echo "<td>" . $row['gametype'] . "</td>";
  echo "<td>" . $row['gamelocation'] . "</td>";
  echo "<td>" . $row['gametime'] . "</td>";
  echo "<td>" . $row['gamedate'] . "</td>";
  echo "<td>" . $row['oppositeteam'] . "</td>";

// Lets see if there is a address to show a map link.
$street = $row['street'];
{
if ($street == null) {
echo 'No Directions'; }
ELSE {
  echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>";
  }
  }
  echo "</tr>";
}
echo "</table>";

Link to comment
Share on other sites

I got string(4) "NULL"

 

can you add var_dump before the <td><a href=directions.php?id=" .$row['id']. ">Map</td> and tell us what it displays.. will help us.

 

var_dump($street);
echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>";

 

Link to comment
Share on other sites

I have a question. How would I do this samething but without the database having to say NULL? Basically I want it to check if it is blank and than do the if?

 

 

// Lets see if there is a address to show a map link.

$street = $row['street'];

{

if ($street == "NULL") {

echo "<td>". 'No Directions'. "</td>"; }

ELSE {

  echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>";

  }

  }

  echo "</tr>";

}

echo "</table>";

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.