Page 1 of 1

Keep getting a blank page with this...

Posted: Fri Nov 08, 2002 2:04 pm
by sgt_underpants

Code: Select all

// 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.

Posted: Fri Nov 08, 2002 2:45 pm
by volka
try

Code: Select all

php -l <scriptfile name>
it will just check your script without executing it ;)

silly question

Posted: Fri Nov 08, 2002 2:46 pm
by phpScott
are you using a opening php tag either
<?

or <?php

on your page?

phpScott

Posted: Fri Nov 08, 2002 2:55 pm
by sgt_underpants
Yes...here is the whole code that I'm still working on. I can't get it to display the way I want it too.

Code: Select all

&lt;div align="center"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" width="550"&gt;
	&lt;tr&gt;&lt;td bgcolor="#c9c9c9"&gt;
		&lt;table border="0" cellpadding="0" cellspacing="0" width="550"&gt;
&lt;?php 
    $host = "localhost"; 
    $user = "root"; 
    $pass = ""; 
    $database = ""; 
    $table = "stuff"; 

        // 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&#1111;"id"];
		$username = $row&#1111;"name"];
		$description = $row&#1111;"description"]; 
		//run the for loop
		for ($i = 0; i &lt; count($row); $i++) {
		//set table row color
			if ($i % 2) { 
             echo "&lt;tr bgcolor=B0C4DE&gt;"; 
         } else { 
             echo "&lt;tr bgcolor=FOF8FF&gt;"; 
         } 

		//now display table cell info  
	}
?&gt;
&lt;td&gt;&lt;? echo $userid; ?&gt;&lt;/td&gt;&lt;td&gt;&lt;? echo $username; ?&gt;&lt;/td&gt;&lt;td&gt;&lt;? echo $description; ?&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;? 
mysql_close($connect);
}

?&gt;

Posted: Fri Nov 08, 2002 3:18 pm
by sgt_underpants
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.

Posted: Fri Nov 08, 2002 3:25 pm
by volka
There's a link on top of every page here
PHP Tutorials there are plenty of tutorial, examples, tips .....
(of course not only there ;) )

Posted: Fri Nov 08, 2002 3:33 pm
by sgt_underpants
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.

Posted: Fri Nov 08, 2002 4:14 pm
by sgt_underpants
Never mind...I got it to work. This is what I did to change my code.

Code: Select all

&lt;?php
// Connecting to the Database 
    $connect = @mysql_connect($host, $user, $pass) or die("could not connect to server"); 

        // Selecting the Database
    $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 		
	$alternate = "2"; // number of alternating rows
    	while($row = @mysql_fetch_array($result)) {
			$userid = $row&#1111;"id"];
			$username = $row&#1111;"name"];
			$description = $row&#1111;"description"];
		if ($alternate == "1") { 
			$color = "#f5f5f5"; 
			$alternate = "2"; 
		} 

		else { 
			$color = "#ffffff"; 
			$alternate = "1"; 
		} 
		//now display table cell info  
print("&lt;tr&gt;&lt;td bgcolor=$color&gt;$userid&lt;/td&gt;&lt;td bgcolor=$color &gt;$username&lt;/td&gt;&lt;td bgcolor=$color &gt;$description&lt;/td&gt;&lt;/tr&gt;");
}
?&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
?&gt;

I got a question?

Posted: Fri Nov 08, 2002 4:16 pm
by icesolid
How come you wrote:

Code: Select all

&lt;?php
if($row = @mysql_fetch_array($result)) { 
?&gt;
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.

Posted: Fri Nov 08, 2002 5:04 pm
by mydimension
he didn't. he made a while loop. which continues untill mysql_fetch_arry() stops outputing result data.