Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso


stubarny

Recommended Posts

Hello,

 

I'm getting the following error message on the commented line of code below. 2 results are being returned by the sql command ($nrows = 2). The strange thing is that the error message only triggers on the second result ($i=1).

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... (i've removed the file address)

 

<?php
$haystack = $_GET[q];
$query ="SELECT * FROM research_job_searches";
$result=mysql_query($query)
  or die ("Connection to database table failed. 35. "  . mysql_error());	
$nrows=mysql_num_rows($result);

if ($nrows<>'0')
{
	for ($i=0;$i<$nrows;$i++)
		{
			# error occurs on line below for $i=1
                                                                $record = mysql_fetch_array($result, MYSQL_BOTH);			
                                                                $needle = $record[research_job_search_url_keyword] . "-jobs";
                                                }
                }
?>

 

Any ideas?

 

Thanks,

 

Stu

Link to comment
Share on other sites

just re-created this from different set of source code and it seems to work. I'm not sure what i've done differently but here's the solution:

 

$query ="SELECT * FROM research_job_searches";

$result=mysql_query($query)

or die ("Connection to database table failed. 106."  . mysql_error() );

$nrows=mysql_num_rows($result);

 

if ($nrows<>'0')

{

for ($i=0;$i<$nrows;$i++)

{

$record = mysql_fetch_array($result, MYSQL_ASSOC);

}

}

Link to comment
Share on other sites

Try this:

 

<?php
$haystack = $_GET[q];
$query ="SELECT * FROM research_job_searches";
$result=mysql_query($query)
  or die ("Connection to database table failed. 35. "  . mysql_error());	
$nrows=mysql_num_rows($result);

if ($nrows > 0){
while($record = mysql_fetch_array($result, MYSQL_BOTH)){
	$needle = $record[research_job_search_url_keyword] . "-jobs";
	echo $needle."<br>";
}
}
?>

Link to comment
Share on other sites

Thanks little Guy,

 

I think I've got to the bottom of it. I was putting the following preg_match within the loop. The outputted $result variable from the preg_match was messing up the msql_fetch_array - can't believe that took me 2 days to figure out!

 

Thanks for your help though - I'll use the while loop in future, it reads more cleanly.

 

Thanks,

 

Stu

 

if (preg_match("/$needle/i", $haystack, $result))

{

    # echo "<br>A match was found.<br>";

# echo "<br>0, $result[0]<br>";

# echo "<br>1, $result[1]<br>";

# echo "<br>2, $result[2]<br>";

 

$display_research_job_search_url_keyword = $research_job_search_url_keyword;

$display_research_job_search_index = $research_job_search_index;

}

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.