Jump to content

Archived

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

Mutley

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

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites


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




Is there a need for an extra space on that?


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

shoudl work.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
How about:


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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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. :)

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.