Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2012, 08:36 PM   PM User | #1
achira
New Coder

 
Join Date: Mar 2012
Location: Somewhere over the Rainbow
Posts: 96
Thanks: 7
Thanked 5 Times in 5 Posts
achira is an unknown quantity at this point
help needed: fetch_assoc multi-variable arrays

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:
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 Code:
<?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.

Last edited by achira; 04-25-2012 at 08:54 PM.. Reason: formatting
achira is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 PM.


Advertisement
Log in to turn off these ads.