Jump to content

Can someone please help!!!


gatez

Recommended Posts

i keep gettin an error 

 

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource

on line 17    $result = mysql_query($query);

 

 

 

can someone tell me where the problem is

 

<?

include "header.php";

$fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=".$user.")";

$friends = $facebook->api_client->fql_query($fql);

$query="SELECT ratings_winner FROM `ratings` WHERE ratings_winner='$user'";

 

for ($i=0; $i<count($friends);$i++)

{

$query = $query . " OR ratings_winner=" . $friends[$i]['uid'];

}

 

$query .= " GROUP BY ratings_winner ORDER BY count( ratings_winner ) DESC LIMIT 0 , 15";

mysql_connect('localhost',$mysqlusername,$mysqlpassword);

@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query($query);

mysql_close();

$num = mysql_numrows($result);                            <------------------------this line has the error

?>

<div style="padding-left:20px"><h1>Your most fight-able friends</h1></div>

<p />

<center>

<table width=90%>

<?

if ($num==0)

{

?>

<div style="padding-left:30px; padding-right:30px">

<fb:error><fb:message>Wow, no friends smashed yet</fb:message>This is tragic - none of your friends (or you) have been virtually "smashed" yet - so now its upto you to populate these rankings. And there's only one way to do that - <b><a href="http://apps.facebook.com/rather_fight/index.php">Play The Game</a></b>. Good luck! </fb:error></div>

<?

include "footer.php";

die();

}

 

$i=0;

 

while ($i < $num) {

 

$uid=mysql_result($result,$i,"ratings_winner");

$j = $i+1;

?>

<tr>

<td><center><a href="http://apps.facebook.com/rather_fight/mystats.php?id=<? echo $uid; ?>"><fb:profile-pic uid="<? echo $uid; ?>" linked="no" /><br><font size="2" face="Verdana"><b><? echo $j; ?>. </b></font> <fb:name uid="<? echo $uid; ?>" ifcantsee="Name hidden" linked="no" /></a></center>

</td>

<?

$i++;

if ($i < $num)

{

$uid=mysql_result($result,$i,"ratings_winner");

$j=$i+1;

?>

 

<td><center><a href="http://apps.facebook.com/rather_fight/mystats.php?id=<? echo $uid; ?>"><fb:profile-pic uid="<? echo $uid; ?>" linked="no" /><br><font size="2" face="Verdana"><b><? echo $j; ?>. </b></font> <fb:name uid="<? echo $uid; ?>" linked="no" ifcantsee="Name hidden" /></a></center>

</td>

<?

}

$i++;

if ($i < $num)

{

$uid=mysql_result($result,$i,"ratings_winner");

$j=$i+1;

?>

 

<td><center><a href="http://apps.facebook.com/rather_fight/mystats.php?id=<? echo $uid; ?>"><fb:profile-pic uid="<? echo $uid; ?>" linked="no" /><br><font size="2" face="Verdana"><b><? echo $j; ?>. </b></font> <fb:name uid="<? echo $uid; ?>" ifcantsee="Name hidden" linked="no" /></a></center>

</td>

</tr>

<?

}

$i++;

}

?>

</center>

<?

include "footer.php";

 

Link to comment
Share on other sites

simple debugging stuff...

 

change:

$result = mysql_query($query);
mysql_close();
$num = mysql_numrows($result);

 

to:

if ( !$result = mysql_query($query) ) {
    die('MySQL error for query:<br>$query<br>' . mysql_error());
}
mysql_close();
$num = mysql_numrows($result);

 

you should get more details about the error now.

 

PhREEEk

Link to comment
Share on other sites

MySQL error for query:

