[thelist] PHP, problems with mysql_fetch_array (); First time Poster

Nimrod Evans nimrod at artema.com.au
Fri Oct 26 01:05:53 CDT 2001


First time poster (or whatever you call it) here.
I realy cannot figure out why this page is not working!
The test array at the top does, but when I try to get the information from
the database, it don't work.

I found out today that this line of code is the problem in both the admin
AND the user pages!
It just DOESN'T WANT TO WORK!
Here are the code chunks that seem to come up with the errors:

	[code]
	if ($row = mysql_fetch_array($result))
	{
		echo "The fetch array worked! YAY!<br>\n";
	}
	else
	{
		echo "The fetch array is stupid and it don't work.<br>\n";
	}
	[/code]

That's for the admin script, and...

	[code]
	if (mysql_num_rows($result))
	{
		echo "I love you!<br>";
	}
	else
	{
		echo "I hate you!<br>";
	}
	[/code]

that is for the user script.

Is it just me? Or should this work?
The annoying part is that in another script on my site it DOES work.

I'm lost, thanks for any help in advance.
NOTE: I sorta did some de-bugging, so there is a lot of code in there just
to report what's going on. I commented out my 'format' function too as this
page is an include and that function is on another page.

Here is the whole script (not the admin page):

[code]
<?php

//// Server information ////
$mysql_hostname = "localhost";
$mysql_username = "admin";
$mysql_password = "password";
$mysql_db = "mydb";


//// Connect to Server ////
if (@mysql_connect ($mysql_hostname, $mysql_username, $mysql_password))
{
	$mysql_connect_status = "Connected To Server.<br>\n";
}
else
{
	$mysql_connect_status = "<b>Could not connect to
server!!</b>Error:".mysql_error()."<br>\n";
}

//// Connect to Database ////
if (@mysql_select_db ($mysql_db))
{
	$mysql_connect_status = $mysql_connect_status."Connected To
Database.<br>\n";
}
else
{
	$mysql_connect_status = $mysql_connect_status."<b>Could not connect to
Database!!</b>Error:".mysql_error()."<br>\n";
}


//// WARNING //// DUMMY ARRAY! REPLACE WITH ARRAY FROM DATABASE! ////
WARNING ////
$testlocation = array (
	0 => array ("Vic","Melbourne","Dandenong"),
	1 => array ("NSW","Sydney","Woolengong"),
	2 => array ("QLD","Brisbane")
);


//// GET DATABASE INFORMATION ////
echo $mysql_connect_status."</p>\n";
unset ($result);
if ($result = mysql_unbuffered_query("SELECT * FROM tbllocations"))
{
	echo "The result loves you!<br>";
}
else
{
	echo "The result hates you!<br>";
}

//// FORMAT DATABASE INFORMATION ////
$location = array ();
if ($happyness = mysql_num_rows($result))
{
	echo "The effected rows loves you! $happyness Rows for you!<br>";
}
else
{
	echo "The effected rows hates you! $happyness Rows for you!<br>";
}
if ($happyness = mysql_data_seek ($result, 0))
{
	echo "The data seek loves you!<br>";
}
else
{
	echo "The data seek hates you!<br>";
}

for ( $n = 0 ; $n < mysql_num_rows($result) ; $n++ )
{
	mysql_data_seek ($result, $n);
	$loop = mysql_fetch_array ($result);
	$site = explode (",",@$loop[locations]);
	$location[$n][0] = $loop[1];
	for ( $i = 1 ; $i < sizeof($site) ; $i++ )
	{
		$location[$n][$i] = "$site[$i]" ;
	}
}

//// !!WARNING!! /// REMEMBER TO REMOVE THESE! FOR TESTING ONLY! ////
!!WARNING!! ////
print_r ($location);



//// CONTRUCT TABLE BUILD INFORMATION ////
$oursize = sizeof (@$location[0]);
for ( $n = 0; $n <= sizeof($location); $n++ ) {
	$oursize = $oursize + sizeof (@$location[$n]);
}
$oursize = $oursize / sizeof ($location);
$oursize = round($oursize,0);
$oursize = $oursize - 2;

//// BUILD TABLE ////
echo "<table cellpadding='3' align='center'>";
for ($r = 0; $r <= $oursize; $r++ ) {
	echo "<tr>\n";
	for ( $c = 0; $c <= sizeof($location); $c++ ) {
		$printinfo = @$location[$c][$r];
		if ($r == 0) { $theformat = "head"; $justify = " align='center'"; } else
{ $theformat = "body"; $justify="";}
		echo "<td".$justify.">"./*format ("*/$printinfo/*",
$theformat )*/."</td>\n";
	}
	echo "</tr>\n";
}
echo "</table>";

?>
[/code]

from   ("Nimrod Evans"){
}else{ ("Sir Not Appearing in this Film"){
}else{ ("Shraka"){
}
$Email = "nimrod at artema.com.au";
$Url   = "http://www.artema.com.au/wang/";
$Quote = "We are the nights who say... Ni!";





More information about the thelist mailing list