Jump to content

Recommended Posts

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>';}

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827100
Share on other sites

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.  :)

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827183
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827584
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827592
Share on other sites

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>';

?>

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827596
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827826
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-827859
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/157002-if-commands/#findComment-828316
Share on other sites

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.