Warning: mysql_fetch_array()
06-08-2009, 08:50 PM
|
Warning: mysql_fetch_array()
|
Posts: 102
|
My warning is " Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/zybersca/public_html/code-bin/themes/hd/_index.php on line 211"
and ive worked it out so i can get it not error but it then wont do what i need it to.
PHP Code:
<?php $i = 0; $latest = ''; $postsQ = ''; $threads = mysql_query("SELECT * FROM threads WHERE forum={$row2['id']}"); while ($thread = mysql_fetch_array($threads)) { if ($postsQ != '') { $postsQ .= ' OR '; } $postsQ .= 'thread= '.$thread['id']; } $posts = mysql_query("SELECT * FROM posts WHERE $postsQ ORDER BY createdYear DESC, createdMonth DESC, createdDate DESC, createdHour DESC, createdMinute DESC, createdSecond DESC"); while ($row2A = mysql_fetch_array($posts)) { if ($i == 0) { $latest = compileTimestamp($row2A['createdMonth'], $row2A['createdDate'], $row2A['createdYear'], $row2A['createdHour'], $row2A['createdMinute'], $row2A['createdSecond']) . '<br />by ' . returnUsername($row2A['creator']); } $i++; } ?>
Last edited by Aaron™; 06-09-2009 at 08:40 PM..
|
|
|
|
06-08-2009, 08:56 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
see what error it is, and echo the actual SQL statement so you can read it:
PHP Code:
$sql = "SELECT * FROM threads WHERE forum={$row2['id']}" $threads = mysql_query($sql) or die(mysql_error().": ".$sql);
This is just a debugging line, and I don't recommend you plant stuff like this during production.
__________________
I build web things. I work for the startup Please login or register to view this content. Registration is FREE
.
|
|
|
|
06-08-2009, 10:10 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
PHP Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY createdYear DESC, createdMonth DESC, createdDate DESC, createdHour DESC' at line 1
|
|
|
|
06-09-2009, 01:04 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Check the syntax of the fields, the error may be there.
To simplify your query, you don't have to specify the direction on each order by elements, you could write it
Code:
SELECT *
FROM posts
WHERE $postsQ
ORDER BY createdYear, createdMonth, createdDate, createdHour, createdMinute, createdSecond DESC
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
06-09-2009, 01:31 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Well I will take a lowly educated guess and would say it could be here because thats whats getting echo'ed into the sql syntax
PHP Code:
while ($thread = mysql_fetch_array($threads)){ if ($postsQ != ''){ $postsQ .= ' OR '; } $postsQ .= 'thread='.$thread['id']; }
|
|
|
|
06-10-2009, 12:59 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Anyone?
|
|
|
|
06-10-2009, 02:00 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 181
Name: David Jackson
|
is this valid?...
PHP Code:
"SELECT * FROM threads WHERE forum={$row2['id']}"
try this...
PHP Code:
$forumVal = $row2['id']; $sql = "SELECT * FROM threads WHERE forum='$forumVal'";
|
|
|
|
06-10-2009, 02:22 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Still has the same error. I really think its in the $postsQ but I don't know what would be wrong.
|
|
|
|
06-11-2009, 03:19 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 181
Name: David Jackson
|
ok
start debugging
first echo the $sql variable out to see if the SQL Syntax is valid
|
|
|
|
06-11-2009, 03:26 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
I echo'ed $postsQ and I get this
Code:
thread= 112 OR thread= 94thread= 91
But I get something similar to that on another category with no errors.
Code:
thread= 92 OR thread= 93thread= 3
|
|
|
|
06-11-2009, 10:48 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 181
Name: David Jackson
|
that is not valid SQL
echo the sql variable and see if its valid
Your example is invalid.....
Code:
thread= 112 OR thread= 94thread= 91
this should be
Code:
thread= '112' OR thread= '94' OR thread= '91'
Last edited by davidj; 06-11-2009 at 10:51 AM..
|
|
|
|
06-11-2009, 02:28 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
So what one do you want me to echo there is 2.... $posts or $threads
|
|
|
|
06-11-2009, 03:04 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 181
Name: David Jackson
|
did you write this or did you copy and paste it?
i ask so i know that you will be able to spot a mistake if you can debug it?
Be honest so we can sort this out
|
|
|
|
06-11-2009, 03:40 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Were the hell would I copy and paste code for a post counter and a last post viewer, but yes I did, I had a friend whom I dont talk to anymore do this part of the code.
Last edited by Aaron™; 06-11-2009 at 08:13 PM..
|
|
|
|
06-11-2009, 07:01 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 1,533
Name: Paul Davis
Location: San Francisco
|
Quote:
Originally Posted by Aaron™
Where the hell would I ..... but yes I did...
|
lmao 
|
|
|
|
06-11-2009, 09:14 PM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Aren't you a great mod.
|
|
|
|
06-12-2009, 01:05 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Quote:
Originally Posted by Aaron™
Aren't you a great mod.
|
Can you blame him? Honestly when I read your reply I thought of Rick James.
Change:
PHP Code:
$postsQ .= 'thread= '.$thread['id'];
To:
PHP Code:
$postsQ .= 'thread = \''.$thread['id'].'\' ';
That should fix the problem with the spaces.
Last edited by NullPointer; 06-12-2009 at 01:06 AM..
|
|
|
|
06-12-2009, 04:12 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 102
|
Still doesn't fix the error tho.
I've un-hid the category for you to see. The error and to see the $postsQ;
http://zyberscape.com/
For the source of _index.php
http://zyberscape.com/index.phps
Last edited by Aaron™; 06-12-2009 at 04:30 AM..
|
|
|
|
06-12-2009, 06:39 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 303
|
PHP Code:
while ($thread = mysql_fetch_array($threads)){ if ($postsQ != ""){ $postsQ .= " OR "; $poststhreadid .= 'thread = \''.$thread['id'].'\' '; }else{ $postsQ .= ''; //removes OR from SQL } } $posts = mysql_query("SELECT * FROM posts WHERE '".$poststhreadid."' '".$postsQ."' ORDER BY createdYear DESC, createdMonth DESC, createdDate DESC, createdHour DESC, createdMinute DESC, createdSecond DESC");
__________________
Websites Created;
warscope.com
ratepayers.org.nz
Last edited by lothop; 06-12-2009 at 06:47 AM..
|
|
|
|
06-12-2009, 07:26 AM
|
Re: Warning: mysql_fetch_array()
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Maybe if you try to simplify your query:
Code:
SELECT * FROM threads WHERE forum in (1,2,3,102,103,14)
No need to add OR and such.
PHP Code:
$threads = mysql_query("SELECT * FROM threads WHERE forum={$row2['id']} ORDER BY id ASC"); $list=""; while ($thread = mysql_fetch_array($threads)){ if($list!=''){ $list.=","; } $list.=$thread['id']; } $posts = mysql_query("SELECT * FROM posts WHERE thread in ($list) ORDER BY createdYear DESC, createdMonth DESC, createdDate DESC, createdHour DESC, createdMinute DESC, createdSecond DESC");
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
|
« Reply to Warning: mysql_fetch_array()
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|