Page 1 of 1

Displaying data from mysql into HTML

Posted: Tue Apr 15, 2003 7:22 am
by rashpal
Hello,

I have a query, I am developing an information website and am expericing a few minor problems. I would like to know how to display data from mysql database dynamically. I have tired this several times but to no avail.

I seem to be getting parse errors!!


Can anyone help as this is becoming frustrating!!!!!!! :cry:

Posted: Tue Apr 15, 2003 7:33 am
by twigletmac
We can help better if you say exactly what errors you are getting and show us some of your code.

Mac

Posted: Fri Apr 18, 2003 3:35 pm
by AlphaWolf
Hmmm, without knowing the errors, the data, the tables, etc...
In very generic form...

Code: Select all

<?php
// Make your connection to the DB. 
$link = mysql_connect("localhost", "db_username", "db_password");

// Choose your DB.
$db = mysql_select_db("db_name", $link);

// Your SQL statement.
$sql = "SELECT * from your_table";
$result = mysql_query($sql, $link) or die(mysql_error());

while ($row = mysql_fetch_array($result)) &#123;
 $id = $row&#1111;"$id"];
 $field1 = $row&#1111;"$field1"];

//Note this is in a while loop so for each record you will get the following line. Format away here...
 echo "Now you can display $id and/or $field1 here";
&#125;

//close your db connection.
mysql_close($link);

?>
This is not taking an security into account, assuming the db is on localhost, etc.

Good luck.