abrahamgarcia27 Posted March 16, 2012 Share Posted March 16, 2012 I am have a query with a limit of 3 i want it to echo the first two in one li class and the 3 in another li class. This is what i have, but i know the logic is not right, but i cant figure it out </div> <?php echo "<ul class='services-list'>"; //echo "<li class='bubble'>"; $i = 1; foreach ($rows_class as $record_class ){ ?> <li class="bubble"><a href="viewclass.php?class_id=<?php echo base64_encode($record_class[class_id]) ?>" /><h6 class="title"><img src="./images/services/picture-services.png" class="picture" alt="logo" /><? echo $record_class[class_title]; ?></h6></a><p><?php $string = $record_class['description']; echo substr(strip_tags($string), 0, 200); ?></p> <?php if( $i % 2 === 0 && $record_class !== end($rows_class) ) { echo "</li>\n<li class='bubble last'>\n";?> <?php } elseif ( $record_class === end($rows_class) ) { echo "</li>\n "; } $i++; } ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/259034-after-2-records/ Share on other sites More sharing options...
q11we Posted March 16, 2012 Share Posted March 16, 2012 Well, here are the list of mistakes 1. you've closed a tag twice (like <a href="" /> </a>) 2. Try to use <?php instead of <? 3. If class of li tags have to change after first two li items code should be <?php echo "<ul class='services-list'>"; //echo "<li class='bubble'>"; $i = 1; foreach ($rows_class as $record_class ){ if($i!=1) {echo "</li>\n";} if( $record_class === end($rows_class) ) { echo "\n"; } else if($i <= 2) { echo "<li class='bubble'>"; } else { echo "</li>\n<li class='bubble last'>\n"; } $string = $record_class['description']; ?> <a href="viewclass.php?class_id=<?php echo base64_encode($record_class[class_id]) ?>"> <h6 class="title"><img src="./images/services/picture-services.png" class="picture" alt="logo" /> <?php echo $record_class[class_title]; ?> </h6></a> <p> <?php echo substr(strip_tags($string), 0, 200); ?> </p> <?php $i++; } ?> </ul> Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/259034-after-2-records/#findComment-1327979 Share on other sites More sharing options...
abrahamgarcia27 Posted March 16, 2012 Author Share Posted March 16, 2012 it didnt work, but it sure helped me out this is the code that i used <?php echo "<ul class='services-list'>"; $i = 1; foreach ($rows_class as $record_class ){ if($record_class === end($rows_class) ) { echo "<li class='bubble last'>\n"; } else if($i <= 2) { echo "<li class='bubble'>"; } $string = $record_class['description']; ?> <a href="viewclass.php?class_id=<?php echo base64_encode($record_class[class_id]) ?>"> <h6 class="title"><img src="./images/services/picture-services.png" class="picture" alt="logo" /> <?php echo $record_class[class_title]; ?> </h6></a> <p> <?php echo substr(strip_tags($string), 0, 200); ?> </p> </li> <?php $i++; } ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/259034-after-2-records/#findComment-1327992 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.