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.
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
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. :)
Link to comment
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..
Link to comment
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.
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.