Jump to content

[SOLVED] Small Array Print Question?


Solarpitch

Recommended Posts

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

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.