SELECT ratings_winner FROM `ratings` WHERE ratings_winner='634794851' OR ratings_winner=305300379 OR ratings_winner=500254115 OR ratings_winner=500300799 OR ratings_winner=501793914 OR ratings_winner=504304794 OR ratings_winner=505410815 OR ratings_winner=505905624 OR ratings_winner=506298469 OR ratings_winner=506661532 OR ratings_winner=507668933 OR ratings_winner=508256272 OR ratings_winner=509671350 OR ratings_winner=509733755 OR ratings_winner=510103823 OR ratings_winner=510311239 OR ratings_winner=510312727 OR ratings_winner=510419835 OR ratings_winner=510430487 OR ratings_winner=510473822 OR ratings_winner=510675385 OR ratings_winner=510779487 OR ratings_winner=510910671 OR ratings_winner=510986403 OR ratings_winner=511203549 OR ratings_winner=511322920 OR ratings_winner=511458462 OR ratings_winner=511520539 OR ratings_winner=511588971 OR ratings_winner=511728077 OR ratings_winner=511882162 OR ratings_winner=511885163 OR ratings_winner=511935714 OR ratings_winner=511986722 OR ratings_winner=512107761 OR ratings_winner=512123009 OR ratings_winner=512207069 OR ratings_winner=512383175 OR ratings_winner=512672921 OR ratings_winner=512734820 OR ratings_winner=513128360 OR ratings_winner=513259991 OR ratings_winner=513360934 OR ratings_winner=513476701 OR ratings_winner=513537732 OR ratings_winner=513826787 OR ratings_winner=514043586 OR ratings_winner=514710890 OR ratings_winner=514828125 OR ratings_winner=514858557 OR ratings_winner=514925605 OR ratings_winner=515025359 OR ratings_winner=515040957 OR ratings_winner=515635376 OR ratings_winner=515967710 OR ratings_winner=516234997 OR ratings_winner=517017717 OR ratings_winner=517530102 OR ratings_winner=517559938 OR ratings_winner=518346952 OR ratings_winner=518606809 OR ratings_winner=519470345 OR ratings_winner=525936276 OR ratings_winner=542476557 OR ratings_winner=544155260 OR ratings_winner=545218893 OR ratings_winner=548446078 OR ratings_winner=550156007 OR ratings_winner=550670603 OR ratings_winner=557425994 OR ratings_winner=558640071 OR ratings_winner=558955260 OR ratings_winner=561145478 OR ratings_winner=562520095 OR ratings_winner=562862613 OR ratings_winner=564167976 OR ratings_winner=564869545 OR ratings_winner=566038026 OR ratings_winner=579928938 OR ratings_winner=580177400 OR ratings_winner=590307393 OR ratings_winner=590805256 OR ratings_winner=591755327 OR ratings_winner=591805290 OR ratings_winner=592634182 OR ratings_winner=598320089 OR ratings_winner=598430525 OR ratings_winner=605520164 OR ratings_winner=607860117 OR ratings_winner=610265243 OR ratings_winner=610455396 OR ratings_winner=618718240 OR ratings_winner=622450633 OR ratings_winner=623670007 OR ratings_winner=625340190 OR ratings_winner=630275253 OR ratings_winner=638275547 OR ratings_winner=639766824 OR ratings_winner=640036779 OR ratings_winner=642365214 OR ratings_winner=643320626 OR ratings_winner=651900310 OR ratings_winner=652155164 OR ratings_winner=654485337 OR ratings_winner=659351474 OR ratings_winner=665975787 OR ratings_winner=669794262 OR ratings_winner=672575093 OR ratings_winner=675146821 OR ratings_winner=676362914 OR ratings_winner=681030242 OR ratings_winner=686365378 OR ratings_winner=690309258 OR ratings_winner=691785651 OR ratings_winner=692585227 OR ratings_winner=696510524 OR ratings_winner=701210660 OR ratings_winner=703090026 OR ratings_winner=704110541 OR ratings_winner=711200083 OR ratings_winner=712013950 OR ratings_winner=713765503 OR ratings_winner=720776550 OR ratings_winner=725773785 OR ratings_winner=726225303 OR ratings_winner=731360429 OR ratings_winner=734455415 OR ratings_winner=738234452 OR ratings_winner=738390273 OR ratings_winner=744410082 OR ratings_winner=770662932 OR ratings_winner=783445031 OR ratings_winner=792175213 OR ratings_winner=861400634 OR ratings_winner=874510396 OR ratings_winner=875785088 OR ratings_winner=894440206 OR ratings_winner=896330388 GROUP BY ratings_winner ORDER BY count( ratings_winner ) DESC LIMIT 0 , 15

Invalid use of group function

 

 

 

 

thats a bunch of ids pulled from my database?

Link to comment
Share on other sites

Um. This thread is exactly the same as the one gatez posted yesterday, including adding mysql_error() reporting to get what the problem with the query was - http://www.phpfreaks.com/forums/index.php/topic,169849.0.html

 

gatez, if you already have a thread for a problem, don't start another duplicate thread. It just wastes everyone's time getting to the point where the previous thread left off.

 

 

Link to comment
Share on other sites

We've got you to the point where your SQL query and the error are displayed... what more can we do? We don't know what it's supposed to do... does the query look good to you? Is it what you expected? You have to tell us what you expect the results to be if we are going to help design the proper query.

 

PhREEEk

Link to comment
Share on other sites

If you bought it, please email the author for tech support. We can't be mind-readers and try to figure out what it's supposed to do, and what the end result should look like. I'm afraid we can't be of much further help, unless a helper comes along who is familiar with this script you have...

 

PhREEEk

Link to comment
Share on other sites

well the person i bought it from is to no avil 

that part of the script is supposed to pull users from the database and sort  them

 

 

so lets say the script was the most hot chics  that would pull information from that database based on user votes

 

i have the database info as well

Link to comment
Share on other sites

The mysql error - Invalid use of group function - is most likely occurring because the count() function is being used in the ORDER BY clause.

 

If your query was as follows, it should work -

 

