Jump to content

Archived

This topic is now archived and is closed to further replies.

esoom

Question plz

Recommended Posts

if i have a table with its hostname as DBserver and database name as Dbase and the table consists of 5 columns called catref, title, artist, catorgry and number

how would i write the code to connect to the database and retrieve all the information on the table as a results table.....can some1 help me

Share this post


Link to post
Share on other sites
assuming you have a table called 'table' and some columns called 'name' and 'email' for example purposes:

[code]
//database information used to connect
$host = 'localhost'; // the host name for the database. usually 'localhost' works
$user = 'username'; // the database username
$pass = 'password'; // the database password
$dbname = 'databasename'; //name of your database

//connect to the database
$conn = mysql_connect($host, $user, $pass) or die(mysql_error());
$db = mysql_select_db($dbname) or die(mysql_error();

//select all the information from the table
$sql = "select * from table";
$result = mysql_query($sql, $conn) or die(mysql_error());

//get the results of the query and print it out
while ($listinfo = mysql_fetch_array($result)) {
   echo $listinfo['name'] . " " . $listinfo['email'] . "<br>";
}
[/code]

Share this post


Link to post
Share on other sites
Oh right

Thank you kind sir [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites
another thing

ive written this code

<?php
$cat="Rock";
$result=@mysql_query("SELECT Title, Artist
FROM Stock WHERE Category='$cat'");
while ($item=@mysql_fetch_array($result))
{
extract($item);
print("<p>$Title $Artist</p>");
}
$number=@mysql_num_rows($result);
print("<p>$number matches found</p>");
?>

but how do i generate this in html when this run

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.