News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP help needed :)

Started by CoolMan, August 20, 2004, 06:31:29 PM

Previous topic - Next topic

CoolMan

Hey fellas, thanks for reading this :)

I got this script:

<?php
include("db_conn.php"); <- all DB connection info
$sql
= "SELECT * FROM users";
$result = mysql_query($sql);
echo
'<table>';
while(
$row = mysql_fetch_object($result)) {
        echo "<tr><td>$row->name<td>$row->email<td>$row->status</tr>";
}
echo
'</table>';
mysql_free_result($result);
?>


Now i got over 100 or so rows in the users table, and I would like that each time it enters another row in the "while" it will change the color in the <tr>... like in the posts in this forum, first post gets X color and the next  one gets Y, then back to X and so on..
How did you guys do that?

[Unknown]


<?php

// Load the database connection information.
include("db_conn.php");

$result = mysql_query('
  SELECT *
  FROM users'
);

echo
'
<table>'
;
$alternate = true;
while (
$row = mysql_fetch_object($result))
{
  echo
'
  <tr style="background-color: '
, $alternate ? 'red' : 'blue', '">
     <td>'
, $row->name, '</td>
     <td>'
, $row->email, '</td>
     <td>'
, $row->status, '</td>
  </tr>'
;

 
$alternate != $alternate;
}
echo
'
</table>'
;

mysql_free_result($result);

?>


-[Unknown]

CoolMan


CoolMan

Oh hold on, its just putting it as 'Red' all the time... i put the Alternate = true before the while then the Alternate != Alternate in the while and its not changing....

CoolMan

and i fixed it using:


if($alternate == "true") {
$alternate = false;
} else {
$alternate = true;
}


instead of the 2nd one:

$alternate != $alternate;

[Unknown]

You should definitely not put "true" in quotes..

-[Unknown]

whiterabbit

Ahh.. well, I believe just change
$alternate != $alternate;

to

$alternate = !$alternate;

should work .... or isn't it  :-
One pill makes you larger, and one pill makes you small
And the ones that mother gives you, don't do anything at all

[Unknown]

Oops, see, that was the typo... good eye.

-[Unknown]

Advertisement: