zipperhead Posted September 26, 2008 Share Posted September 26, 2008 Hello, I'm hoping someone can help me with this. I have a query that outputs an array and would like to display the results differently depending on what they are. The query also uses a left join so some of the results will be empty, or null I suppose. The results of the query look something like this... $title_result['title'] $title_result['city'] $title_result['value'] title1 city1 8 title2 city2 3 title3 city3 8 title4 city4 no value (null?) So the logic of what I'm trying to do is display a different echo statement depending on the results of the ['value'] in the array. Something like this: (I know the code is incorrect) while($title_result = mysql_fetch_array($result)){ if ($title_result['value']="8"){echo '.$title_result['title'].' and '.$title_result['city'].' have a high value of '.$title_result['value'].';} if ($title_result['value']="3"){echo '.$title_result['title'].' and '.$title_result['city'].' have a low value of '.$title_result['value'].';} if ($title_result['value']="null"){echo '.$title_result['title'].' and '.$title_result['city'].' have no value;} } I've been trying and just can't seem to get the proper syntax for the IF statements to work, get confused with all the ";}'. Perhaps someone can enlighten me on the proper code for this? Or is there a better way to do it? thanks, ZH Quote Link to comment Share on other sites More sharing options...
Maq Posted September 26, 2008 Share Posted September 26, 2008 I think this because you're assigning variables to the integers that you really want to compare to. For example: ($title_result['value']="8") You have ="8") when you really want == . Try that first. Quote Link to comment Share on other sites More sharing options...
zipperhead Posted September 26, 2008 Author Share Posted September 26, 2008 Thanks for the reply. I missed the = vs == The error I keep getting is... Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' Quote Link to comment Share on other sites More sharing options...
KPH71 Posted September 28, 2008 Share Posted September 28, 2008 {echo '.$title_result['title'].' and '.$title_result['city'].' have a high value of '.$title_result['value'].';} Look at the echo statment. The first ' starts it and then you have a . which should be after ending it. You then echo the $title_result['title'] inside the single quotes and then have another dot(.). Your and is therefore out of single quotes and your variables in. You need to reverse this which can simply be done by removing the first and last dot and single quote. Try this: {echo $title_result['title'].' and '.$title_result['city'].' have a high value of '.$title_result['value'];} Just change the words to make the other rows as well. Notice now that the single quotes enclose the and and not the $title_result['title']. Quote Link to comment 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.