esoom Posted May 22, 2006 Share Posted May 22, 2006 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 https://forums.phpfreaks.com/topic/10154-question-plz/ Share on other sites More sharing options...
.josh Posted May 22, 2006 Share Posted May 22, 2006 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 outwhile ($listinfo = mysql_fetch_array($result)) { echo $listinfo['name'] . " " . $listinfo['email'] . "<br>";}[/code] Link to comment https://forums.phpfreaks.com/topic/10154-question-plz/#findComment-37849 Share on other sites More sharing options...
esoom Posted May 22, 2006 Author Share Posted May 22, 2006 Oh rightThank you kind sir [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Link to comment https://forums.phpfreaks.com/topic/10154-question-plz/#findComment-37858 Share on other sites More sharing options...
esoom Posted May 22, 2006 Author Share Posted May 22, 2006 another thingive 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 https://forums.phpfreaks.com/topic/10154-question-plz/#findComment-38003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.