Jim R Posted May 5, 2009 Share Posted May 5, 2009 Ok. I'm stuck on this. Why is the below not working? FYI, I have tried it with =1 and ="1". It still produces the same results, which is just printing the entire list. I"m not getting any errors. $query = 'SELECT * FROM class2010 ORDER BY rankPOS ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { if ($line['group'] = "1") {echo '<tr> <td valign="top">'. $line['rankPos'] . $line['deviation'] . '</td> <td valign="top"><a href="/wiki/index.php?title=' . $line['nameFirst'] . '_' . $line['nameLast'] .'">'. $line['nameFirst'] . ' ' . $line['nameLast'] . '</a></td> <td valign="top"><center>'. $line['height'] . '</center></td> <td valign="top"><center>'. $line['level'] . '</center></td> <td valign="top">'. $line['hschool'] . '</td> <td valign="top">'. $line['college'] . '</td> </tr>';} Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/ Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Use == or preferably === when comparing data. There are differences between == and ===. You can read up on that. Google is your friend! Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827067 Share on other sites More sharing options...
teng84 Posted May 6, 2009 Share Posted May 6, 2009 if ($line['group'] = "1") this condition is always true. since you're passing 1 which also means true. plus your not really asking if 1 is equal to $line['group'] but you are assigning value to $line['group'] with 1.. so ti should be $line['group'] == 1 or $line['group'] === 1 Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827100 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 Very nice. The == worked. The === yielded no results. At the risk of sounding lazy, what is the difference? I always thought == meant it didn't equal. I Googled it, but it didn't come up because they aren't words. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827167 Share on other sites More sharing options...
teng84 Posted May 6, 2009 Share Posted May 6, 2009 using === AKA identical you are comparing the value and the data type so they should be equal in all means Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827171 Share on other sites More sharing options...
Maq Posted May 6, 2009 Share Posted May 6, 2009 I Googled it' date=' but it didn't come up because they aren't words. [/quote'] Please see here: Comparison Operators Google is your friend! Apparently Google doesn't like everybody... Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827176 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 I Googled it' date=' but it didn't come up because they aren't words. [/quote'] Please see here: Comparison Operators Google is your friend! Apparently Google doesn't like everybody... It usually likes me, but I was searching for equal signs, not comparative operators. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827183 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Google is your friend! Apparently Google doesn't like everybody... Nope, it's just some people don't know how to Google. I think Google needs a Google 101 video or guide somewhere. Jim R, in no offense to you. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827268 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 Can I continue this topic a little further? I know enough PHP to tinker with echo statements, but as for writing my own, my brain no longer functions with that kind of logic. As I'm dealing with "IF" commands, what I posted above, I have three separate sections from the same database. Section 1 is posted above, and as you can see the output is in a table. I will continue the table for sections 2 and 3. Should I repeat what I have above for sections 2 and 3, or is there a way of IF....AND...AND...? I don't think it's IF/else. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827584 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Can I continue this topic a little further? I know enough PHP to tinker with echo statements, but as for writing my own, my brain no longer functions with that kind of logic. As I'm dealing with "IF" commands, what I posted above, I have three separate sections from the same database. Section 1 is posted above, and as you can see the output is in a table. I will continue the table for sections 2 and 3. Should I repeat what I have above for sections 2 and 3, or is there a way of IF....AND...AND...? I don't think it's IF/else. Can you elaborate on that? While you're at it, can you post the updated code? Ken Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827592 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 I actually came back to post the updated code. Sorry about that. Basically, I have three different queries(?) with three different SELECTS. (Not sure of the terminology.) <?php mysql_select_db("jwrbloom_hhr"); echo '<table class="playerTable" width="100%"> <thead> <tr> <th>#</th> <th>Top 10</th> <th>HT</th> <th>Level</th> <th>City (School)</th> <th>College</th> </tr> </thead> <tfoot> <tr> <td colspan="6" align="right">(+) moved up; (d) debut; (s) switched from another position</td> </tr> <tr> <td colspan="6" align="right">Colleges in bold print means committed</td> </tr> </tfoot> <tbody> '; $query = 'SELECT * FROM class2010 ORDER BY rankPOS ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { if ($line['group'] == 1) { echo '<tr> <td>'. $line['rankPos'] . $line['deviation'] . '</td> <td><a href="/wiki/index.php?title=' . $line['nameFirst'] . '_' . $line['nameLast'] .'" class="thickbox">'. $line['nameFirst'] . ' ' . $line['nameLast'] . '</a></td> <td><center>'. $line['height'] . '</center></td> <td><center>'. $line['level'] . '</center></td> <td>'. $line['hschool'] . '</td> <td>'. $line['college'] . '</td> </tr>';} } echo ' <tr> <td class="playerTable_head" colspan="6">The Best of the Rest</td> </tr>'; $query = 'SELECT * FROM class2010 ORDER BY nameLast ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) if ($line['group'] == 2) { echo '<tr> <td>'. $line['deviation'] . '</td> <td><a href="/wiki/index.php?title=' . $line['nameFirst'] . '_' . $line['nameLast'] .'" class="thickbox" >'. $line['nameFirst'] . ' ' . $line['nameLast'] . '</a></td> <td><center>'. $line['height'] . '</center></td> <td><center>'. $line['level'] . '</center></td> <td>'. $line['hschool'] . '</td> <td>'. $line['college'] . '</td> </tr>';} echo ' <tr> <td class="playerTable_head" colspan="6">Names To Know</td> </tr>'; $query = 'SELECT * FROM class2010 ORDER BY nameLast ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) if ($line['group'] == 3) { echo '<tr> <td>'. $line['deviation'] . '</td> <td><a href="/wiki/index.php?title=' . $line['nameFirst'] . '_' . $line['nameLast'] .'" class="thickbox" >'. $line['nameFirst'] . ' ' . $line['nameLast'] . '</a></td> <td><center>'. $line['height'] . '</center></td> <td><center>'. $line['level'] . '</center></td> <td>'. $line['hschool'] . '</td> <td>'. $line['college'] . '</td> </tr>';} echo '</tbody></table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827596 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Okay, I see the 3 selects. What about them? Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827697 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 Is that the best way to do that? They are all confined in one table. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827823 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 No, you can put the third if statement directly after the second if statement because they're using the same SQL anyways. Also, you can be more specific in your query so you don't have to use your first if statement. SELECT * FROM class2010 WHERE group = 1 ORDER BY rankPOS ASC For the last two, you can have MySQL only select rows where group is either 2 or 3. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827826 Share on other sites More sharing options...
Jim R Posted May 6, 2009 Author Share Posted May 6, 2009 No, you can put the third if statement directly after the second if statement because they're using the same SQL anyways. Also, you can be more specific in your query so you don't have to use your first if statement. SELECT * FROM class2010 WHERE group = 1 ORDER BY rankPOS ASC For the last two, you can have MySQL only select rows where group is either 2 or 3. I'm not sure of the logic of the code as you describe it. I tried to do them all with the same SQL (before I switched what section 2 queried), and it printed the Header for the second section every time too. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827859 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Post your code. You probably did it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827861 Share on other sites More sharing options...
fenway Posted May 6, 2009 Share Posted May 6, 2009 And by "code" i hope there's an mysql query in there somewhere -- otherwise I'm moving this to a more appropriate board. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827865 Share on other sites More sharing options...
Jim R Posted May 7, 2009 Author Share Posted May 7, 2009 And by "code" i hope there's an mysql query in there somewhere -- otherwise I'm moving this to a more appropriate board. The "code" is already up there, and it has plenty of queries, exactly three. That's the point. Is there a more concise way of doing it? The answer is probably yes, which is why I'm asking. Ken, I no longer have the example I referred to because it wasn't yielding what I wanted. Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-828316 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Well that's not progress. Can you re-do that and then show me the updated code? Quote Link to comment https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-828490 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.