Solarpitch Posted November 10, 2008 Share Posted November 10, 2008 Hey, I have the below function that will return 5 results in an array... I'm just wondering how can I print the results to screen where I'm calling them. <?php function latest_news() { dbconnect(); $myinfo = array(); $sql = "SELECT * FROM latest_news ORDER BY id desc LIMIT 5"; $result = mysql_query($sql); while(($row = mysql_fetch_row($result)) != false) { $myinfo[] = " <h2><img src='designs/article.jpg' /><a href='article.php?id=".$row[0]."'> ".$row[1]."</a></h2> <p>".substr($row[2],0,65)."...</p> "; } return $myinfo; } ?> Then I'm trying to call it like this on the following page... but this willl only print the first result and not loop through to display all 5. <?php //page content.... $page_1->content .= latest_news(); //page content.... ?> Link to comment https://forums.phpfreaks.com/topic/132179-solved-small-array-print-question/ Share on other sites More sharing options...
Solarpitch Posted November 10, 2008 Author Share Posted November 10, 2008 I figured it out... <?php $alloc->content .= $e = latest_news(); foreach($e as $r){ $alloc->content .= $r;} ?> Link to comment https://forums.phpfreaks.com/topic/132179-solved-small-array-print-question/#findComment-686987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.