SELECT ratings_winner, count(*) as cnt FROM `ratings` WHERE ratings_winner='634794851' OR ratings_winner=305300379 OR ... all the OR'ed values, removed for clarity  ... GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15

 

I just noticed in the query that the first ratings_winner = value is enclosed in single-quotes. While this will not prevent the query from working, the single-quotes should not technically be there.

 

 

Link to comment
Share on other sites

i just imported the database tables etc when i did this

 

 

 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

 

--

-- Database: `********`

--

 

-- --------------------------------------------------------

 

--

-- Table structure for table `comments`

--

 

CREATE TABLE IF NOT EXISTS `comments` (

  `comments_comment` text NOT NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

-- --------------------------------------------------------

 

--

-- Table structure for table `minifeed`

--

 

CREATE TABLE IF NOT EXISTS `minifeed` (

  `minifeed_id` int(11) NOT NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

-- --------------------------------------------------------

 

--

-- Table structure for table `notifications`

--

 

CREATE TABLE IF NOT EXISTS `notifications` (

  `notifications_id` int(11) NOT NULL,

  KEY `notifications_id` (`notifications_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

-- --------------------------------------------------------

 

--

-- Table structure for table `ratings`

--

 

CREATE TABLE IF NOT EXISTS `ratings` (

  `ratings_userid` int(11) NOT NULL,

  `ratings_winner` int(11) NOT NULL,

  `ratings_loser` int(11) NOT NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

-- --------------------------------------------------------

 

--

-- Table structure for table `users`

--

 

CREATE TABLE IF NOT EXISTS `users` (

  `users_facebookid` int(11) NOT NULL,

  `users_sendnotifications` tinyint(1) NOT NULL default '1',

  KEY `users_facebookid` (`users_facebookid`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Link to comment
Share on other sites

The following part of the code is where the query is formed -

 

$query="SELECT ratings_winner FROM `ratings` WHERE ratings_winner='$user'";

for ($i=0; $i<count($friends);$i++)
{
$query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
}

$query .= " GROUP BY ratings_winner ORDER BY count( ratings_winner ) DESC LIMIT 0 , 15";

 

To make the changes that I believe will fix this, change those lines to the following (I also removed the single-quotes around the first value ) -

 

$query="SELECT ratings_winner, count(*) FROM `ratings` WHERE ratings_winner=$user";

for ($i=0; $i<count($friends);$i++)
{
$query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
}

$query .= " GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15";

Link to comment
Share on other sites

like  this?

 

 

<?

include "header.php";

$fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=".$user.")";

$friends = $facebook->api_client->fql_query($fql);

$query="SELECT ratings_winner, count(*) FROM `ratings` WHERE ratings_winner=$user";

 

for ($i=0; $i<count($friends);$i++)

{

$query = $query . " OR ratings_winner=" . $friends[$i]['uid'];

}

 

$query .= " GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15";

mysql_connect('localhost',$mysqlusername,$mysqlpassword);

@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query($query);

mysql_close();

$num = mysql_numrows($result);

 

Link to comment
Share on other sites

Actually I see that I left off an "as cnt" alias, which would have generated a syntax error in the ORDER BY clause, so it is unlikely that the code you executed was the code you just posted. It should not have given the same error as before.

 

Here is the corrected code I meant to post -

 

$query="SELECT ratings_winner, count(*) as cnt FROM `ratings` WHERE ratings_winner=$user";

for ($i=0; $i<count($friends);$i++)
{
$query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
}

$query .= " GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15";

 

I just tested both your original query and the one I gave, and in mysql 5.0.45, they both work without any mysql error.

 

My guess at this point is that your version of mysql does not support the combination of GROUP BY and ORDER BY.

Link to comment
Share on other sites

awesome  it worked  how what did you change?

 

 

i also have a error on line 9 with this

 

 

<?

include "header.php";

 

$query="SELECT ratings_winner FROM `ratings`GROUP BY ratings_winner ORDER BY count( ratings_winner ) DESC LIMIT 0 , 30";

mysql_connect('localhost',$mysqlusername,$mysqlpassword);

@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query($query);

mysql_close();

$num = mysql_numrows($result);

?>

<div style="padding-left:20px"><h1>Most fight-able people on Facebook</h1></div>

<p />

<center>

<table width=90%>

<?

if ($num==0)

{

?>

<div style="padding-left:30px; padding-right:30px">

<fb:error><fb:message>Wow, no friends smashed yet</fb:message>This is tragic - none of your friends (or you) have been virtually "smashed" yet - so now its upto you to populate these rankings. And there's only one way to do that - <b><a href="http://apps.facebook.com/rather_fight/index.php">Play The Game</a></b>. Good luck! </fb:error></div>

<?

include "footer.php";

die();

}

 

$i=0;

 

while ($i < $num) {

 

$uid=mysql_result($result,$i,"ratings_winner");

$j = $i+1;

?>

 

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.