...

View Full Version : Having a problem with mysql_fetch_array()...



Penguin
01-04-2007, 12:17 PM
So, here it is:
On my computer I have Apache2 with PHP5..
I'm writing all my codes on this system.

So I built a simple code with mysql_fetch_array().. On my Comp. it works great,
but when i uploaded it to some hosting company (who uses php5 too) it dosent work.

Here is my code:


<?php
$link = mysql_connect ($dbhost, $dbusername, $dbpass)
or die ("Can not connect to MySQL");
if (mysql_select_db ($dbname)) {
$result = mysql_query ("Select * from GuestBook order by gb_index desc");
if (mysql_affected_rows() == 0) {
echo "<font face='Arial' size='2'>אין כרגע רעיונות.</font>\n";
} else {
while ($row = mysql_fetch_array ($result)) {

echo "<html dir='rtl'>\n";
echo "<p>\n";
echo "<table dir='rtl' align='center' cellspacing='5' bgcolor='#e9e9e9' border=0 width='70%'style='font: 8pt verdana, geneva, lucida, arial, helvetica, sans-serif;'>\n";
echo "<tr><td align=right>\n";
echo "<b>מאת:</b>\n";
echo "<br>".$row["name"]." <br>\n";
echo "<b> פורסם ב: </b>\n";
echo "<br>".$row["date"]." <br><br>\n";
echo "<b> הרעיון: </b>\n";
echo "<br>".$row["message"]."\n";
echo "</tr></td></table>\n";
echo "</html>\n";

}
}
} else {
echo "<font face='Arial' size='2'>An error occured will trying to select the database.</font>\n";
}
mysql_close ($link);
?>


Returns the next error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/yazamim/webapps/htdocs/ideas/admin1.php on line 43

Line 43:

while ($row = mysql_fetch_array ($result)) {

Can anyone help me?

MRMAN
01-04-2007, 12:21 PM
change this line

$result = mysql_query ("Select * from GuestBook order by gb_index desc");

to


$result = mysql_query ("Select * from GuestBook order by gb_index desc") or die (mysqlL_error());

That error tends to mean there is no data in $result so you could check that my putting this line


print mysql_num_rows($result);
just before the while loop

that won't fix the problem but might help find out what the problem is

Penguin
01-04-2007, 12:33 PM
Thank You!
I have managed to find the problem..
The table name at the database wasn't correct (case-sensitive)

Thanks Again :D

CFMaBiSmAd
01-04-2007, 03:38 PM
That error tends to mean there is no data in $result
The error means the query failed (syntax error, typo's or incorrect table/column names, no database selected, no connection to database server...) and returned a FALSE value. Executing a mysql function using the FALSE value instead of a resource result is what causes the error. A query that succeeds returns a valid resource result even if the number of rows in the result is zero.

Executing a mysql_fetch_array($result) on a resource result with zero rows returns a FALSE value. Executing a mysql_num_rows($result) on a resource result with zero rows returns a ZERO value.

Executing a mysql_fetch_array($result) or a mysql_num_rows($result)following a failed query, results in the error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum