|
-
Nov 3rd, 2012, 11:00 AM
#1
Thread Starter
Fanatic Member
Not returning results.
Hi Guys, For some reason my code is returning no results and is not working, Basically I've created an ajax search box that searches a php file with the code below, I basically need it to be in the format below, just listing all of the data in the stations table.
Any ideas?
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'),
);}
?>
-
Nov 3rd, 2012, 12:26 PM
#2
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!"
?>
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 3rd, 2012, 12:54 PM
#3
Thread Starter
Fanatic Member
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
-
Nov 3rd, 2012, 01:00 PM
#4
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..
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 3rd, 2012, 07:16 PM
#5
Thread Starter
Fanatic Member
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
-
Nov 3rd, 2012, 11:51 PM
#6
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.
Last edited by akhileshbc; Nov 4th, 2012 at 12:01 AM.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 4th, 2012, 10:59 AM
#7
Thread Starter
Fanatic Member
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
-
Nov 4th, 2012, 11:14 AM
#8
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 6th, 2012, 05:43 AM
#9
Thread Starter
Fanatic Member
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.
-
Nov 6th, 2012, 06:53 AM
#10
Re: Not returning results.
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 ?
just does not work if PHP is automatically adding the data.

So, you are using this Smart Suggest jQuery Plugin. Isn't it ? Are you echoing the data in JSON format ?
* 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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 7th, 2012, 05:45 AM
#11
Thread Starter
Fanatic Member
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
-
Nov 7th, 2012, 07:43 AM
#12
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 7th, 2012, 11:43 AM
#13
Thread Starter
Fanatic Member
Re: Not returning results.
I tried that, It still will not work,
Any other ideas?
Jamie.
-
Nov 7th, 2012, 10:33 PM
#14
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:
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|