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
https://forums.phpfreaks.com/topic/245832-help-with-a-query/
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
https://forums.phpfreaks.com/topic/245832-help-with-a-query/#findComment-1262659
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
https://forums.phpfreaks.com/topic/245832-help-with-a-query/#findComment-1262661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.