Can´t retrieve data from database

Hi,

I know this must be very simple but I am struggling with it.

I’m trying to retrieve data from MySQL, but I don’t know why my code doesn’t work :frowning:



  require('includes/cloud.php');
  $query = "select products_name from " . TABLE_PRODUCTS_DESCRIPTION . "";
  $text_content = mysql_query($query);
  echo($text_content);


It echos the error Resource id #45

Thanks in advance

It solved my problem.
Thank you very much guys for the quick response :slight_smile:

Hi duarte300,
You are using it in a wrong way.




  require('includes/cloud.php');
  $query = "select products_name from " . TABLE_PRODUCTS_DESCRIPTION . "";
  $text_content = mysql_query($query);
  $rs=mysql_fetch_array($text_content);
  echo $rs['products_name'];

you missed to fetch the data using the mysql_fetch_array or assoc or object…

Hi duarte300,

Welcome to sitepoint forums!

Before you use any of the php functions , please try to understand what and how that function does work for you. You can just see the manual at http://www.php.net/mysql_query. Here you have tried to echo the resource because the mysql_query function return the resource. See mysql_num_rows(), [URL=“http://www.php.net/mysql_fetch_assoc”]mysql_fetch_assoc(), [URL=“http://www.php.net/mysql_fetch_array”]mysql_fetch_array() or [URL=“http://www.php.net/mysql_fetch_object”]mysql_fetch_object() functions in manual page.


$query = "select products_name from " . TABLE_PRODUCTS_DESCRIPTION . ""; 
$result = mysql_query($query) or die(mysql_error()); 
$row = mysql_fetch_assoc($result);
echo $row['products_name'];

This should display product name as you expected.

Good luck!