...

View Full Version : help needed: fetch_assoc multi-variable arrays



achira
04-25-2012, 09:36 PM
So I created a table that pulled a list of countries from my database, and put check boxes next to them. It worked great!
Here's the code:

<table width="95%">
<tr>
<td>
<table border="0" cellpadding="1" cellspacing="2">
<tr>
<td></td>
</tr>

<?php
$num_in_col = ceil($totalRows_countries/4);
for($i=0;$i<$totalRows_countries;$i++){
$row_countries = mysql_fetch_assoc($countries);
?>

<tr>
<td><input type="checkbox" name="CountryID[]" value="<?php echo $row_countries['CountryID'];?>"/></td>
<td><?php echo $row_countries['CountryName']; ?></td>
</tr>

<?php
$num_done++;
if($num_done >= $num_in_col){
print '</table></td><td valign="top"><table>';
$num_done = 0;
}
}
?>

</table></td>
</tr>
</table>


So great, that I thought that I could do the same thing but for a ul/li set of options, since within each list item there is a sublist of choices.

Not.so.great.

I think part of the problem is that I'm trying to get it to count the options automatically and reprint the row; but I can't see where I'm going wrong.



<?php
$num_in_li = ceil($totalRows_Sectors);
for($i=0;$i<$totalRows_Sectors;$i++){
$row_Sectors = mysql_fetch_assoc($Sectors); ?>

<ul id="MenuBar1" class="MenuBarVertical">
<li><a class="MenuBarItemSubmenu">
<input name="SectorID[]" type="hidden" value="<?php echo $row_Sectors['SectorID']; ?>"/>
<?php echo $row_Sectors['SectorName']; ?></a>

<?php
$num_done++;
if($num_done >= $num_in_li){
print '<li><ul>';
$num_done = 0;
}
} ?>

<ul>

<?php
$num_in_ulli = ceil($totalRows_Seervices);
for($i=0;$i<$totalRows_Services;$i++){
$row_Services = mysql_fetch_assoc($Services); ?>

<li><input name="ServiceID[]" type="checkbox" value="<?php echo $row_Services['ServiceName']; ?>" />
<?php echo $row_Services['ServiceName']; ?></li>

<?php
$num_done++;
if($num_done >= $num_in_li){
print '<li>';
$num_done = 0;
}
} ?>
</ul>
</li>
</ul>


I think that I will try putting the li portions in a table format and see what happens? I don't want to give up on this idea.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum