Jump to content

[SOLVED] using variables instead of static data in mysql query!


will_1990

Recommended Posts

Despite being able to get the query to work sucessfully in phpmyadmin with static data, when i swap this out for my variable input this does not work.

 

this works in phpmyadmin and returns the expected data on the webpage.

 

$sql = 'SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName'
        . ' FROM BookTitle AS bt'
        . ' CROSS JOIN BookCopy USING (BtId)'
        . ' CROSS JOIN Loan USING (BcId)'
        . ' CROSS JOIN Publisher USING (PubId)'
        . ' CROSS JOIN Authorship USING (BtId)'
        . ' CROSS JOIN Author USING (AuthorId)'
        . ' WHERE'
        . ' Loan.DateBack IS NOT NULL'
        . ' AND'
        . ' bt.BtName LIKE \'%Harry%\' AND Author.AuthorName LIKE \'%row%\' LIMIT 0, 30 ';

 

However when it is edited to:

       . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 ';

[/code]

 

the expected output is completely blank. Why is this is there a way to solve this or a work around?

 

Many thanks

Variables are not parsed inside of ''.

 

You need to use "" if you want variables parsed inside of quotes.

 

Is this how its meant to be?

 

        . ' bt.BtName LIKE \'%"$bn"%\' AND Author.AuthorName LIKE \'%"$an"%\' LIMIT 0, 30 ';

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.