Q:

MySQL Random output does not work

So I want to pull a random record off my DB:
mysql_connect("127.0.0.1","my_shop","xxxxxx");

mysql_select_db("my_shop_db");
error_reporting(E_ALL && ~E_NOTICE);

$random_record = "SELECT * FROM products ORDER BY RAND() LIMIT 1";
$random_product = mysql_query($random_record) or die ($random_record);

echo $random_product['id'];

What I tried so far:

DB Connection works 100%
Tables exist, have exact wordings and contain data
DB User has rights to pull Data

What is wrong with my script?

A:

Obligatory comment that mysql_* is deprecated and not safe and should not be used anymore.
mysql_query returns a resource object NOT an array. You need to fetch the data into an array so you can access it.
$random_record = "SELECT * FROM products ORDER BY RAND() LIMIT 1";
$random_product = mysql_query($random_record) or die ($random_record);
//fetch data
$data_array = mysql_fetch_assoc($random_product);

echo $data_array['id'];

print_r the array so you understand the structure and how to access the element you want.

