I'm new to MySQL and PHP and am having trouble with this code. Please do tell me where I am going wrong:
Here's the code:
<?php
include('connection.php');
$num1 = '1';
$num2 = '2';
// Get all the data from the table
$sql = mysql_query("SELECT * FROM table1 WHERE num1 = '$num1' AND num2 = '$num2'");
$row = mysql_fetch_assoc($sql) or die("No rows returned by query");
while ($row = mysql_fetch_assoc($sql)) {
echo $row["num1"];
echo '</br>';
echo $row["num2"];
echo '</br>';
}
?>
If I change
$sql = mysql_query("SELECT * FROM table1 WHERE num1 = '$num1' AND num2 = '$num2'");
to
$sql = mysql_query("SELECT * FROM table1 WHERE num1 > '$num1' AND num2 > '$num2'");
it works. It doesn't work with the equal sign although there are records that should be printed out.
Thank you for your time.
table1table.SELECT * FROM orders WHERE order_id = '81837' AND customer_id = '13';in a database where both those fields areINTs and it works fine. Can you provide you SCHEMA and any error messages/returned values?