say, there are two database tables named
user
id name
-- -----
1 Mike
2 Bob
3 Tony
4 Christina
5 James
product
product_id chooser_id chooser_name selection_status
---------- ---------- ------------ -----------------
1 1 Mike 0
2 2 Bob 1
3 3 Tony 0
4 3 Tony 1
5 3 Tony 1
here data available in the above product
table are inserted by the logged in users of user
table based on the following mysql syntax.
mysql_select_db($database_XYZ, $XYZ);
$query_test = "SELECT user.id, user.name, product.product_id, product.chooser_id, product.chooser_name, product.selection_status FROM user, product WHERE user.id = '$_SESSION[userid]' AND user.id = product.chooser_id AND product.selection_status = 1 ";
$test = mysql_query($query_$test, $XYZ) or die(mysql_error());
$row_test = mysql_fetch_assoc($test );
$totalRows_test = mysql_num_rows($test );
now if the user Tony wants to check the selection_status
(0
& 1
are flagged values) of product
table inserted by him in a logged in session depending on the following syntax
if (isset($row_test ["selection_status"]) == "1") {
echo $row_test ["selection_status"];
}
the syntax unusually returns 1
, 1
as he is still logged in while checking the data and it fetches all rows which unexpectedly seem to match mysql
query from following part of product
table :
product_id chooser_id chooser_name selection_status
---------- ----------- ------------- -----------------
4 3 Tony 1
5 3 Tony 1
how to call / check only one row of mysql database in a session array using alternative php conditional statement so that it returns the data of only one row in each check or call like?
product_id chooser_id chooser_name selection_status
---------- ----------- ------------- -----------------
4 3 Tony 1
or
product_id chooser_id chooser_name selection_status
---------- ----------- ------------- -----------------
5 3 Tony 1
please note that, mysql LIMIT
and WHERE product_id=4
etc. won't be applicable here since data shall be populated here through session.