PEDER1001 Posted February 15, 2007 Share Posted February 15, 2007 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 | | .. | | .. | -------- ------ Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 Can you show us your current code for the way it works at the moment? Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 <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> Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 The code there just shows the same thing in each div 1 1 2 2 3 3 4 4 Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 Okay, well just use an if statement like: <?php $number = rand(2,20); if ($number & 1) { //some div tag here for odd listings } else { //some div tag here for even listings } ?> Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 like this? : <?php $number = rand(2,20); if ($number & 1) { <div id="left">...... all the code bla bla </div> } else { <div id="right">...... all the code bla bla </div> } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 Yes, but obviously $number is not the source that you get your numbers from. Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 didn't quite understand Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 I know about that part, I'm just not exactly sure what i'm supposed to put instead of $number. Is it the total number or rows? Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 No, its the numbers you want to sort into odd or even lists. Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 I'm sorry to be asking so many questions, but in my case what would you put in my case? Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted February 15, 2007 Share Posted February 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 I figured it out Used a completely different method though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.