php - Compare data from two tables and check the same data -
hello have 2 tables in database.
the first 1 table disease above...
and second table patient ...
and have edit page want give user ability update his/her diseases. example below..
what want check disease column table patient column name table disease , check if data table patient same data table disease check checkboxes same disease.
i tried find way couldnt here code...
<?php $sql = "select name disease union select disease patient username='$username'"; $query_resource = mysql_query($sql); while( $name = mysql_fetch_assoc($query_resource) ): ?> <span><?php echo $name['name']; ?></span> <input type="checkbox" name="disease[]" value="<?php echo $name['name']; ?>" /><br /> <?php endwhile; ?>
the way store diseases in database this...
$disease = implode(",",$_post["disease"]);
because user might have many diseases
my answer not looking however. if u building application should consider integrating relations between person , desies tables. besause it's mysql relational databases :)
if got right: not tested
<?php $sql = "select disease patient username='$username'"; $query_resource = mysql_query($sql); $person = mysql_fetch_assoc($query_resource); $persons_desisies = explode(',', $person['disease']); $sql = "select name disease"; $query_resource = mysql_query($sql); $disease = array(); while( $name = mysql_fetch_assoc($query_resource) ): ?> <span><?php echo $name['name']; ?></span> <input type="checkbox" name="disease[]" value="<?php echo $name['name']; ?>" <?php if(in_array($name['name'], $persons_desisies)): ?> checked="checked" <?php endif; ?>/><br /> <?php endwhile; ?>
idea - getting patiens desieses list , checking full desies list. :)
Comments
Post a Comment