Page 1 of 1

Formatting Data

Posted: Sat Oct 13, 2007 6:00 pm
by gregwhitworth
Ok, here's the scoop -

I am creating a very simple cms (This is my first), and so far I can connect to mySQL, connect to the Table, Retrieve and display data.

Here is where my problem lies, I want the user to be able to enter as many new items as they want and I want each of them to be formatted the same way:

News Header - Date
Description

Here is the PHP Code:

Code: Select all

<?php

	$username = "root";
	$password = "";
	$hostname = "localhost";
	$select = "SELECT header,date,description FROM news"; 
	$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
	print ("Connected to MySQL<br>");
	
	$selected = mysql_select_db("biglakebaptist",$dbh) or die("Could not select biglakebaptist");
	print ("Selected biglakebaptist<br>");
	
	$result = mysql_query($select) or die("Could not select news");
	print ("Selected news table<br>");

	while($col=mysql_fetch_assoc($result))
	{
		$header[] = $col['header'];
		$date[] = $col['date'];
	}
	
	print($header);
	
	foreach ($header as $value) {
    echo "Value: $value<br />\n";
}
			
	mysql_close($dbh);
	
?>
Where my problem is is this: I don't want to have to type in $value every time the user enters a value, how do I get them all to display, and display in different divs automatically.

Thanks, I hope that makes sense.
Greg