Page 1 of 1

Custom display of MYSQL content.

Posted: Fri Mar 02, 2012 10:32 pm
by jmgr2007
How can i make a code like:

Code: Select all

<?php
		mysql_connect(localhost,$username,$password);
		@mysql_select_db($database) or die( "Unable to select database");
		$query="SELECT * FROM `Posts` ORDER BY `Date` DESC LIMIT 10";;
		$result=mysql_query($query);
		
		mysql_close();
?>
echo out to display the columns in a format like :

Code: Select all

<?php
		$Title=mysql_result($result,$i,"Title");
		$Body=mysql_result($result,$i,"Body");
		$Date=mysql_result($result,$i,"Date");
		$Author=mysql_result($result,$i,"Author");
		
		echo "<center><h1>$Title</h1></center><br/><table><tr><td>
		<p>$Body</p></td></tr></table><br><h6 align='right'>By: $Author<br>Date:$Date</h6><hr>";
		
		$i--;
?>
Please help.

Re: Custom display of MYSQL content.

Posted: Sat Mar 03, 2012 6:07 am
by Celauran
Looks like you've already got the right idea, just move it into a while loop.

Code: Select all

while ($row = mysql_fetch_assoc($result))
{
    echo "<h1>{$row['Title']}</h1>";
    echo "<p>{$row['Body']}</p>";
    echo "<h6>By: {$row['Author']} Date: {$row['Date']}</h6>";
}