Skip to main content
Inspiring
March 11, 2010
Question

Ajax/MySQL problems

  • March 11, 2010
  • 1 reply
  • 551 views

I have a page that lists industries using horizontal looper.

That works fine.

Now my customer has decided that he wants to cut down on the text on the page by having a list from A-Z at the top from where a user can select.

So I decided I did not want a page refresh so I looked @ http://www.w3schools.com/PHP/php_ajax_database.asp

I have modified the code to my needs, but the sql keeps falling down and give me this message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL  result resource in

I also get Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL  result resource in

I do not know what to do.

Can some one help me?

-- html page --

<a href="#" onclick="showUser(this.value)">A</a> B C

<div id="txtHint"><b>Person info will be listed here.</b></div>

-- php page --

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'demo', 'demo');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("demo", $con);
$sql="SELECT * FROM industry WHERE industry LIKE %'".$q."' ORDER BY industry ASC";


$sql_endRow = 0;
$sql_columns = 6; // number of columns
$sql_hloopRow1 = 0; // first row flag
do {
    if($sql_endRow == 0  && $sql_hloopRow1++ != 0) echo "<tr>";
   ?>
      <td><div id="bdTagLinks"><a href="search_by_industry.php?id=<?php echo $row_sql['ind_id']; ?>"><?php echo $row_sql['industry']; ?></a></div></td>
      <?php  $sql_endRow++;
if($sql_endRow >= $sql_columns) {
  ?>
    </tr>
    <?php
$sql_endRow = 0;
  }
} while ($row_sql = mysql_fetch_array($result));
if($sql_endRow != 0) {
while ($sql_endRow < $sql_columns) {
    echo("<td> </td>");
    $sql_endRow++;
}
echo("</tr>");
}


mysql_close($con);
?>

The JS page has not changed apart from the php pages name.

This topic has been closed for replies.

1 reply

Participating Frequently
March 11, 2010

Hello,

You did not execute the sql request thus $result is empty.

After this line :

$sql="SELECT * FROM industry WHERE industry LIKE %'".$q."' ORDER BY industry ASC";

you have to add :

$result=mysql_query($sql);

Broz

www.broz-reggae-tabs.com

Inspiring
March 11, 2010

Hi,

I had this in the code originally, but it was not working, so I was trying different things to see.

It says error is on line 28 which is:

} while ($row_sql = mysql_fetch_array($result));

Participating Frequently
March 11, 2010

Hi,

If you have the same error by adding the line that I indicated to you, there should be also an error in the syntax of your request.

It seems to me strange here : LIKE %'".$q."'

That would not be rather : LIKE '%".$q."'

Broz