Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,938 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,851 people online right now. Registration is fast and FREE... Join Now!




Assign hyperlinks to search results

 
Reply to this topicStart new topic

Assign hyperlinks to search results

agarwalsrushti
13 Mar, 2008 - 11:59 AM
Post #1

New D.I.C Head
*

Joined: 13 Mar, 2008
Posts: 1

Hi,
Ive made a search page. It displays the name of the users which is the result of search. Now i want that if we click on the name it should open another page in which the profile of the user will be displayed. The code that i ve done till now, only works for the last user in the list of users displayed and it also doesnt opens in another window. I think the name of the users should be passed as an array to the account page where profile is displayed. But i was not able to do it. Plz help. Ive given the relevant code below plz let me know what is the problem.

search.php


CODE

if($resultnum>0) { // Echos out matches if anything was found
while($info=mysql_fetch_array($data)){
//Print it out to page
$_SESSION['username'] = $info['UserName'];
echo "$info['UserName'] <a href=\"searchaccount.php?id=$info['UserName']\">profile</a><br/>";
}/ end of while
}//end of if
else{
echo "There are no results to be displayed for your search";
}  


In this file i get an error as:

Quote:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\skill_search\search.php on line 181

searchaccount.php


CODE

$uname = $_SESSION['username'];
$un=$_GET['id'];
$result1= " SELECT UserName, EmailAddress, FullName FROM usermaster WHERE UserName= '$un'";
$data1 = mysql_query($result1) or die(mysql_error());  


Plz help me with this

*edit* code.gif
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Assign Hyperlinks To Search Results
13 Mar, 2008 - 12:23 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,495



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Is it possible that there are quotes in the results being returned?

Also, is it the 2nd code block that is causing that error?
User is online!Profile CardPM
+Quote Post

JBrace1990
RE: Assign Hyperlinks To Search Results
14 Mar, 2008 - 04:09 PM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 477



Thanked: 22 times
Dream Kudos: 350
My Contributions
when you echo the results, you need to do something like this:

echo "<a href=location.php?user=".$user.">".$user."</a>"

that would show as a hyperlink to the next page with the url name being the data called and the location being location.php with a GET function of $user
User is offlineProfile CardPM
+Quote Post

_net
RE: Assign Hyperlinks To Search Results
17 Mar, 2008 - 03:15 PM
Post #4

D.I.C Head
**

Joined: 22 Sep, 2007
Posts: 146


My Contributions
You cannot output an array inside a string. Although you can display a normal variable you cannot do so with an array so here is what you can do.

echo "$info['UserName'] <a href=\"searchaccount.php?id=$info['UserName']\">profile</a><br/>";

put {} around the array variables like this:

echo "{$info['UserName']} <a href=\"searchaccount.php?id={$info['UserName']}\">profile</a><br/>";
User is offlineProfile CardPM
+Quote Post

samn84
RE: Assign Hyperlinks To Search Results
18 Mar, 2008 - 10:54 PM
Post #5

New D.I.C Head
*

Joined: 21 Feb, 2008
Posts: 41

what u can do is if u want only the user to appear as hyper link and if u click them u can c there profile do this:

<? echo "<a href='searchaccount.php?id=$info[USERNAME]'>".$info[USERNAME]."</a>";?>

now this username is a hyperlink and will also be send to the searchaccounts page where u can put the query of finding the profile against this username and display it!!
n dont put quotes around USERNAME oda wise wont work!!!!!!!!imp
hope u understood n it wrks 4 u.

This post has been edited by samn84: 18 Mar, 2008 - 11:03 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:49PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month