View Full Version : Select from not working...
iceflyin
07-25-2007, 08:21 AM
$ownerId= '19717633';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("iceflyin_frFacebook", $conn);
$rssURL = mysql_query("SELECT rssURL FROM userInfo WHERE user = $ownerId");
echo "$rssURL";
That results in: Resource id #2 -- What the heck is Resource id #2?
Now, heres the weird thing... When I ruin a this query in PHPMYADMIN, It gives me the rssURL... What gives?
SELECT rssURL FROM userInfo WHERE user = 19717633
Results in: http://blog.myspace.com/blog/rss.cfm?friendID=4277...
_Aerospace_Eng_
07-25-2007, 09:19 AM
Try this
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("iceflyin_frFacebook", $conn);
$ownerId= '19717633';
$sql = "SELECT rssURL FROM userInfo WHERE user = '$ownerId'";
$rssURL = mysql_query($sql,$conn) or die('The mysql error is: '.mysql_error().'<br>The query was: '.$sql);
The reason it worked in phpmyadmin is because you were using real data. You weren't using variables like you are in php. In the mysql query any variables if strings need to be in single quotes.
Its always good to have error checking on your mysql_query calls this way you know why the query is failing. Also echoing out rssURL is useless because it doesn't really return any data.
iceflyin
07-25-2007, 09:22 AM
Same old... Resource id #2
Argh...
_Aerospace_Eng_
07-25-2007, 09:25 AM
Not sure what you mean. What is it saying? Where are you running the query? What is the error?
iceflyin
07-25-2007, 09:30 AM
testing.php, in a subfolder on my server...
<?php
$ownerId= '19717633';
$dbhost = 'localhost';
$dbuser = '*****';
$dbpass = '*****';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("iceflyin_frFacebook", $conn);
$ownerId= '19717633';
$sql = "SELECT rssURL FROM userInfo WHERE user = '$ownerId'";
$rssURL = mysql_query($sql,$conn) or die('The mysql error is: '.mysql_error().'<br>The query was: '.$sql);
echo "$rssURL";
?>
I want to pull rssURL out of the database for use in my PHP script.
It keeps giving me fu**ing Resource id 2, instead of the rssURL... I need it to give me the full url as a variable!
http://www.iceflyin.com/db.gif
_Aerospace_Eng_
07-25-2007, 09:35 AM
No need for swearing. It keeps giving you that because thats not the way to return the data from the database.
<?php
$ownerId= '19717633';
$dbhost = 'localhost';
$dbuser = '*****';
$dbpass = '*****';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("iceflyin_frFacebook", $conn);
$ownerId= '19717633';
$sql = "SELECT rssURL FROM userInfo WHERE user = '$ownerId'";
$result = mysql_query($sql,$conn) or die('The mysql error is: '.mysql_error().'<br>The query was: '.$sql);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
echo $row['rssURL'];
?>
iceflyin
07-25-2007, 09:37 AM
Lol, sorry, not swearing at you... I have just been puzzling over this for hours...
Driving me crazy, thanks a ton! I didn't know it wouldn't just return the variable.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.