I am using the below code to query an pull Category and Stock of the first 30 Product ID that are store into the $IDs array in PHP.
//Category
for ($n = 0; $n < 30; $n++) {
$ID = $IDs[$n];
$result = mysql_query("SELECT Category FROM Products where Code= '$ID'", $link);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
$productCategory[$n] = $row["Category"];
}
}
//Stock
for ($n = 0; $n < 30; $n++) {
$ID = $IDs[$n];
$result = mysql_query("SELECT Stock FROM Products where Code= '$ID'", $link);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
$productStock[$n] = $row["Stock"];
}
}
Is there a way to query and pull both Category and Stock with the same SELECT so i can minimise the queries to mySQL DB to only 30 not 60?
mysql_*functions. These api is depricated. Usemysqli_*functions or pdo and prepared statement.