View Full Version : mysql_fetch_array() error
corsacrazy
07-21-2003, 10:36 AM
ok i am getting an error after having this query on my index
this is the error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /forums/admin/db_mysql.php on line 154
this is the query
$newestsql=$DB_site->query("SELECT * FROM gal_Object where Freigabe='y' order by newat desc limit 1");
while($newObject=$DB_site->fetch_array($newestsql)) {
$getnewthumb=$DB_site->query_first("SELECT * FROM gal_Pictures where Object='$newObject[ID]' ORDER BY rand() DESC LIMIT 1");
// get a random pic
$tmpnew=explode(".",$getnewthumb[filename]);
$newthumbfilename="gt_".$tmpnew[0].".jpg";
eval( '$newestsql = "' . gettemplate( 'home_newest' ) . '";' );
}
this is line 154
$this->record = mysql_fetch_array($this->query_id);
noppid
07-21-2003, 02:38 PM
Try...
LIMIT 0,1
That's the only thing that jumps out to me.
NTLDR
07-21-2003, 02:51 PM
Your only fetching one row, hence you should be using query_first and remove the while loop.
corsacrazy
07-22-2003, 06:42 AM
ok so im now trying
$newestsql=$DB_site->query_first("SELECT * FROM gal_Object where Freigabe='y' order by newat desc limit 0,1");
{
$getnewthumb=$DB_site->query_first("SELECT * FROM gal_Pictures where Object='$newObject[ID]' ORDER BY rand() DESC LIMIT 1");
// get a random pic
$tmpnew=explode(".",$getnewthumb[filename]);
$newthumbfilename="gt_".$tmpnew[0].".jpg";
eval( '$newestsql = "' . gettemplate( 'home_newest' ) . '";' );
}
but its not werking atall
if i remove the { i get a Parse error
NTLDR
07-22-2003, 09:54 AM
Neither of the {} are needed as far as I can see with that code segment.
noppid
07-22-2003, 01:08 PM
I see Limits which are not needed on query_first.
I see an array element with no single quotes around it.
I see order by rand, but rand() will not equate to a field name, just a number.
filburt1
07-22-2003, 01:26 PM
Also, a side note: never, ever query in a loop :)
corsacrazy
07-22-2003, 01:32 PM
Today at 03:08 PM noppid said this in Post #6 (https://vborg.vbsupport.ru/showthread.php?postid=419698#post419698)
I see an array element with no single quotes around it.
can u show me this please ?
NTLDR
07-22-2003, 01:36 PM
Its not stricly needed, but heres what he means:
$getnewthumb[filename];
$getnewthumb['filename'];
The second being the prefered way to do it.
corsacrazy
07-22-2003, 01:42 PM
:( @ Call to undefined function: mysql_fetch_array()
NTLDR
07-22-2003, 01:49 PM
As I've already said, theres no need to use the while loop and $DB_site->fetch_array as your only getting one row from the DB.
corsacrazy
07-22-2003, 01:50 PM
Today at 03:49 PM NTLDR said this in Post #11 (https://vborg.vbsupport.ru/showthread.php?postid=419713#post419713)
As I've already said, theres no need to use the while loop and $DB_site->fetch_array as your only getting one row from the DB.
if i take that out the whole thing just doesnt werk and i get a broken red X instead of the image
atleaset wiv the erro the script is working
Link14716
07-22-2003, 04:33 PM
Here's how it should look...
$newestsql=$DB_site->query_first("SELECT * FROM gal_Object where Freigabe='y' order by newat desc");
$getnewthumb=$DB_site->query_first("SELECT * FROM gal_Pictures where Object='$newestsql[ID]' ORDER BY rand(NOW()) DESC");
// get a random pic
$tmpnew=explode(".",$getnewthumb['filename']);
$newthumbfilename="gt_".$tmpnew['0'].".jpg";
eval( '$newestsql = "' . gettemplate( 'home_newest' ) . '";' );
corsacrazy
07-22-2003, 05:26 PM
U R A LEGEND took me a few template changes but i finally got it sorted CHEERS TO ALL THE VB people AND ESPECIALLY MR LINK ! im gald i got my self that vb license now ;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.