conan318 Posted April 30, 2011 Share Posted April 30, 2011 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']."; } } Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/ Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208645 Share on other sites More sharing options...
conan318 Posted April 30, 2011 Author Share Posted April 30, 2011 // 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 Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208648 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208666 Share on other sites More sharing options...
Pikachu2000 Posted April 30, 2011 Share Posted April 30, 2011 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.// Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208825 Share on other sites More sharing options...
conan318 Posted May 1, 2011 Author Share Posted May 1, 2011 <? $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 Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208922 Share on other sites More sharing options...
wildteen88 Posted May 1, 2011 Share Posted May 1, 2011 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']== Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1208966 Share on other sites More sharing options...
conan318 Posted May 1, 2011 Author Share Posted May 1, 2011 $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.. Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1209025 Share on other sites More sharing options...
Pikachu2000 Posted May 1, 2011 Share Posted May 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235190-if-statement-depending-on-the-value-returned-from-the-database/#findComment-1209130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.