dan_t Posted April 9, 2010 Share Posted April 9, 2010 My question is, when you extract information from a database, lets say userName for instance, better yet when you have a search for something like zip codes, how do you put a link to each persons page from their zip? Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 9, 2010 Share Posted April 9, 2010 Depends how your searching. If your using a while, to loop out the results, you can use something similar to below. <?php $query = mysql_query("select * from zip codes"); //Change to match what you need while($row = mysql_fetch_array($query) { echo '<a href="mylink.php?id='.$row['id'].'">$row['zipcode']</a>'; } ?> This will bring up the zip codes, in a link to the page mylink.php?id=USERID Providing mylink.php is setup correctly, so that it displays information based on the users id, then it'll work. Quote Link to comment Share on other sites More sharing options...
dan_t Posted April 9, 2010 Author Share Posted April 9, 2010 Ok, I don't have any pages made, I'm just trying to understand this whole thing. Perhaps I need to create some fake pages, but how does the zipcode attach an individuals personal page to it? Meaning when you do a search and it pulls up and displays these zipcodes how is their personal pages linked to each page? Through variables some how? Or is it much more complicated. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 11, 2010 Share Posted April 11, 2010 Well, you'd do similar to what I stated. For example, on mylink.php.. You could do this.. mylink.php <?php if($_GET['id']) { $id = $_GET['id']; $query = mysql_query("select * from users where id = $id") or die(mysql_error()); if(mysql_num_rows($query) > 0) { $r = mysql_fetch_assoc($query); echo $r['username'] . '<br />'; echo $r['email']; } } ?> So when the code I supplied before, is in place. it'll create a link on the persons zipcode, to their personal page on your site. The link put in the code, has a unique ID for each user being displayed. This will allow mylink.php to process it depending on that ID. Clicking on it, takes you to 'mylink.php' The code above, will display details related to that particular user their viewing. Is this what you're after? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.