Jump to content

i want to find out how many rows i have


deansaddigh

Recommended Posts

i have this code.

 

  $k =1;
                foreach ($imagesResults as $imagesResults2){
                ?>
                    <div class='thumbPhoto' style='margin-left:-3px;margin-right:8px;'>
                        <a href="javascript:image_click(<?=$k?>, '<?=$imagesResults2{'large'}?>', '<?=$imagesResults2{'main'}?>')" border="0"><img src='admin/images/properties/<?=$imagesResults2{'thumb'}?>' width='53px' height='45px' id="pimage<?=$k?>" name="pimage<?=$k?>" border='0'></a>
                    </div>
                <?			
                    $k++;
                }
                ?>

 

and i want to find out how many rows there are, because i then need to do an if statement to see if there are more than 5 rows do this etc

Link to comment
https://forums.phpfreaks.com/topic/188170-i-want-to-find-out-how-many-rows-i-have/
Share on other sites

You should use the count function to check the amount of elements within the array (in this case the rows you're wanting to display). Here's an example:

if (count($imagesResults2) > 5) {
     echo "More than 5 rows";
     //Do Something
} else {
    //Less than 5 rows
}

Thank you so much.

 

i have done it this way. they are already looping through and displaying images, with this code. so i added an extra $imagecount

 

<?
			$imagecount =1;
                $k =1;
                foreach ($imagesResults as $imagesResults2){
                ?>
                    <div class='thumbPhoto' style='margin-left:-3px;margin-right:8px;'>
                        <a href="javascript:image_click(<?=$k?>, '<?=$imagesResults2{'large'}?>', '<?=$imagesResults2{'main'}?>')" border="0"><img src='admin/images/properties/<?=$imagesResults2{'thumb'}?>' width='53px' height='45px' id="pimage<?=$k?>" name="pimage<?=$k?>" border='0'></a>
                    </div>
                <?			
                    $k++;
				$imagecount++;
                }
                ?>

 

Then here i want to display a different image based on how many images it brings back but i am getting an error.

 

<?php
			if ($imagecount <= 6);
        			{ ?>
                		<div class='mainImageBox' style='float:right; background-image:url(/images/mainImageBox.jpg);'>	
              <?php }
		  
		  else {
		  		
				?><div class='mainImageBox' style='float:right; background-image:url(/images/bigmainImageBox.jpg);'>	
		  			
		  <?php	 } ?>

 

its an

Parse error: syntax error, unexpected T_ELSE in D:\Inetpub\wwwroot\dhcottages.co.uk\testsite\details.php on line 233

error and it seems to be this line

 

else {
		  		
				?><div class='mainImageBox' style='float:right; background-image:url(/images/bigmainImageBox.jpg);'>	
		  			
		  <?php	 } ?>

 

 

 

 

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.