...

View Full Version : Doesn't Work - Why?



Cerby
11-17-2007, 01:08 AM
Why doesn't the contents of the "title" field get displayed on the screen?


<?php
$con = mysql_connect("localhost","ODBC","");
if (!$con)
{
die(mysql_error());
}

mysql_select_db("MP3", $con);

$result = mysql_query("SELECT * FROM books");



echo $result['title'];



mysql_close($con);
?>

JustBlaze
11-17-2007, 01:25 AM
Try using this to connect via odbc:


$conn=odbc_connect('northwind','','');
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);

PappaJohn
11-17-2007, 02:31 AM
mysql_query() returns a resource id, not the recordset. Once you have that resource id you need to use it to fetch the recordset before you can display it.

For example:


$row = mysql_fetch_assoc($result);

echo $row['title'];

_Aerospace_Eng_
11-17-2007, 02:35 AM
Try this

<?php
$con = mysql_connect("localhost","ODBC","");
if (!$con)
{
die(mysql_error());
}

mysql_select_db("MP3", $con);

$result = mysql_query("SELECT * FROM books") or die(mysql_error());
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_assoc($result);
echo $row['title'];
}

mysql_close($con);
?>
Beaten to it. Either way you should also check to see if mysql_num_rows is greater than 0 or you will nave nothing to echo.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum