Jump to content


Photo

Warning: mysql_num_rows(): supplied argument is not...


  • Please log in to reply
10 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 11 August 2006 - 02:00 PM

I don't under stand this, when I goto the page and do a "?team_id=1" at the end of the URL I get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nsnitro2/public_html/yorkrufc/site/teams/teams.php on line 15

Here is the code...


<table border="1" cellpadding="0" cellspacing="2">
<?
require_once("connection.php");

$id = $_GET['team_id'];

if($id) {

	$sql  = "SELECT name, surname ";
	$sql .= "FROM teams ";
	$sql .= "WHERE team_id=".$id." ";
	
	$result = mysql_query($sql);
	
	if(mysql_num_rows($result)!=0) {

	while(list($name, $surname) = mysql_fetch_row($result)) {
	?>
<tr>
	<td>
	<?=$name?> <?=$surname?>
	</td>
</tr>
	<?
			}	
	}
}
else {
	
	echo "Please specify a Team ID";
}

?>
</table>





...Any help would be much appreciated on this error. Thank-you.
~ Mutley.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 02:06 PM

we need to find out what error MySQL is having so change

$result = mysql_query($sql);

to

$result = mysql_query($sql) or die(mysql_error().' ERROR using SQL line'. $sql);


Regards
Liam

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Nimwei

Nimwei
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 August 2006 - 02:08 PM



$sql .= "WHERE team_id=".$id." ";




Is there a need for an extra space on that?


$sql .= "WHERE team_id=".$id;

shoudl work.

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 11 August 2006 - 02:22 PM

Fixed it, the ?id= part on the URL had to be a number, not a word/letters.

However, I have a question with a similar subject.

I want to include files with an ?id= how do I make the file include all of that number for example:

include('teams/teams.php?id=$id')
include('scores/get_scores.php?id=$id')

would include teams.php?id=1, if 1 was in the ?id=1 of the url?

Can I just do:
$id = $_GET['id'];

if($id) {

Again? Not sure how to work it.
~ Mutley.

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 11 August 2006 - 02:30 PM

How about:


$id = $_GET['id'];

if(id == '$id') {
//code
} else {
Sorry but you are not authorized to view this team
}


#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 02:32 PM

From how you explained it then yes that should work but you can't include it as a local file! else it looks for a file with the name 'teams.php?id=1' for example instead of passing it thru the url.. so you would have to use

include("http://www.mydomain....ams.php?id=$id");

for it to work sucesfuly

Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 11 August 2006 - 02:35 PM

How about:


$id = $_GET['id'];

if(id == '$id') {
//code
} else {
Sorry but you are not authorized to view this team
}


Yep, close, I did this:

$id = $_GET['id'];

if($id == '$id') {

include "teams/teams.php?id=".$id."";
include "scores/scores.php?id=".$id."";
include "profiles/get_profile?id=".$id."";

}
else {
	echo'Please select a team below:';
	}

But it doesn't "find" the files to include using the ID, it just goes straight to the echo.
~ Mutley.

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 11 August 2006 - 02:51 PM

From how you explained it then yes that should work but you can't include it as a local file! else it looks for a file with the name 'teams.php?id=1' for example instead of passing it thru the url.. so you would have to use

include("http://www.mydomain....ams.php?id=$id");

for it to work sucesfuly

Liam


It works that way, thank-you but if anyone knows away with out the root domain path http://www.mysite.... etc, please let me know by reply. :)
~ Mutley.

#9 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 11 August 2006 - 02:55 PM

Why not just:
include("includes/teams/teams.php?id=$id");


#10 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 03:11 PM

you cant because it looks for the file called 'includes/teams/teams.php?id=$id' therefore not going through the server just simply including a file.. So you have to run it through your server e.g. how i showed with the address.. can't think of any other way for it to be done using include..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#11 tox_yray

tox_yray
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 August 2006 - 03:17 PM

In this case, just do that:

$id = (value you want);

include(whatever relative path you want WITHOUT url variables);

include(); will just make a big php page with ALL the code before interpreting it, so $id or the "parent" will be recognized by included pages.

As easy as that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users