SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery/Ajax - Get the value of a hyperlink.

    Hi All,

    I have a search user option on my webpage (search.php) where people can search for a product. The processing part is done on a separate php page (process.php)


    The code for process.php page is:
    Code:
    	if($_GET['action']=='search_user'){
    	$name = $_GET['txtnamesearch'];
    	$result = mysql_query("select username,full_name from login where username LIKE'$name%' or full_name LIKE'$name%'");
    	$num_rows = count($result);
    		if($num_rows<1)
    		echo "<B>Oouchhh!! Try refining your search.</b>";
    		else{
    			for($x=0;$x<$num_rows;$x++){
    			echo '- '.$result[$x]['full_name'] .' => <a id='.$result[$x]['username'].'>'. $result[$x]['username']. '</a><BR>';
    			}
    		}
    	}//End Search User


    The result on the search.php page will output as the following :

    Search Results:
    - Sam Thomas => sam
    - John Clinger => jon
    - Patrick Norton => pat


    Now, I want such that clicking on each username would display their profile details.

    What ajax call do I have to make and how?


    Thanx

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd personally "json_encode" your result array and pass that back. Then let Javascript convert it back to an object using "eval".

    Then you can do what you want with the data, including create new requests with the user's username, userid etc.


  3. #3
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Please note that the search result comes under a <div > tag on the search.php page.

    How do I fetch the username using "json_encode"?

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    json_encode is php function that converts an object into a json string. Javascript can then use eval to turn that string back into an object.

    Jquery, if I recall correctly will also automatically convert the json string into an object (using eval) and pass it back.

    You can then treat it like you would in PHP, loop through the results and get the user's id.

    You can then also create a new ajax call with the users id or what ever information you have.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •