Displaying data from mysql into HTML

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rashpal
Forum Newbie
Posts: 7
Joined: Tue Apr 15, 2003 7:22 am

Displaying data from mysql into HTML

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

We can help better if you say exactly what errors you are getting and show us some of your code.

Mac
User avatar
AlphaWolf
Forum Newbie
Posts: 12
Joined: Sun Mar 23, 2003 8:49 pm

Post 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.
Post Reply