php - Checking if a particular entry already present in MySQL -
php - Checking if a particular entry already present in MySQL -
i've table events
next fields:
`id`-->int,primary , auto_increment `event_id`-->int `mem_1_id`-->int `mem_2_id`-->int `mem_3_id`-->int `mem_4_id`-->int `mem_5_id`-->int `mem_6_id`-->int
all mem_x_id
(0<x<7)
distinct particular event_id
in events
table. id
primary key used. possible example:
id event_id mem_1_id mem_2_id mem_3_id mem_4_id mem_5_id mem_6_id 1 11 123 345 567 67 34 56 2 12 234 555 67 43 23 12 2 12 34 55 167 435 233 122
now want check if user's id
(from users
table) has logged in , viewing page of particular event nowadays or not in events
table under event's id
. there may multiple entries particular event_id
. want search in event_id
of event page.
my code below: please note, i'm new php , hence still using old version. plan things working, , modify code pdo. i'm learning pdo parallelly. first wish create code work.
$id=stores event_id of event page user viewing. $_session['id']=`id` of user logged in , viewing page. if(isset($_session['id'])){ $result1=mysql_query("select id events event_id='".$id."')"); if ($result1 == false) { echo mysql_error(); die; } $row1 = mysql_fetch_assoc($result1); if($row1['id']){ if ($_session['id']==$row1['mem_1_id'] || $_session['id']==$row1['mem_2_id'] || $_session['id']==$row1['mem_3_id'] || $_session['id']==$row1['mem_4_id'] || $_session['id']==$row1['mem_5_id'] || $_session['id']==$row1['mem_6_id']){ $is_already_regis=1; } } }
in query, have select fields going use:
"select id, mem_1_id, mem_2_id, [...], mem_6_id events event_id='".$id."'"
then, have utilize loop check each row:
while ($row = mysql_fetch_assoc($result1)) { if ($_session['id']==$row['mem_1_id'] || $_session['id']==$row['mem_2_id'] || $_session['id']==$row['mem_3_id'] || $_session['id']==$row['mem_4_id'] || $_session['id']==$row['mem_5_id'] || $_session['id']==$row['mem_6_id']){ $is_already_regis=1; } }
php mysql sql session search
Comments
Post a Comment