Craigy
06-16-2010, 11:54 PM
I am wanting to fill parts of a page with values from a mysql database but Im not sure how to go about doing it. I used an example from w3 schools which displays things in a table fine, but I am wanting a different layout Please can somebody point me in the right direction. The layout works fine with <?php include("news.php"); ?> without my attempt to add database values.
<?php
$username = "user";
$password = "password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("username_news",$dbhandle)
or die("Could not select username_news");
echo "Connected to Database<br>";
//execute the SQL query and return records
$result = mysql_query("SELECT title, newstext, id, date FROM news");
echo "queried<br>";
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "<div id="main_column">"
echo "<div class="main_column_section">"
echo "<h2><span></span>".$row{'title'}. "</h2>"
echo" <div class="main_column_section_content">"
echo" <a href="#"><img class="image_wrapper fl_image" src="images/image_01.jpg" alt="image one" /></a>"
echo" <p><br />"
echo "<br />"
echo"".$row{'newstext'}. "<br />"
echo"".$row{'id'}. "<br />"
echo"".$row{'date'}. "<br />"
echo" </p>"
echo" </div>"
echo" <div class="cleaner"></div>"
echo" <div class="bottom"></div>"
echo"</div>"
}
//close the connection
mysql_close($dbhandle);
?>
<?php
$username = "user";
$password = "password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("username_news",$dbhandle)
or die("Could not select username_news");
echo "Connected to Database<br>";
//execute the SQL query and return records
$result = mysql_query("SELECT title, newstext, id, date FROM news");
echo "queried<br>";
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "<div id="main_column">"
echo "<div class="main_column_section">"
echo "<h2><span></span>".$row{'title'}. "</h2>"
echo" <div class="main_column_section_content">"
echo" <a href="#"><img class="image_wrapper fl_image" src="images/image_01.jpg" alt="image one" /></a>"
echo" <p><br />"
echo "<br />"
echo"".$row{'newstext'}. "<br />"
echo"".$row{'id'}. "<br />"
echo"".$row{'date'}. "<br />"
echo" </p>"
echo" </div>"
echo" <div class="cleaner"></div>"
echo" <div class="bottom"></div>"
echo"</div>"
}
//close the connection
mysql_close($dbhandle);
?>