Jump to content

[SOLVED] Search Result with Link


PHPro

Recommended Posts

Could anyone please help about making a search result with links. To be specific, I have a list of names in my database. I want to create a search that will list names with links. Its been 5 hours and cant still figure out how it goes.

 

Thank you

Link to comment
Share on other sites

Links to what? Profile pages?

 

As an example.

 

<?php

$sql = "SELECT id, uname FROM users";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      echo "<a href='prefile.php?id={$row['id']}'>{$row['uname']}</a>";
    }
  }
}

 

profile.php

<?php

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT email FROM users WHERE id = $id LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['email'];
    }
  }
}

Link to comment
Share on other sites

Link to profile

 

Thank you so much Thorpe.Thats exactly what I'm looking for. You refer to this as a pagination right?

thanks again sir!

 

Nope, nothing to do with pagination. Pagination is when you have so many results from one query that you split those results over several pages. Much how this board is split into pages, otherwise this page would need to display something like 150000 records at once.

Link to comment
Share on other sites

  • 11 months later...
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.