How to create a search with multiple tables with php and mysqli

I created a database with the name ‘food-order’, on the search bar i can only search for files on one of the table, how can i search for all the items within the database ‘food-order’ not a specific table

Show us the code you’ve tried so far, and someone will have some advice for you.

I tried this but it’s working, i also used UNION but it’s still not working @droopsnoot



                //sql query to get category based on search keyword

                $sql = "SELECT * FROM tl_category AND apartment_rent  WHERE title LIKE '%$search%' OR description LIKE '%$search%' OR location LIKE '%$search%'";

                // execute the query

                $res = mysqli_query($conn, $sql);

                // count rows

                $count = mysqli_num_rows($res);

                // check whether category is available or not


                    // category is available


                        // get the details

                        $id = $row['id'];

                        $title = $row['title'];

                        $price = $row['price'];

                        $description = $row['description'];

                        $location = $row['location'];

                        $image_name = $row['image_name'];

The query you posted isn’t valid, you can’t just stick AND in there to join multiple tables. I suspect you are going down the correct avenue with UNION, but this really isn’t a PHP question, it’s a database question. Once you have the query working, then you can add the PHP to retrieve the results from it.

You didn’t post your attempt with UNION, but it’s generally something along the lines of

SELECT col1, col2 from tl_category where col1 like '%searchparam%'
SELECT col1, col2 from apartment_rent where col2 like '%searchterm%'

and so on.

I’ll move this into the database section where I am sure there will be more useful responses.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.