Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Warning: mysql_fetch_array()
Old 06-08-2009, 08:50 PM Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
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..
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-08-2009, 08:56 PM Re: Warning: mysql_fetch_array()
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
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
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-08-2009, 10:10 PM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
PHP Code:
You have an error in your SQL syntaxcheck 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 
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-09-2009, 01:04 AM Re: Warning: mysql_fetch_array()
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-09-2009, 01:31 AM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
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'];

Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-10-2009, 12:59 AM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
Anyone?
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-10-2009, 02:00 AM Re: Warning: mysql_fetch_array()
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
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'"
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 06-10-2009, 02:22 AM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
Still has the same error. I really think its in the $postsQ but I don't know what would be wrong.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 03:19 AM Re: Warning: mysql_fetch_array()
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
ok

start debugging

first echo the $sql variable out to see if the SQL Syntax is valid
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 03:26 AM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
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
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 10:48 AM Re: Warning: mysql_fetch_array()
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
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'
__________________

Please login or register to view this content. Registration is FREE

Last edited by davidj; 06-11-2009 at 10:51 AM..
davidj is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 02:28 PM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
So what one do you want me to echo there is 2.... $posts or $threads
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 03:04 PM Re: Warning: mysql_fetch_array()
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 03:40 PM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
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..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 07:01 PM Re: Warning: mysql_fetch_array()
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Quote:
Originally Posted by Aaron™ View Post
Where the hell would I ..... but yes I did...
lmao
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 06-11-2009, 09:14 PM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
Aren't you a great mod.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-12-2009, 01:05 AM Re: Warning: mysql_fetch_array()
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Aaron™ View Post
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 06-12-2009 at 01:06 AM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-12-2009, 04:12 AM Re: Warning: mysql_fetch_array()
Super Talker

Posts: 102
Trades: 0
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..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 06-12-2009, 06:39 AM Re: Warning: mysql_fetch_array()
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
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..
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-12-2009, 07:26 AM Re: Warning: mysql_fetch_array()
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Warning: mysql_fetch_array()

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 3.27748 seconds with 12 queries