Re: Not returning results.
Try this:
PHP Code:
<?php
include ("/home/welovera/public_html/inc/database.php");
$query1 = mysql_query ( "SELECT * FROM `Stations`" );
while ( $sta = mysql_fetch_object ( $query1 ) ){
$fruits = array( $sta->Title => array('image' => $sta->Logo, 'description' => $sta->Genre) );
}
?>
If you use a variable inside single quotes, it won't be considered as variable.
For example:
PHP Code:
<?php
$a = 'hello';
echo '$a Jamie!'; // output = "$a Jamie!"
echo "$a Jamie!"; // output = "Hello Jamie!"
?>
:wave:
Re: Not returning results.
THanks for your reply, how ever that still didn't manage to work.
This is what the sample data usually looks like when not using php to create the data...
Code:
$fruitss = array(
'Apple' => array('image' => 'assets/images/fruits/alfalfa.jpg', 'description' => 'One cup of raw, sprouted alfalfa seeds, contains 1.32 grams of protein.'),
That works, how ever the code you provided still wont work.
Any other ideas?
Jamie
Re: Not returning results.
"That didn't worked" doesn't gives any clues to me! I didn't test run your code. I just copied your code to the reply box, changed here and there and then posted.
It would be lot more helpful if you tell me what is it now showing. Does the fruits array contains anything ? Or is it showing any errors ? What is the output of the array after you ran that code ? And so on..
:wave:
Re: Not returning results.
Well when it checks the php page with the code on when a user types in the search box it is coming back 0results found.
I echo'd $fruits; on the page, and it just shows 'Array' once rather than a list of the titles from the Stations database.
Thanks
Jamie
Re: Not returning results.
ok..
Try testing it with this:
PHP Code:
<?php
include ("/home/welovera/public_html/inc/database.php");
$query1 = mysql_query ( "SELECT * FROM `Stations`" ) or die(mysql_error());
while ( $sta = mysql_fetch_object ( $query1 ) ){
$fruits[] = array( $sta->Title => array('image' => $sta->Logo, 'description' => $sta->Genre) );
}
print_r($fruits);
?>
Check whether it is giving anything.
:wave:
Re: Not returning results.
Hi that shows the array and is showing all the stations like it should, but the search bar that checks the data.php page with that code on just returns 0 results.
This is how the array looks and works (when it's not using the code to grab data from the database and puting it on the page)
Code:
<?php
$fruits = array(
'Apple' => array('image' => 'assets/images/fruits/apple.jpg', 'description' => 'One of America\'s favorite fruits.'),
'Avocado' => array('image' => 'assets/images/fruits/avocado.jpg', 'description' => 'The avocado is a dense, evergreen tree, shedding many leaves in early spring.'),
'Banana' => array('image' => 'assets/images/fruits/banana.jpg', 'description' => 'Bananas are fast-growing herbaceous perennials arising from underground rhizomes.'),
);
?>
Thanks
Jamie
Re: Not returning results.
Means, the code that populates the array are working fine and only the ajax is showing problem ? That is, the AJAX is not fetching the data from this php page ? If so, please post the code that you used to fetch. I mean the AJAX code.
:wave:
Re: Not returning results.
HI mate, this is the code to fetch the data..
Code:
$(document).ready(function() {
$('#field1').smartSuggest({
src: 'assets/php/search_multiple.php',
minChars: 1
});
If i manually type in the data.php page some data it works, just does not work if PHP is automatically adding the data.
Re: Not returning results.
Quote:
If i manually type in the data.php page some data it works
You mean if you access that page directly, it is echoing the data fine ?
Quote:
just does not work if PHP is automatically adding the data.
:confused:
So, you are using this Smart Suggest jQuery Plugin. Isn't it ? Are you echoing the data in JSON format ?
Quote:
* The plugin will send a GET query to your data source. The user's search text is sent as the q variable.
* Your script needs to search your database with that query and output the results in JSON format.
:wave:
Re: Not returning results.
Hey,
Thanks for your reply.
I am echoing it the way you told me too, and yes I am using that plugin, but its not made to work with a database, so that's what I am trying to add to it.
Any ideas / examples?
Regards
Jamie
Re: Not returning results.
Try using the header:
Code:
header('Content-type: application/json');
in your php page where you echo the array in JSON format.
See if it helps.
:wave:
Re: Not returning results.
I tried that, It still will not work,
Any other ideas?
Jamie.
Re: Not returning results.
I think, you are not echoing the JSON data in the correct format. Goto that SmartSuggest's site. Scroll down to point 4 titled "Create your JSON output source". The fourth one in the list is a sample format of how the JSON data should be. Are you echoing your JSON data in that format ?
Also, did you noticed the first one:
Quote:
The plugin will send a GET query to your data source. The user's search text is sent as the q variable.
This mean, in the PHP page, you will get the user entered text in $_GET array:
PHP Code:
$search = $_GET['q'];
So you can use this data in your db query.
:wave: