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
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
}

Link to comment
Share on other sites

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	 } ?>

 

 

 

 

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.