Jump to content

Recommended Posts

Can anyone please explain this error to me?

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sites/site138/web/ottersdb/confirmmatch3.php on line 149

 

I set up the record set using the following code ($players is an array):

$players = $_POST['matchTeam'];

$playerGames = "SELECT * FROM players WHERE playerID IN (". implode(", ",$players). ")";

$playerGames_query = mysql_query($playerGames) or die(mysql_error());

$rsPlayerGames = mysql_fetch_assoc($playerGames_query);

 

Then I want to show the results on screen using:

<?php echo $rsPlayerGames['playerID']; ?> <?php echo $rsPlayerGames['playerFirstName']; ?> <?php echo $rsPlayerGames['playerLastName']; ?> <?php echo $rsPlayerGames['playerGames'];  ?>

<?php } while ($rsPlayerGames = mysql_fetch_assoc($playergames_query)) ?>

 

(the last line is the line 149 mentioned in the error)

 

Any suggestions as to what I've done wrong? I'm new to this stuff and seem to be taking two steps backwards for every one step forward!

Link to comment
https://forums.phpfreaks.com/topic/65941-mysql_fetch_assoc-error/
Share on other sites

It showed: query: SELECT * FROM players WHERE playerID IN (1, 2)

(I selected the first two items in the list)

 

So from what I've picked up it seems to be missing hyphens around the values 1 and 2.

 

In another post someone gave me the following code to implode the $players variable and put commas in there, but it hasn't put hyphens in.

$playerGames = "SELECT * FROM players WHERE playerID IN (". implode(", ",$players). ")";

 

Any idea how I could modify this to get the hyphens? (If they actually necessary.) I've played around with it but keep getting knocked back.

Doh! Meant single quotes. Not thinking straight as I've been looking at this screen for far too long!

 

I want the query to look like:

query: SELECT * FROM players WHERE playerID IN ('1', '2')

 

Or at least that's what I think it should look like based on the stuff I read about IN.

but that depends on the datatype of the column-playerID.

 

If playerID is of numeric type in db,then query wud b

  SELECT * FROM players WHERE playerID IN (1, 2)

If playerID is of varchar type in db,then query needs 2 b

  SELECT * FROM players WHERE playerID IN ('1', '2')

The primary key is integer, so I guess that having (1,2) should work then.

 

Something else must be causing the problem, as I hard-coded in a player name into the IN parameter and it only returned one record and the same error - even though there are two players with names matching the parameter.

 

$playerGames = "SELECT * FROM players WHERE playerFirstName IN ('mark')";

 

There are two records in the database which have 'mark' as their value in the playerFirstName column, so I thought I'd get two records coming back when I did this query.

 

Is IN even the correct thing to use here? I was using it because I thought it was necessary when I was sending multiple values in the query.

$playerGames = "SELECT * FROM players WHERE playerID IN (". implode(", ",$players). ")";

Or could I use playedID = (". implode(", ",$players). ")?

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.