deansaddigh Posted January 12, 2010 Share Posted January 12, 2010 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 More sharing options...
oni-kun Posted January 12, 2010 Share Posted January 12, 2010 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 https://forums.phpfreaks.com/topic/188170-i-want-to-find-out-how-many-rows-i-have/#findComment-993411 Share on other sites More sharing options...
deansaddigh Posted January 12, 2010 Author Share Posted January 12, 2010 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 https://forums.phpfreaks.com/topic/188170-i-want-to-find-out-how-many-rows-i-have/#findComment-993426 Share on other sites More sharing options...
Catfish Posted January 12, 2010 Share Posted January 12, 2010 if ($imagecount <= 6); remove the semi colon off the end. Link to comment https://forums.phpfreaks.com/topic/188170-i-want-to-find-out-how-many-rows-i-have/#findComment-993441 Share on other sites More sharing options...
deansaddigh Posted January 12, 2010 Author Share Posted January 12, 2010 Thanks man, i appreciate the help all is good now. Link to comment https://forums.phpfreaks.com/topic/188170-i-want-to-find-out-how-many-rows-i-have/#findComment-993448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.