I need to get a field from a mySQL database using PHP
The problem is that in my mysql panel I use this sql code:
SELECT * FROM TESTS WHERE TEST_ID=1
and I get exactly what I want (I see the row that I want to display)
But if i use this code in PHP:
<?php
$con=mysql_connect("localhost", "root", "psw") or die("\nConnection Failed\n");
mysql_select_db("mydb")or die("\nDB Failed\n");
$query = "SELECT * FROM TESTS WHERE TEST_ID=1";
$result=mysql_query($query);
echo $result;
mysql_close($con);
?>
all I get is “Resource ID #3”
why??
the $result is a resource which is a link to a result set from mysql. To get the actual data you have to do something like:
You would need to repeat the mysql_fetch_assoc() call for each row you want to retrieve, until it returns false, indicating there are no more rows, which can be done in a while loop like this: