Benjamin Fahey
Benjamin Fahey

Reputation: 3

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result - Cant add multiple strings in SQL query

I understand that this issue has been posted before but I'm having a slightly different issue.

<?php

$query = "SELECT * FROM $sql_table WHERE make LIKE '%$make%' OR WHERE model LIKE '$model'";
$result = mysqli_query($conn, $query);

if (!'result') {
    echo "<p class=\"wrong\">Something is wrong with ", $query, "</p>";
} else {
    echo "<table border=\"1\">\n";
    echo "<tr>\n "
        . "<th scope=\"col\">Make</th>\n "
        . "<th scope=\"col\">Model</th>\n "
        . "<th scope=\"col\">Price</th>\n "
        . "<th scope=\"col\">YOM</th>\n "
        . "</tr>\n ";
    while ($row = mysqli_fetch_assoc($result)) {
        echo "<tr>\n ",
        "<td>", $row['make'], "</td>\n ",
        "<td>", $row['model'], "</td>\n ",
        "<td>", $row['price'], "</td>\n ",
        "<td>", $row['yom'], "</td>\n ";
        echo "</tr>\n ";
    }
}

My code works when I have a string such as make, where it returns all cars with that certain make. But when I try to add to the string so I can return more results based on the search, it is returning the above error. I'm not sure how I should be adding together these strings in the SQL Query.

Upvotes: 0

Views: 55

Answers (1)

seema
seema

Reputation: 354

change your query syntax as;

$query = "SELECT * FROM table_name WHERE make LIKE '%$make%' OR model LIKE '$model'"

you can not use two where clause in one query.

Upvotes: 1

Related Questions