Jump to content

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'].";
}
  }

An if/else statement is constructed like so

if( condition )
{
     // do something when condition is true
}
else
{
     // do something when condition is false
}

 

What are you trying to do?

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

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

 

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.//

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

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']==

 

  $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..

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.

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.