Hi, when I try to use a SELECT statement in php, I get an error:

Resource id #18

<?php
include("include/session.php");
$get = mysql_query("SELECT value FROM settings WHERE id=2");
echo $get;
?>

The file session.php contains the database credentials .etc and it's correct.
But then when I try to echo $get, I get the error.

Why, I'm not sure and I'm still learning MySQL/PHP.

Please could someone help and thank you in advance for any replies.

Recommended Answers

Hi,

When you store the results of an SQL query for example, you need to pass it onto either mysql_fetch_array or

Jump to Post

All 3 Replies

You just need to read a little more.

Here's one article from a google search. I've picked mysqli rather than mysql as mysql is so last year :-)

Hi,

When you store the results of an SQL query for example, you need to pass it onto either mysql_fetch_array or mysql_fetch_assoc, and, go through a loop such as foreach, for example to output / use the information retrieved.

Also, since it seems you're relatively new with working with arrays, here's a tip. When working with, or outputting arrays in PHP, you can't simply 'echo' it. You must use a function like print_r, or better yet, use a loop like foreach to navigate through the array.

  • n21115

Using var_dump instead of echo if your intention is to check on the value of the variable. Change "echo $get;" to "var_dump($get);". Hope it helps!

For more information on var_dump check this out http://php.net/manual/en/function.var-dump.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.