FrankNP
1
I’m a MySQL/PHP newbie with a problem I can’t figure out.
Have a simple database with 2 columns and 2 rows of data as follows:
site url
Google googlecom
Yahoo yahoocom
I want to use PHP to retreive this data and display it on a web page as hyperlinks so the output is as follows:
Major Search Engines
Google (This would be a hyperlink)
Yahoo (This would be a hyperlink)
Any help would be greatly appreciated.
#connect to server
$con = mysql_connect('host', 'username', 'password');
#make sure we connected ok
if(false === is_resource($con)){
echo 'Cannot Connect: ' . mysql_error();
exit;
}
#select our database
mysql_select_db('database', $con);
#execute our query
$res = mysql_query('SELECT site, url FROM table');
#make sure the query executed
if(false === is_resource($res)){
echo 'Cannot Query: ' . mysql_error();
exit;
}
#display how many records we found
echo '<h2>' . mysql_num_rows($res) . ' found.</h2>';
#display the records
while($record = mysql_fetch_assoc($res)){
printf(
'<a href="%s">%s</a>',
$record['url'],
$record['site']
);
}

FrankNP
3
Thank you that did the trick.