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 | | .. | | .. | -------- ------ Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/ 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? Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185249 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> Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185250 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 Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185251 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 } ?> Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185252 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> } ?> Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185253 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. Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185254 Share on other sites More sharing options...
PEDER1001 Posted February 15, 2007 Author Share Posted February 15, 2007 didn't quite understand Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185256 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 Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185258 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? Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185263 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. Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185282 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? Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185284 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 Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185292 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. Link to comment https://forums.phpfreaks.com/topic/38602-mysql-php-and-css-showing-every-2nd-row-in-two-different-divs/#findComment-185327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.