latinofever Posted June 15, 2007 Share Posted June 15, 2007 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 />"; Link to comment https://forums.phpfreaks.com/topic/55772-solved-problem-with-creating-dynamic-hyperlinks-with-user-ids-in-php-query/ Share on other sites More sharing options...
GingerRobot Posted June 15, 2007 Share Posted June 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/55772-solved-problem-with-creating-dynamic-hyperlinks-with-user-ids-in-php-query/#findComment-275544 Share on other sites More sharing options...
latinofever Posted June 15, 2007 Author Share Posted June 15, 2007 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 Link to comment https://forums.phpfreaks.com/topic/55772-solved-problem-with-creating-dynamic-hyperlinks-with-user-ids-in-php-query/#findComment-275572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.