Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kristian Terziev
28,449 Pointslive search output
Hello,
I want to output information about item after finding it with live search using the id that we managed to get (https://teamtreehouse.com/forum/live-search)
I don't know any accepted way of doing that so I think I'll use php. For example for each element I have an image saved in a folder not in the database. and every image is called id.ext, where id is the auto incremented id in the database and ext is the extention.
<img src="../upload/images/<?php echo $id.'.png';?>"> // I use png for example as i haven's started the php cade that will get the extention.
The problem I face is that I want to get the id variable in Jquery to PhP so then i can use it like the code above.
Here is my Jquesry where the id is declared:
jQuery("#result").on("click", "div", function(e){
var $name = $(this).find(\'.name\').html();
var decoded = $("<div/>").html($name).text();
$(\'#searchid\').val(decoded);
var id = $(this).data(\'id\');
});
and then in the php file:
<?php $id=isset($_REQUEST['val'])?$_REQUEST['val']:'';?>
But it does not seem to work.
I have one more question: Is this a good way to dispaly information after live search without refreshing the page?