Jump to content

Help with a query


zero_ZX

Recommended Posts

Hi,

So maybe some fresh eyes can tell me what's wrong :P

 

<?PHP
//Get and display news
$result = mysql_query("SELECT * FROM groups_news WHERE group = ('$getid') AND topic = 0 ORDER BY date DESC");
IF (!result)
{
die(mysql_error());
}

while($row = mysql_fetch_array($result))
{
$topicid = $row["id"];
$authorid = $row["author"];
//Get profile info from author
$result2 = mysql_query("SELECT * FROM profiles WHERE id=('$authorid')  LIMIT 1");
IF (!result2)
{
die(mysql_error()) +"Result 2";
}
$row2 = mysql_fetch_array($result2);
//Count comments
$result3 = mysql_query("SELECT * FROM groups_news WHERE group=('$getid') AND topic=1");
IF (!result3)
{
die(mysql_error()+"Result 3");
}

 

Returns the usual:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\prog\groups.php on line 38

 

Line 38: while($row = mysql_fetch_array($result))

 

Any help is much appreciated.

Link to comment
Share on other sites

That error indicates the query failed and is returning a boolean FALSE instead of a result resource. Are you getting anything returned form mysql_error()? <-- nevermind for the moment, you won't get an error until you fix the problem pointed out by cunoodle2

Link to comment
Share on other sites

Are there more lines of code?  Are you sure that is the line 38?

 

I see these..

IF (!result)

 

SHOULD be..

IF (!$result)

 

(note they are ALL like that)

 

fail lol :D

 

Okay so got this:

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 'group = ('1') AND topic = 0 ORDER BY date DESC' at line 1

 

Will i have to escape date?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.