Jump to content

if statement depending on the value returned from the database


conan318

Recommended Posts

just a little confused where ( brackets go in this statement . im just wanting to to display the information differently depending on which message is returned from the database.

 

thanks


if ($info['message'])="<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>";{

Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'];
}elseif  ($info['message'])="You have sent a contact request to";

Echo " .$info['message']<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user'].";
}
  }

Link to comment
Share on other sites

//  condition 1 will return this link //
if ($info['message']="<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>");{
// then echo this line //

Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'];

// condition 2 will return this message// 
}elseif  ($info['message']="You have sent a contact request to");

//echo this //
Echo ".$info['from_user'] .$info['message']<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>";
}
  }
// and so there a few more  conditions to come after this.//

 

Parse error: syntax error, unexpected T_ELSE on the elseif line

Link to comment
Share on other sites

this line

Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'];

 

should be

echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'] . ";

 

you forgot to end you concatenation on the end

 

Link to comment
Share on other sites

this line

Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'];

 

should be

echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'] . ";

 

you forgot to end you concatenation on the end

 

 

The line you posted has a parse error. There should be no concatenation operator or quote at the end.  The line that was originally posted was fine and had no parse errors.

 

The problem is mostly due to the semicolons after the conditions, such as

if(condition); {

                ^ THERE

 

//  condition 1 will return this link //
if ($info['message']= "<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>") {
   // then echo this line //
   Echo "<a href='viewprofile.php?username={$info['username']}'><img src='[url=http://datenight.netne.net/images/]http://datenight.netne.net/images/[/url]".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message'];
   // condition 2 will return this message//
} elseif  ($info['message']="You have sent a contact request to") {
   //echo this //
   Echo "{$info['from_user']} {$info['message']}<a href='viewprofile.php?username={$info['username']}'><img src='[url=http://datenight.netne.net/images/]http://datenight.netne.net/images/[/url]".$info['img'] ."' width='30' height='30''></a>";
}
// and so there a few more  conditions to come after this.//

Link to comment
Share on other sites

<?
$data = mysql_query("SELECT * FROM alog, users WHERE from_user=users.username AND  alog.to_user='$myusername'  ORDER BY alog.id DESC LIMIT 10;") or die(mysql_error());
  while($info = mysql_fetch_array( $data )) 

{  

//  condition 1 will return this link //
if ($info['message']= "<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>"."<br>") {
  
  // then echo this line //
   Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>".$info['from_user']." ".$info['message']."<br>";

   // condition 2 will return this message//

} elseif  ($info['message']="You have sent a contact request to") {
   //echo this //
  
  Echo "{$info['from_user']} {$info['message']}<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>"."<br>";
}
}

no errors but its not working everything is returned as if it was condition 1

Link to comment
Share on other sites

If you're comparing values you should be using the comparison operator == (two equal signs together). At the moment you're using the assignment operator = (one equal sign). Change $info['message']= to $info['message']==

 

Link to comment
Share on other sites

  $data = mysql_query("SELECT * FROM alog, users WHERE from_user=users.username AND  alog.to_user='$myusername'  ORDER BY alog.id DESC LIMIT 20;") or die(mysql_error());
  while($info = mysql_fetch_array( $data )) 

{  

} if ($info['message']=='<a href=\"freindacept.php?username=$myusername\">Has sent you a friend request </a>'){

  
  // then echo this line //
   Echo "<a href='viewprofile.php?username=={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>".$info['from_user']." ".$info['message']."<br>";
   // condition 2 will return this message//



 } elseif ($info['message']=="You have sent a contact request to"){

 Echo " {$info['message']}{$info['to_user']}<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>"."<br>";

// and so there a few more  conditions to come after this.//
 } elseif ($info['message']=="has sent you a message"){
  Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>".$info['from_user']." ".$info['message']."<br>";


} elseif ($info['message']=="Welcome to singlesbook"){
  Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>".$info['from_user']." ".$info['message']."<br>";


} elseif ($info['message']=="is Checking you out"){
  Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/{$info['img']}'  title='{$info['username']}' width='50' height='50'></a>".$info['from_user']." ".$info['message']."<br>";


}

If you're comparing values you should be using the comparison operator == (two equal signs together). At the moment you're using the assignment operator = (one equal sign). Change $info['message']= to $info['message']==

 

 

i totally forgot about ==  but now the query returns nothing.. i tried just using if instead of elseif but then it would only return 1 entry instead of limit of 20..

Link to comment
Share on other sites

Echo your query string, make sure it contains the values you'd expect it to . If it does, paste it into phpMyAdmin and execute it to see what results it returns. If the query string doesn't contain the values you'd expect, investigate why.

Link to comment
Share on other sites

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.