MySQL data into a html table

Hi, I wanna be able to display all MySQL data into a HTML table, with the functions of editing and deleting specific data…please help…thanks

To display content in a HTML table from PHP/MySQL…

First
you need to create a database connection:
connect.php
[php]<?php
define(‘DB_HOST’,‘localhost’);//creates constant Host. If you are not working locally, enter database hostname provided by your webhost provider
define(‘DB_USER’,‘dbuser’);//creates constant User
define(‘DB_PASS’,‘dbpass’);//creates constant Password
define(‘DB_NAME’,‘myDatabase’);//creates constant database name

$connection = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die (mysql_error());
mysql_select_db(DB_NAME) or die (mysql_error());
?>[/php]

Then create the content page where data will be displayed…
content.php

[php]

<?php include ("includes/connect.php");//connect file resides in a folder called "includes" $query = mysql_query ("SELECT * FROM myTable");//database table called "myTable" WHILE ($row = mysql_fetch_assoc($query)){ echo ''.''; }?>
'.$row['id'].''.$row['name'].'
[/php]

That’s it. This set up assumes you are connecting to the database myDatabase and fetching the table myTable
Then pull id and name fields (assuming they exist in your table) from myTable and parsed to html using the Table tags.

Also, I use CSS class in <table class"myTableStye"> to control the look of your html table. You have to declare this class in a CSS (stylesheet) and add it to the header of the page. If you nee help with this, just ask. I assume you know a bit about CSS, I don’t explain it here.

For updating and deleting content you need to create some sort of control panel that uses forms to put and pull data from and to the database. This is a bit more complex to explain it here.

Here’s a good video tutorial that you can follow. It will make more sense to you this way…

http://www.youtube.com/watch?v=u3ry84gg0fw
I hope this can help you.

Sponsor our Newsletter | Privacy Policy | Terms of Service