Jump to content

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


Mutley

Recommended Posts

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


[code=php:0]
<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>
[/code]





...Any help would be much appreciated on this error. Thank-you.
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:

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

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

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

if($id) {[/code]

Again? Not sure how to work it.
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.com/includes/teams/teams.php?id=$id");

for it to work sucesfuly

Liam
[quote author=hostfreak link=topic=103863.msg413901#msg413901 date=1155306602]
How about:


[code]
$id = $_GET['id'];

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

Yep, close, I did this:

[code]$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:';
}[/code]

But it doesn't "find" the files to include using the ID, it just goes straight to the echo.
[quote author=shocker-z link=topic=103863.msg413902#msg413902 date=1155306730]
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.com/includes/teams/teams.php?id=$id");

for it to work sucesfuly

Liam
[/quote]

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. :)
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..
In this case, just do that:

[code]
$id = (value you want);

include(whatever relative path you want WITHOUT url variables);
[/code]

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.

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.