Current location: Hot Scripts Forums » Programming Languages » PHP » simple $num_rows help


simple $num_rows help

Reply
  #1 (permalink)  
Old 06-22-04, 12:44 AM
BigTime BigTime is offline
New Member
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
simple $num_rows help

Im trying to gather a sum of records that match a certain criteria, then return the number of records that match only. This would basically be for a win loss column for a jr football league.

Ive messed around all day and still cant get it to work.

My latest rendition is the following code, but it is returning an error on the line that begins with $num_rows -- Exactly it says:
mysql_num_rows(): supplied argument is not a valid MySQL result


I just cant figure out what is going on and Im pulling my hair out....for sure there are 2 records that match the select criteria....

Can anyone that is a bit more experienced in this help?

<.?php

$division = "Featherweight";
$league = "Sunday";
$hometeam = "Fox Lake";

$result = mysql_query("SELECT * FROM `schedules` WHERE `league` = '$league' AND `division` = '$division' AND `hometeam` = '$hometeam' AND `homescore` > `awayscore` FROM schedules");
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?.>
Reply With Quote
  #2 (permalink)  
Old 06-22-04, 04:49 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you shouldn't have 2 FROMs in the query!
use this query instead:
Code:
SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-22-04, 09:41 AM
BigTime BigTime is offline
New Member
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hehe

Well that just how convoluted my thought process got yesterday I guess.....FROM started out at the beginning and then ended up at the end, and neither got deleted.

HOWeva......

Still same error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Calling from the line that is the beginning of $num_Rows


<?php

$division = "Featherweight";
$league = "Sunday";
$hometeam = "Fox Lake";

$result = mysql_query("SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore");
$num_rows = mysql_num_rows($result);

echo "$num_rows Wins\n";

?>
Reply With Quote
  #4 (permalink)  
Old 06-22-04, 11:06 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
then try changing this:
PHP Code:

$result mysql_query("SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore"); 

to this:
PHP Code:

$result mysql_query("SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore")or

die(
mysql_error()); 
and see what is the error message that appears and tell us ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 06-22-04, 11:48 AM
BigTime BigTime is offline
New Member
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hmmm....

Well now Im all embarassed -- It says no Database selected......I'm connecting the same way I normally do...but I'm sure there was something simple here Im overlooking.......

Full on code:

<?
$usr = "username";
$pwd = "password";
$db = "database";
$host = "localhost";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

$division = "Featherweight";
$league = "Sunday";
$hometeam = "Fox Lake";

$result = mysql_query("SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore")or
die(mysql_error());

$num_rows = mysql_num_rows($result);

echo "$num_rows Wins\n";

?>


Working Now and I changed it to:

<?
$dbuser="userinfo";
$dbpass="password";
$dbname="database name"; //the name of the database
$cid = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $cid) or die ($dbname . " Database not found." . $dbuser);


$division = "Featherweight";
$league = "Sunday";
$hometeam = "Fox Lake";

$result = mysql_query("SELECT * FROM schedules WHERE league = '$league' AND division = '$division' AND hometeam = '$hometeam' AND homescore > awayscore", $cid)or
die(mysql_error());

$num_rows = mysql_num_rows($result);

echo "$num_rows Wins\n";
mysql_close($cid);
?>


Thank you Nevermind very much for getting the juices flowing and helping me sort this out!!!

Last edited by BigTime; 06-22-04 at 12:02 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with this keyword script - i'm sure it's simple! dudeman248 JavaScript 2 05-19-04 05:11 PM
Need a simple image with info text script (I can even pay you for this) nezbie Script Requests 2 04-05-04 09:47 AM
simple photo gallery forcer Script Requests 5 01-08-04 09:07 AM
Need simple example of making a website with Perl JohnElmore Perl 5 10-04-03 09:46 PM
I need a very simple calendar Giullare Script Requests 0 09-24-03 06:53 PM


All times are GMT -5. The time now is 05:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.