Jump to content

Question plz


esoom

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
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.