Jump to content

after 2 records


abrahamgarcia27

Recommended Posts

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>  

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.