adam291086 Posted September 25, 2008 Share Posted September 25, 2008 I am trying to print out all the information from an array using a for loop like so for ($i=0; $i<=sizeof($pages); $i++) { ?> <tr> <td> <?php echo $pages['title']?> </td> <td> <?php echo $pages['description']?> </td> </tr> <?php } The array contains data from a query of the database. The number of rowd full of information can vary. At the moment it is supposed to print out one lot of information but instead it is printing out the same info 11 time. I know its due to the sizeof function but how else can i loop through? Link to comment https://forums.phpfreaks.com/topic/125791-solved-printing-all-information-out-from-an-array/ Share on other sites More sharing options...
trq Posted September 25, 2008 Share Posted September 25, 2008 Where is $pages defined? And what is the output of.... echo '<pre>'; print_r($pages); echo '</pre>'; ? Link to comment https://forums.phpfreaks.com/topic/125791-solved-printing-all-information-out-from-an-array/#findComment-650451 Share on other sites More sharing options...
adam291086 Posted September 25, 2008 Author Share Posted September 25, 2008 like $pages = $add->get_page($domain,$account); which looks like Array ( [0] => 7 [id] => 7 [1] => www.adamplowman.co.uk [domain] => www.adamplowman.co.uk [2] => 123 [account_number] => 123 [3] => dfsdf [title] => dfsdf [4] => dsfsdfsd [description] => dsfsdfsd ) i just want every title and description printed out no matter how many there is the fuction that pages use function get_page($domain,$account) { require_once('DbConnector.php'); $loginConnector = new DbConnector(); $getTemplate = $loginConnector->query("SELECT * FROM pages WHERE domain = '$domain' AND account_number='$account'"); if ($loginConnector->getNumRows($getTemplate)<=0) { $page = 'No Pages Found'; } else { $page = $loginConnector->fetchArray($getTemplate); } return $page; } Link to comment https://forums.phpfreaks.com/topic/125791-solved-printing-all-information-out-from-an-array/#findComment-650452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.