Jump to content

creating a link


dan_t

Recommended Posts

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. :)

Link to comment
https://forums.phpfreaks.com/topic/198115-creating-a-link/#findComment-1039467
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/198115-creating-a-link/#findComment-1039755
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/198115-creating-a-link/#findComment-1039905
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.