Keep getting a blank page with this...

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!

Moderator: General Moderators

Post Reply
sgt_underpants
Forum Newbie
Posts: 9
Joined: Mon Oct 07, 2002 11:52 am
Location: Denver
Contact:

Keep getting a blank page with this...

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

php -l <scriptfile name>
it will just check your script without executing it ;)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

silly question

Post by phpScott »

are you using a opening php tag either
<?

or <?php

on your page?

phpScott
sgt_underpants
Forum Newbie
Posts: 9
Joined: Mon Oct 07, 2002 11:52 am
Location: Denver
Contact:

Post 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;
Last edited by sgt_underpants on Fri Nov 08, 2002 3:21 pm, edited 1 time in total.
sgt_underpants
Forum Newbie
Posts: 9
Joined: Mon Oct 07, 2002 11:52 am
Location: Denver
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;) )
sgt_underpants
Forum Newbie
Posts: 9
Joined: Mon Oct 07, 2002 11:52 am
Location: Denver
Contact:

Post 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.
sgt_underpants
Forum Newbie
Posts: 9
Joined: Mon Oct 07, 2002 11:52 am
Location: Denver
Contact:

Post 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;
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

I got a question?

Post 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.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

he didn't. he made a while loop. which continues untill mysql_fetch_arry() stops outputing result data.
Post Reply