Jump to content

mysql, php and css - showing every 2nd row in two different divs


PEDER1001

Recommended Posts

Basically, I call up the mysql database and at the moment everything is displayed in a single list. I would like to take this list and put it into two columns in seperate div's like this:

 

<div id="left">
	<ul class="List">
		    <li>1</li>
		    <li>3</li>
		    <li>5</li>
	</ul>	
</div>
<div id="right">
	<ul class="List">
		    <li>2</li>
		    <li>4</li>
		    <li>6</li>
 	</ul>	
</div>	

 

Therefore, I would like the results of the mysql query to be altered in php somehow to only show odd results in the left div, and even results in the right div.

 

I would preferrably not like to meddle too much with the sql coding as it is located in the header.php. This part (above) is in a different php file loaded later in the template.

 

pic:

 

--------       -------

|    1    |     |    2   |

|    3    |     |    4   |

|    5    |     |    6   |

|    7    |     |    8   |

|    ..    |     |   ..   |

--------       ------

<div id="left">
	  <ul class="List">
	  <?php
	     //print('level:'.$level);

	    for ($j=0;$j<count($channel_list);$j++)
	    {
                      if ($level == 1)
                      {
                        $onclick = 'onclick="open_video('.$channel_list[$j]['ch_id'].'); return false;"';
                        $channel_count = false;
                        $p_dir = $site_uri. $parent_channel_info['name'].'/'. $channel_info['name'];
                      } else {
                        //get channel count
                       $channel_count = getChannelListCount($channel_list[$j]['ch_id']);
                       $p_dir = $site_uri . $parent_channel_info['name'];
                      }
                      print('<li><a href="'.$p_dir.'/'.$channel_list[$j]['name'].'" class="top" '.$onclick.'>'.$channel_list[$j]['title'].'');
                       if ($channel_count !== false)
                       {
                         print('  <small>(Antall videoer: '.$channel_count.')</small>');
                       }
                       //-----------------------
                       if (strtotime("-7 days") < strtotime($channel_list[$j]['date_added']))
                       {
                        print('  <small>Ny!</small></a>');
                       }
                       //-----------------------
                      print('</li>');


                     $onclick='';
                     $p_dir = '';
                    }
                    
                    if (!is_array($channel_list[0]))
                    {
                      print('Ingen videoer i denne kategorien.');
                    }
                  ?>
                   </ul>
</div>
<div id="right">
	  <ul class="List">
	  <?php
	     //print('level:'.$level);

	    for ($j=0;$j<count($channel_list);$j++)
	    {
                      if ($level == 1)
                      {
                        $onclick = 'onclick="open_video('.$channel_list[$j]['ch_id'].'); return false;"';
                        $channel_count = false;
                        $p_dir = $site_uri. $parent_channel_info['name'].'/'. $channel_info['name'];
                      } else {
                        //get channel count
                       $channel_count = getChannelListCount($channel_list[$j]['ch_id']);
                       $p_dir = $site_uri . $parent_channel_info['name'];
                      }
                      print('<li><a href="'.$p_dir.'/'.$channel_list[$j]['name'].'" class="top" '.$onclick.'>'.$channel_list[$j]['title'].'');
                       if ($channel_count !== false)
                       {
                         print('  <small>(Antall videoer: '.$channel_count.')</small>');
                       }
                       //-----------------------
                       if (strtotime("-7 days") < strtotime($channel_list[$j]['date_added']))
                       {
                        print('  <small>Ny!</small></a>');
                       }
                       //-----------------------
                      print('</li>');


                     $onclick='';
                     $p_dir = '';
                    }
                    
                    if (!is_array($channel_list[0]))
                    {
                      print('Ingen videoer i denne kategorien.');
                    }
                  ?>
                   </ul>
</div>

if	($number & 1)
{
<div id="left">
	  <ul class="List">
	  <?php
	     //print('level:'.$level);

	    for ($j=0;$j<count($channel_list);$j++)
	    {
                      if ($level == 1)
                      {
                        $onclick = 'onclick="open_video('.$channel_list[$j]['ch_id'].'); return false;"';
                        $channel_count = false;
                        $p_dir = $site_uri. $parent_channel_info['name'].'/'. $channel_info['name'];
                      } else {
                        //get channel count
                       $channel_count = getChannelListCount($channel_list[$j]['ch_id']);
                       $p_dir = $site_uri . $parent_channel_info['name'];
                      }
                      print('<li><a href="'.$p_dir.'/'.$channel_list[$j]['name'].'" class="top" '.$onclick.'>'.$channel_list[$j]['title'].'');
                       if ($channel_count !== false)
                       {
                         print('  <small>(Antall videoer: '.$channel_count.')</small>');
                       }
                       //-----------------------
                       if (strtotime("-7 days") < strtotime($channel_list[$j]['date_added']))
                       {
                        print('  <small>Ny!</small></a>');
                       }
                       //-----------------------
                      print('</li>');


                     $onclick='';
                     $p_dir = '';
                    }
                    
                    if (!is_array($channel_list[0]))
                    {
                      print('Ingen videoer i denne kategorien.');
                    }
                  ?>
                   </ul>
</div>
}
else
{
<div id="right">
	  <ul class="List">
	  <?php
	     //print('level:'.$level);

	    for ($j=0;$j<count($channel_list);$j++)
	    {
                      if ($level == 1)
                      {
                        $onclick = 'onclick="open_video('.$channel_list[$j]['ch_id'].'); return false;"';
                        $channel_count = false;
                        $p_dir = $site_uri. $parent_channel_info['name'].'/'. $channel_info['name'];
                      } else {
                        //get channel count
                       $channel_count = getChannelListCount($channel_list[$j]['ch_id']);
                       $p_dir = $site_uri . $parent_channel_info['name'];
                      }
                      print('<li><a href="'.$p_dir.'/'.$channel_list[$j]['name'].'" class="top" '.$onclick.'>'.$channel_list[$j]['title'].'');
                       if ($channel_count !== false)
                       {
                         print('  <small>(Antall videoer: '.$channel_count.')</small>');
                       }
                       //-----------------------
                       if (strtotime("-7 days") < strtotime($channel_list[$j]['date_added']))
                       {
                        print('  <small>Ny!</small></a>');
                       }
                       //-----------------------
                      print('</li>');


                     $onclick='';
                     $p_dir = '';
                    }
                    
                    if (!is_array($channel_list[0]))
                    {
                      print('Ingen videoer i denne kategorien.');
                    }
                  ?>
                   </ul>
</div>
}

 

Im presuming $number is not the thing you want to check

I think from your code it is $channel_list, is that your incrementing number that orders your list, sorry can't be arsed to make sense of it all.  But that is what papaface is trying to tell you.  The &1 option seperates the odd items in the list from the even ones.  Good Luck

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.