Hya, I have a loop that returns records from a database relation and prints them in a web page. I would like to extend it by having the code dynamically assign every other record to a sepeare div, so I end up with two vertical columns of records.
I'm getting a parse error at the moment, and tbh I'm not even sure if this is possible, any ideas would be appreciated. Here's my code:
<?php
$storeQuery = "SELECT store.StoreID,
store.StoreAddress1,
FROM store;";
$result = mysql_query($storeQuery);
$i = 0;
while ($row = mysql_fetch_array($result))
{
if ($odd = $i%2) // calculates (using modulus) if a returned row interation is odd or even
{
echo "<DIV ='leftContent'>";
$storeHeader = $row['StoreID'];
$storeAddress1 = $row['StoreAddress1'];
echo "<h3 class='underline'>Store ".$storeHeader."</h3>";
echo "<p>".$storeAddress1."</p>";
echo "</DIV>";
}
else
{
echo "<DIV ='rightContent'>";
$storeHeader = $row['StoreID'];
$storeAddress1 = $row['StoreAddress1'];
echo "<h3 class='underline'>Store ".$storeHeader."</h3>";
echo "<p>".$storeAddress1."</p>";
echo "</DIV>";
}
}
// Free up the memory used for $result
mysql_free_result($result);
// Close the database connection
mysql_close();
?>
I'm getting a parse error at the moment, and tbh I'm not even sure if this is possible, any ideas would be appreciated. Here's my code:
<?php
$storeQuery = "SELECT store.StoreID,
store.StoreAddress1,
FROM store;";
$result = mysql_query($storeQuery);
$i = 0;
while ($row = mysql_fetch_array($result))
{
if ($odd = $i%2) // calculates (using modulus) if a returned row interation is odd or even
{
echo "<DIV ='leftContent'>";
$storeHeader = $row['StoreID'];
$storeAddress1 = $row['StoreAddress1'];
echo "<h3 class='underline'>Store ".$storeHeader."</h3>";
echo "<p>".$storeAddress1."</p>";
echo "</DIV>";
}
else
{
echo "<DIV ='rightContent'>";
$storeHeader = $row['StoreID'];
$storeAddress1 = $row['StoreAddress1'];
echo "<h3 class='underline'>Store ".$storeHeader."</h3>";
echo "<p>".$storeAddress1."</p>";
echo "</DIV>";
}
}
// Free up the memory used for $result
mysql_free_result($result);
// Close the database connection
mysql_close();
?>