PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
// Connecting to the Database
$connect = @mysql_connect($host, $user, $pass) or die("could not connect to server");
// Selecting the Database for use
$db_select = @mysql_select_db($database) or die("could not select the database");
// Compose SQL command
$SQL = "SELECT * FROM $table";
// Query the Database
$result = @mysql_query($SQL) or die("could not complete your query");
// Loop the results
// Note, results are returned as an
// Array - we cannot just print it out.
if($row = @mysql_fetch_array($result)) {
$userid = $rowї"id"];
$username = $rowї"name"];
$description = $rowї"description"];
//run the for loop
for ($i = 0; i < count($row); $i++) {
//set table row color
if ($i % 2) {
echo "<tr bgcolor=f5f5f5>";
} else {
echo "<tr bgcolor=cccccc>";
}
//now display table cell info
}
?>
<td><? echo $userid; ?></td><td><? echo $username; ?></td><td><? echo $description; ?></td>
</tr></table>
</td></tr></table>
<?
mysql_close($connect);
}
?>
I know it's probably something easy. Any help would be greatly appreciated.
I'm having a hard time wrapping my head around this. Is there a place that gives a good tutorial on how to do this? I used the one at Spoono and it does the same thing...white page city and it takes it forever to render even the mistake.
Thanks anyway but those tutorials only show you how to display the returned values on a page using nothing more than the <p> tag to separate them. I need to use tables and change the colors of every other row.
You are asking if $row, but $row is not available yet, because you hav not set $row to anything yet. You are trying to call $row and make $row an array at the same time.
I think you need to set $row to something, then call it in the if statement.