FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Resource id #3 ?!?!?





web-geek
Code:
<?php
function connect() {
   $dbUser = "blahblahblah";  // 100% correct
   $dbPass = "blahblahblah";  // 100% correct
   $dbName = "blahblahblah";  // 100% correct
   
   $connect = mysql_connect("localhost", $dbUser, $dbPass) or die ("Could not connect: " . mysql_error());
   $dbconnect = mysql_select_db($dbName, $connect) or die ("Could not connect: " . mysql_error());
      
$sql = "SELECT text FROM content WHERE content = 1";

connect();

$result = mysql_query($sql);

?>


Later on in the page

Code:

<?php
   echo $result;
?>


When I load the page all I get is Resorce id #3

If I make an incorrect password, I get the normal errors that say I can't connect and so on. I make the exact same query in phpMyAdmin and i get the desierd content... anyone know whats going on?
Dougie1
mysql_query returns a reference to a result set rather than the result set itself, so you get rubbish if you print it out. You need to call a function such as mysql_fetch_array or mysql_fetch_assoc to read a result itself from the result set object (and what you get will be an array). If your query can return more that 1 row, keep calling it until there are no more rows to get back.

In many ways, a result set is like a file handle that you read from, and just like a file handle it's used to let you iterate over what can be a huge data set in easy steps rather than having you presented with too much data all at the same time
web-geek
THANKS! I have not programmed in quite some time so I am trying to refresh myself on these things! thank you again!
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.