Display x amount of links from a MySQL database

This example will display only 5 entries from the sample MySQl database
//database can be found at http://www.getphp.net/sample-mysql-database/
//connect to server with username and password, this is the default settings
//when MySQL is installed on Windows XP(Not recommended)
$connection = mysql_connect (“localhost”,”root”, “”) or die (“Cannot make the connection”);
//connect to database
$db = mysql_select_db (“test”,$connection) or die (“Cannot connect to database”);
//our SQL query
$sql_query = “SELECT * FROM test LIMIT 5”;
//store the SQL query in the result variable
$result = mysql_query($sql_query);
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
echo (“<a href=\”$row[2]\”>$row[3]</a>”);
echo (“: $row[4]<br>”);
//if no fields exist
echo “no values in the database”;



Please enter your comment!
Please enter your name here