Jquery, Ajax, Checkboxes, Filter, Result/Records Click

I have been following a number of tutorials, in particular this one;
http://hibbard.eu/use-ajax-to-filter-mysql-results-set/

my question is, how would I write the PHP/PDO/MYSQLI code to enable the final search result/record
clickable. as HREF= #Blank or something similar.

I.e employee: David < Click and open David’s file/profile etc.

I am struggling understanding how to add this into ajax/jquery or json. I know it can be achieved but it may be beyond my current skills. it seems no tutorial ive ever seen has this as a possibility, yet it seems quite normal when using any online profile/database searching etc.

Thanks in advance and i appreciate the response.

To be fair, the tutorial is pretty old and in need of an update. It would (for example) be better to use some kind of template to display the results on the client, or just return the necessary HTML from the server.

That said, the part you’d need to look at is here:

$.each(this, function(k , v) {
  tbl_row += "<td>"+v+"</td>";
});

Inside the loop, k and v will hold the key value pairs respectively. You could check for the key to bename and output something different.

E.g. (untested):

$.each(this, function(k , v) {
  if(k==="name"){
    tbl_row += "<td><a href='#'>"+v+"</a></td>";
  } else {
    tbl_row += "<td>"+v+"</td>";
  }
})

Thanks. Ill try that and see how i go.
Yeah i noticed that, the net has moved so fast the last 2 yrs that so many tutorials are deprecated. Plenty of mysql but limited pdo, ajax etc.

Can be a struggle for beginners.

Does the code you suggest indicate 1 value in the row or the whole row?

Thanks

Whole row.

http://hibbard.eu/blog/pages/ajax-filter/1/index.php

I was thinking of updating it and publishing on our main site, actually. It seems quite popular.

Keep asking questions and you’ll be good :slight_smile:

Yeah, that would be a good idea. ill.try it out tomorrow and let you know how it goes.
Its 9pm here, australian time. Thanks for the motivation haha.

1 Like

Hey, i tried as you suggested. it worked to a degree, however it made the whole “Name” column clickable as 1 URL, however I am unsure what the next step would be to make “peter” clickable, as opposed “peter, paul, simon, frank” all being the same URL link. (I used just an example webpage.)

function makeTable(data){ var tbl_body = ""; $.each(data, function() { var tbl_row = ""; $.each(this, function(k , v) { if(k==="name"){ tbl_row += ""+v+""; } else { tbl_row += ""+v+"";

In a previous search script with PDO/PHP i did it this way;

while ($results = $query->fetch()) {
echo “<td style="border-style:solid;border-width:1px;border-color:#98bf21;">”;
echo “

Cook: <a href='”.$results[‘url’].“’ target=‘_blank’>”.$results[‘url’].“”;
echo “<td style="border-style:solid;border-width:1px;border-color:#98bf21;">”;
echo “

Cook: <a href='”.$results[‘url’].“'> “.$results[‘url’].””;
echo “”;
}
echo “”;
} else {
echo ‘Nothing found’;
}

where each URL was indicated in the SQL database, however that was a keyword search and had no ajax/json.

Thanks. .

You want different names to go to different URLS?
Could you provide an example of the HTML output you desire (3 rows or so)

Ok. For example
Name/qualification/location/resume
Simon/engineer/berlin/yes
Peter/teacher/paris/yes
Micheal/doctor/madrid/yes

With the current code i can click on the name column. However that name column is the same url regardless of how far youve filtered. I am wonder how you can make the database value valid as the url.

Hence my previous example of $results [url]. I have seen a couple others but im still lost.

Don’t follow, I’m afraid. This is what we have, right?
When you click on a person’s name (e.g. Jim in position 1), what would you like to happen?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.