PDA

View Full Version : Small problem



tesandco
May 16th, 2002, 12:22
Basically Ive got the main database for OpenBB, and I wanted to extract one of the fields for use in a different script. I came up with this


/* Connecting, selecting database */
$link = mysql_connect("db.host.sk", "tesandco", "*****")
or die("Could not connect");
mysql_select_db("tesandco") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT `homepage` FROM `profiles` WHERE id=7 LIMIT 0, 30 ";
$result = mysql_query($query) or die("Query failed");
mysql_close($link);


The result generated to $result gives me 'Resource Id #2'. The query works in phpMyAdmin, so why not here?

LastActionHero
May 16th, 2002, 12:36
See here (http://www.phpbuilder.com/forum/read.php3?num=5&id=5616&thread=5615)
Basically mysql_query() returns a RESULT set.

spec
May 16th, 2002, 16:56
First off do this:


<?
/* Performing SQL query */
$query = "SELECT `homepage` FROM `profiles` WHERE id=7 LIMIT 0, 30 ";
$result = mysql_query($query) or die(mysql_error());


Do u get any errors

also that code does nothing on its own.
try this


<?
$query = "SELECT * FROM `profiles` WHERE id=7 LIMIT 0, 30 ";
$result = mysql_query($query) or die(mysql_error());
$row=mysql_fetch_assoc($result);
extract($row);
echo $homepage;
?>

That does something but is it what you want?

tesandco
May 17th, 2002, 00:36
That does something but is it what you want?

That got it exactly! Thanks Spec!