Jump to content

[SOLVED] Problem with creating dynamic hyperlinks with user id's in php query


Recommended Posts

Hi there

 

Im dabbling with PHP and trying to write a new search.php file to scan for specic users in my dating website and then display the users along with individual links to their profile.

 

$profile = $row["id"];      -- this field takes profile ID from mysql database

The profile field pulls in an ID field from a mysql database for each record. I need to integrate this fields value into the hyperlink when the results are returned so it has a list of all users each with an individual hyperlink to their profile. Then users can click and access the profile of a specific user.

 

 

This is the line of code that ive written to output the hyperlink

 

echo 'Click <a href="http://www.mywebsite.co.uk/?L=users.profile&id=;$profile">for profile</a> to view this page';

 

As an example I want it to have this as a users hyperlink:       

 

UserX

http://www.mywebsite.co.uk/?L=users.profile&id=1456           

 

UserY

http://www.mywebsite.co.uk/?L=users.profile&id=1459 

 

UserZ 

http://www.mywebsite.co.uk/?L=users.profile&id=1885 

 

 

Results of my query are as follows. Listing username, and hyperlink for profile

1; adventuregent01,Adventuregent Click for profile to view this page

2; after8,paul Click for profile to view this page

 

HOWEVER THE PROFILE LINK HAS WRONG A HTML LINK 

IT LINKS EVERY SINGLE USER TO      http://www.mywebsite.co.uk/?L=users.profile&id=;$profile        -

 

---- instead of $profile I want the value from the database. Im sure its an easy mistake Ive made in the code.

Appreciate your help.

 

 

Snippet of code below

------------------------------

 

 

 

// begin to show results set

echo "Results";

$count = 1 + $s ;

 

// now you can display the results returned

  while ($row= mysql_fetch_array($result)) {

  $title = $row["username"];

$first_name = $row["firstname"];

$profile = $row["id"];

 

 

echo "<br />";

 

echo "$count; $title,$first_name";

echo 'Click <a href="http://www.mywebsite.co.uk/?L=users.profile&id=;$profile">for profile</a> to view this page';

 

 

  $count++ ;

  }

 

$currPage = (($s/$limit) + 1);

 

//break before paging

  echo "<br />";

I think all you need to do is switch the single quotes to double quotes on this line:

echo 'Click for profile to view this page';

 

php parses anything thats being echoed that is in double quotes, but not in single quotes.

After dabbling I have fixed it.. You are right I needed it in double quotes .. Thanks a lot

 

 

echo "$count; $title,$first_name";

echo "Click <a href=\"http://www.mywebsite.co.uk?L=users.profile&id=$profile\">for profile</a> to view this page";

 

I also needed to add \ before the " (double quotes) and before the end of the double quotes as I had double quotes within double quotes :-)

 

 

Thanks again

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.