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.

I'm probably not right here but worth a shot - try == on line 10

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

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.