barrowvian Posted March 27, 2010 Share Posted March 27, 2010 Hey, Im pretty new to php and have just been toying with a few ideas to get used to it. So far I have created a basic database that contains 3 fields: userid, firstname and lastname. On one page I have echoed the firstname and lastname like so; echo $row['surname'] . ", " . $row['firstname'] ."<br />"; I want each row that is displayed to be a link to another page where other information will be presented based upon which user has been clicked. (e.g) click on Smith, John and it will take you to his page with his information. How do I go about creating this so that the primary key can be used to identify which row has been clicked? Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/ Share on other sites More sharing options...
jskywalker Posted March 27, 2010 Share Posted March 27, 2010 something like: echo "<a href=moreinfo.php?$row['id']>".$row['surname'] . ", " . $row['firstname'] ."</a><br />"; where moreinfo.php gives more info about 'id'.... Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032703 Share on other sites More sharing options...
ignace Posted March 27, 2010 Share Posted March 27, 2010 echo '<p><a href="profile.php?id=',$row['id'],'">',$row['surname'],' ',$row['firstname'],'</a></p>'; Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032707 Share on other sites More sharing options...
barrowvian Posted March 27, 2010 Author Share Posted March 27, 2010 Thanks guys; Tweeked it slightly to; echo "<a href=profile.php?userid=$row[userid]>" and it works fine. It initially didnt like the '' that surrounded the userid so thats where my problem was occurring. Thanks again! Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032708 Share on other sites More sharing options...
ignace Posted March 27, 2010 Share Posted March 27, 2010 Try: echo "<a href=\"profile.php?userid={$row['userid']}\">" Also remember for valid HTML use " around values for attributes (href) Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032710 Share on other sites More sharing options...
barrowvian Posted March 27, 2010 Author Share Posted March 27, 2010 thanks ignace, works fine whilst maintaining valid HTML! Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032713 Share on other sites More sharing options...
jskywalker Posted March 27, 2010 Share Posted March 27, 2010 why could you not figure the answer out yourself, if you know about 'valid HTML'...? (/me just curious) Link to comment https://forums.phpfreaks.com/topic/196698-creating-a-link-using-the-primary-key/#findComment-1032727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.