PHP MySQL Data retreival... Problem?
Hey folks,
I'm still quite the newbie to PHP/MySQL, but I have done a website for Uni which worked perfectly well. I am trying to get some information using the following (just for testing right now).
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testing</title>
</head>
<body>
<?php
// open connection
$connection = mysql_connect("IPADDRESS", "xxxxx", "xxxxx") or die ("Unable to connect!");
// select database
mysql_select_db("xxxxx") or die ("Unable to select database!");
// Collects data from "ibf_topic" table
$data = mysql_query("SELECT * FROM ibf_topics")
or die(mysql_error());
// puts the "ibf_topic" info into the $info array
$info = mysql_fetch_array( $data );
// Print out the contents of the entry
Print "<b>TOPIC ID:</b> ".$info['topic_id'] . " ";
Print "<b>TITLE:</b> ".$info['title'] . " <br>";
?>
</body>
</html>
Is there any reason why that should not work?
Thanks
Re: PHP MySQL Data retreival... Problem?
You aren't specifying which row/record you want in the array. Try;
Code:
Print "<b>TOPIC ID:</b> ".$info['topic_id'][0] . " ";
Print "<b>TITLE:</b> ".$info['title'][0] . " <br>";
for the first row/record. You might want to reverse the order of row number and fieldname - can't remember OTOH which way round they go. I usually use echo instead of print.