FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
Trouble with queries
Message  

Reply with quote
Post Trouble with queries 
I seem to be having trouble adding the result of an if condition to a SELECT query using '.='.  It will work if I use '$query =' and write the whole query again, but I would like to just add a line to the existing SELECT query.  It keeps coming back with

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\testresultsa.php on line 50.

I have googled this error and understand what it means, but it doesn't seem to make sense when the only difference is using '.=' or '='.

The code is pasted below:

//Open the connection to the database
    $link = mysqli_connect('localhost', 'student', 'mmst12009', 'assignment3');
        
//Define an SQL query to retrieve the library records
    $query = "SELECT exhibits.exhibit_id, exhibits.exhibit_date,
    exhibits.exhibit_type, exhibits.exhibit_description, libraries.library_name
    FROM exhibits, libraries WHERE exhibits.library_id = libraries.library_id";
        
//Restrict the query  with an AND clause if 'ANY' has been chosen for a library name
    if ($form_library_id != "any") {
        $query .= "AND libraries.library_id = $form_library_id";
    }

View user's profile Send private message

Reply with quote
Post  
Smile. You should insert spaces between your previous string and new string. Because otherwise your query will look like this:

SELECT exhibits.exhibit_id, exhibits.exhibit_date, exhibits.exhibit_type, exhibits.exhibit_description, libraries.library_name FROM exhibits, libraries WHERE exhibits.library_id = libraries.library_idAND libraries.library_id ...

here is your new code:

Code:

//Restrict the query  with an AND clause if 'ANY' has been chosen for a library name
    if ($form_library_id != "any") {
        $query .= " AND libraries.library_id = $form_library_id";
    }


the next time you have errors like this just try to print your query

echo $query;

and you will see the errors within the query.

Regards,
Pratamishus.


_________________
www.eb-downloads.com
FREE E-BOOKS DOWNLOADS.
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com