Jump to content

Search Users


Tom10

Recommended Posts

Hi, i've never created a search in php so i'm not exactly sure on the method you can use do create a search, basically i have created an admin panel and it has a list of users but if there are too many users i will need to create a search.

 

Please can someone tell me how i can do this?

 

Thanks in advance! :)

Link to comment
Share on other sites

Depends on what you need to search for, but let's say you want to search for the users last name.

 

Create a form with an input for the last name. When submitting the form, just do a search for the last name in the db using WHERE lastname = 'lastname_from_form' to get an exact match, or WHERE lastname LIKE 'lastname_from_form%' to get all that start with lastname_from_form (the % at the end is a wildcard).

 

Then display the list of matched users

Edited by CroNiX
Link to comment
Share on other sites

Depends on what you need to search for, but let's say you want to search for the users last name.

 

Create a form with an input for the last name. When submitting the form, just do a search for the last name in the db using WHERE lastname = 'lastname_from_form' to get an exact match, or WHERE lastname LIKE 'lastname_from_form%' to get all that start with lastname_from_form (the % at the end is a wildcard).

 

Then display the list of matched users

 

Thanks, CroNiX i will try this! :)

Link to comment
Share on other sites

Hi i'm trying to echo all usernames from sql to html my code is working but it's echoing to the page as an array

$select = "SELECT username FROM users";
$stmt = $handler->prepare($select);
$stmt->execute();
        
if($stmt->rowCount())
{
                                    
$res = $stmt->fetchAll();
                                    
print_r($res);
                                    
}
Link to comment
Share on other sites

Because $res IS an array of all usernames, which is what your query asked for by using fetchAll(). So you'd need to iterate over that array.

foreach($res as $user)
{
  echo $user['username'] . "<br>";
}
Edited by CroNiX
Link to comment
Share on other sites

 

Because $res IS an array of all usernames, which is what your query asked for by using fetchAll(). So you'd need to iterate over that array.

foreach($res as $user)
{
  echo $user['username'] . "<br>";
}

 

Ah i get you

Link to comment
Share on other sites

<a href="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=manage&new='.hash('ripemd128', rand()).'' ?>"> + New User </a>

Hi i'm trying to load a create page by adding &new= to the url but it won't work if i create case 'new': ?

Link to comment
Share on other sites

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.