0

Hi i'm trying to successfully get this PHP code to search MySQL database called test2
that has a table called questions, in that table there are columns called ID, Question, Category and Answer.

This code is an excerpt from a tutorial that allows you to search the mysql database for state names, i did it successfully but wherever i try to change the selecting the column name questions to display in the search results and change the db_name to test2, i just get the error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search\getStates.php on line 10

here is my search.php

<?php

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test2") or die(mysql_error());


$partialStates = $_POST['partialStates'];

$states = mysql_query("SELECT question FROM questions WHERE name LIKE '%$partialStates%'");
while($state = mysql_fetch_array($states)) {
        echo "<div>".$state['name']."</div>";
}
?>

here is my index.htm code

<html>
<head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
        function getStates(value){
                        $.post("getStates.php",{partialStates:value},function(data){
                                $("#results").html(data);
                });
        }
    </script>
</head>

<body>
<input type="text" onKeyUp="getStates(this.value)" >
    <br>
    <div id="results"></div>

</body>
</html>

Can somebody assist me on this please? Thanks.

2
Contributors
3
Replies
8
Views
5 Years
Discussion Span
Last Post by IanArcher
0

Ignore the above post by me obviously I'm clearly wrong here :( instead,

try: while($state = mysql_fetch_assoc($states)) {

Edited by momo219: n/a

0

Ignore the above post by me obviously I'm clearly wrong here :( instead,

try: while($state = mysql_fetch_assoc($states)) {

I managed to get it working, but it was some a WHERE `question` LIKE that i didn't include, i fixed it and it worked. Thanks for you help though :)

Now i need ask one more favor

right here is the results as you can see http://projecttower.site50.net/search/
I need to add to assign URLs to the questions, like this http://corporate.thechamberteam.com/livesearch/

so when they are typed in the box i can click the question and it will take me to the question page with the answer, i already created a column called 'url' in it. Can i do this in MySQL?

Edited by IanArcher: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.