If I am doing a PHP MYSQL select of a table using the where clause that will return only 1 result, is there a simpler way to do this:
$result = mysql_query("select * FROM cart WHERE ID='".$cartID."'") or die(mysql_error());
$cartrec = mysql_fetch_array($result);
Is the $cartrec = mysql_fetch_array($result); needed or could I just do:
$cartrec = mysql_query("select * FROM cart WHERE ID='".$cartID."'") or die(mysql_error());
or is there a better syntax to use?
mysql_querygets a result set (actually, a resource that refers to a result set) based on your query. This is the set of records that match your query.mysql_fetch_arraygets the first record from a result set, and returns it as an array.So, up until you’ve called
mysql_fetch_array, you haven’t gotten the data in a usable format.Side note: Consider using PDO