I understand that pdo/mysqli is the required standard, for the time being I have no choice other than to use msql
Currently I have this setup to loop through results and display them accordingly
foreach($Items as $Item)
{
if($Item["Col1"] == "valueFoo"){
echo "<li>display relevant results</li>";
}
}
Is there way I can do this without looping through the whole array if Items
and instead combining the foreach loop with a condition. Alternatively filtering the array prior to the foreachloop
? What is the most efficient?
Currently I have 60 items and display them in lists like as below
$SQL = "SELECT * FROM tableName WHERE Col1 IS NOT NULL";
$Data = mysql_query($SQL, $db);
$Items = array();
while ($NewRow = mysql_fetch_assoc($Data)) {
// Append all rows to an array
$Items[] = $NewRow;
}
echo "<ul>";
foreach($Items as $Item)
{
if($Item["Col1"] == "valueFoo"){
echo "<li>display relevant results</li>";
}
}
echo "</ul>";
echo "<ul>";
foreach($Items as $Item)
{
if($Item["Col1"] == "valueDoo"){
echo "<li>display relevant results</li>";
}
}
echo "</ul>";
echo "<ul>";
foreach($Items as $Item)
{
if($Item["Col1"] == "valueHoo"){
echo "<li>display relevant results</li>";
}
}
echo "</ul>";
Is there a more efficient way? I'm still a newbie when it comes to php