views:

63

answers:

4

I am a complete database newbie. So far, I know that I can connect to MySQL using PHP's mysql_connect() command, but apart from that, I really don't see how to take that data and put it onto a web page.

a) are there ways other than mysql_connect()

b) lets say I had a table of data in mysql and all I wanted was for that table (for example: list of names and telephone numbers) to now appear on my web page. I can't for the life of me find a tutorial for this.

+1  A: 

First hit on Google for "php mysql": http://www.freewebmasterhelp.com/tutorials/phpmysql

Or if you prefer a hit on the mysql page itself: http://dev.mysql.com/tech-resources/articles/ddws/index.html

Paul Tomblin
+1  A: 

You should really read a good tutorial.

Here's one

Edit: Too late. ;)

yper
+1  A: 

Check out e.g. this tutorial, which seems to be doing something very similar - an address book with names and telephone numbers, using PHP and MySQL. That should clarify some things :)

Piskvor
+3  A: 
<?
$database_name = "dbname";
$mysql_host = "localhost"; //almost always 'localhost'
$database_user = "dbuser";
$database_pwd = "dbpass";
$dbc = mysql_connect($mysql_host, $database_user, $database_pwd);
if(!$dbc)
{
    die("We are currently experiencing very heavy traffic to our site, please be patient and try again shortly.");
}
$db = mysql_select_db($database_name);
if(!$db)
{
    die("Failed to connect to database - check your database name.");
}

$sql = "SELECT * FROM `table` WHERE `field`= 'value'";
$res = mysql_query($sql);

while($row = mysql_fetch_assoc($res)) {
    // code here
    // access variables like the following:
    echo $row['field'].'<br />'; 
    echo $row['field2'];
}
?>

Check out mysql_fetch_assoc mysql_fetch_array and mysql_fetch_object

This is the very basics, you will want to search for tutorials. There are many about.

Lizard
Typo on your select statement. "SELEET" becomes "SELECT."
T Pops