In phpMyAdmin the query
SELECT * FROM table WHERE value1 LIKE '%O%' OR value2 LIKE '%1%'
nicely returns all rows containing O or 1.
But the same query implemented in a PHP script only returns the first row matching O or 1. Instead off all rows matching O or 1.
This is my current PHP script:
mysqli_select_db ($con, $database) or die (mysqli_error());
$sqli = mysqli_query ($con,"SELECT * FROM table WHERE VALUE1 LIKE '%O%' OR VALUE2 LIKE '%1%'") or die (mysqli_error());
$echo = mysqli_fetch_assoc($sqli);
if (empty ($echo))
{
echo "No matching results found.";
}
else
{
echo "<table width='50%' border='1'>";
echo "<tr><th>VALUE1</th><th>VALUE2</th></tr>";
echo "<tr><td>{$echo["VALUE1"]}</td>";
echo "<td>{$echo["VALUE2"]}</td></tr>";
}
The output is only the first matching row. Instead of all matching rows. Also when I use print_r instead of table rows.
You have to iterate through all the rows with a loop like this
if( !mysqli_num_rows($sqli) )
{
echo "No matching results found.";
} else {
$table = "<table width='50%' border='1'>
";
$table .= "<tr><th>VALUE1</th><th>VALUE2</th></tr>
";
while( $echo = mysqli_fetch_assoc($sqli) )
{
$table .= "<tr><td>{$echo['VALUE1']}</td><td>{$echo['VALUE2']}</td></tr>
";
}
$table .= "</table>";
}
Note I added a couple of lines of code to count the rows and display a message if there are no matches found (as I intended is your goal from your question).
Edit: Better would be to use the built in num_rows instead of reinventing the wheel
Edit 2: I have a feeling he didn't want the table to duplicate for each row. Change the code a bit