Jump to content
Sign in to follow this  
cainam29

How to use WHERE and LIKE with a variable

Recommended Posts

I have a login session where it checks the user name and displays it to the form (it displays FirstName LastName). That username is also being used as a variable to pull up data in db. Now I also have another page where user's can update the db, I dont have a problem if the user will update it with a complete FirstName LastName entry because it will just be the same as the one's being used by the login session, but sometimes they just update it with FirstName.

 

The problem starts when I have values in TEST db under Tester column and in USERS db under User column that is of different values. It would have two diff values when a user did not enter the full FirstName LastName.

 

For example,

 

FirstName1 LastName1 is the value in USERS db User column - this is fixed and is being used in a login session

 

User updated Tester column in TEST db with just FirstName1 - this is different from the User column above

 

Here is what I am trying to do,

 

Getting list of tickets from the TEST db where datefrom and dateto and using a variable for the values that is in User column under USER DB

 

If User column under USERS db = Tester column under Test db which is FirstName1 LastName1 - it will be good as I will be able to get tickets under FirstName1 LastName1.

 

But I will not be able to get ticket which is still assigned to that same person because the value in Tester column under Test db is just FirstName1.

 

If User column under USERS db (FirstName1 LastName1) is not equal to Tester column under Test db which is just FirstName1 - I will not get tickets assigned to FirstName1 as my variable is equal to FirstName1 LastName1.

 

I hope that I explained it clearly, here is my code,

 

Here is the variable that I am posting,   


$uid = false;
    if(isset($_POST['uid'])){
        $uid = $_POST['uid'];
     } 

And here is the query,    


$sql = 'SELECT `id`, `date_implemented`, `tester`, `comments` 
            FROM `tracker` WHERE `tester` = :uid AND `scheduled_start_date` BETWEEN :d1 AND :d2';
            $stmt = $conn->prepare($sql);
    $stmt->bindParam(':uid', $uid, PDO::PARAM_STR);
            $stmt->bindParam(':d1', $date['from'], PDO::PARAM_STR);
            $stmt->bindParam(':d2', $date['to'], PDO::PARAM_STR);
            $stmt->execute();
            $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

I would need help in passing that variable (uid) such that I can use `WHERE tester LIKE uid`. In that case whether the tester column just contains FIRSTNAME1 or a complete FIRSTNAME1 LASTNAME1, I would be able to get all tickets assigned to FIRSTNAME1.

 

Share this post


Link to post
Share on other sites

1. Don't reference people by names in the database. Use IDs instead.

2. Don't let users enter just a name for a person who is also a user in your system. Make them choose the user in such a way that you always get the user ID. You can use a

 

Then your problems will go away.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

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.