1,105,386 Community Members

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

Member Avatar
GraficRegret
Junior Poster
182 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

shouldn't this

while(($row=mysql_fetch_assoc($resource))!==false)

read in stead

while(($row=mysql_fetch_array($resource))!==false)

I am not posative on this, I am stil pretty new to php, however I have not seen the assoc function used before, have only ever seen the $row use the fetch array

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

mysql_fetch_array function returns result in both associative and numeric arrays while

mysql_fetch_assoc function returns result only in an associative array.

It is the matter of what you want when choosing among them.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

for the 3 characters that have to be typed in so the jquery to launch and resource for that ?

All you have to do is check in the javascript code whether the search_term is at least 3 chars long. If not, you do not do an ajax call at all.

$(document).ready(function() {

    $('.autosuggest').keyup(function () {

        var search_term = $(this).attr('value');

        // if we have less than 3 chars just exit the function
        if(search_term.length < 3) {

            return;
        }

        ...
Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

And also I made a small mistake in the html code, sory. I put the result unnumbered list (ul) at the end of the page. I later realized that it should be in the place where you put it originally, just after the input box, since it is the basis for extending the input box into combo box. So please move it back there.

<input type="text" name="tag" value="" placeholder="All" class="autosuggest" />
<div class="dropdown">
<ul class="result">
</ul>
...
Member Avatar
DamzWildfire
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

yeah i had fix that Ul section already.

Member Avatar
DamzWildfire
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

so all i have to do is add this line of code to my js file and thats it?

 if(search_term.length < 3) {
return;
}
Member Avatar
GraficRegret
Junior Poster
182 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

@broj thanks for the clerification,

@Damz sorry i couldnt help guess im still too new to php

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

Yes, it basicaly exits teh function if there are less than 3 chars in the search_term. Haven't tested it, though, but I am pretty sure return statement works like exit in php. Other way of doing it would be wrapping the whole ajax bit in if(search_term.length >= 3).

$(document).ready(function() {

    $('.autosuggest').keyup(function () {

        var search_term = $(this).attr('value');

        if(search_term.length >= 3) {

            // read the values of the select elements (drop downs)

            // read the value of category 
            var category=$('#category').attr('value');

            // this is the conditions you will post over to the searchApp.php script
            // assembled here for clarity
            var conditions = {

                'search_term' : search_term,
                'category' : category
            }; 

            // alert(conditions.toSource());

            // post the conditions over to the searchApp.php script
            $.post('ajax/searchApp.php', conditions, function(data) {

                //alert(data);
                $('.result').html(data);

                /*
                // you can sort this out yourself
                $('.result li').click(function() {

                    var result_value=$(this).text();
                    $('.autosuggest').attr('value',result_value);
                    //alert(result_value);
                    $('.result').html('');

                });
                */

            });
        });
    });
}
Member Avatar
bradly.spicer
Posting Whiz in Training
238 posts since Oct 2012
Reputation Points: 47 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 6 [?]
 
0
 
<?php
require_once '../connect.php';
if(isset($_POST['search_term'])==true && empty($_POST['search_term'])==false)
{

$search_term=mysql_real_escape_string($_POST['search_term']);

$query = mysql_query("SELECT `Category`, `Type` FROM `autosuggest` WHERE `Category`='{$_POST['category']}'` AND `Type` LIKE '$search_term'");

while(($row = mysql_fetch_assoc($query))!==false)
{
echo '<li>',$row['Type'],'</li>';
}
}
?> 

You should format your code neater.

are you sure all the Vars are case sensative etc.

try this

Member Avatar
DamzWildfire
Junior Poster in Training
51 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

yeah i did thats thanks much.

Member Avatar
bradly.spicer
Posting Whiz in Training
238 posts since Oct 2012
Reputation Points: 47 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 6 [?]
 
0
 

IS there a reason your doing POST[customer]

rather than POST['customer']

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

POST[customer] is incorrect while POST['customer'] is correct in php code.

Question Answered as of 1 Year Ago by broj1, bradly.spicer and GraficRegret
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article