dimanche 18 janvier 2015

How would I show this checkbox on realtime?

I'm currently studying html and php and I made this little project about a "notification system". I guess I first have to explain this before I go in detail on my real problem.


My table looks like this:


enter image description here




  1. My first php command would get the values of each feature column and store them into $a, $b, $c, $d and $e.




  2. My second php command would echo 5 textboxes and mark them as checked based on the value of $a,$b,$c,$d and $e so the output based on my table would show five checkboxes with the 1st, 2nd and 4th checkbox with a check.




  3. My third php command would gather the values from the checkboxes because the user might want to change his preferred notifications. After clicking submit the code would update the new values of the textboxes.




Below is the code on my current progress:



<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('main_database') or die(mysql_error());

$fetchchoice=mysql_query("SELECT * FROM notification_table WHERE username='carl'");

while($getchoice=mysql_fetch_assoc($fetchchoice)){
$a=$getchoice['feature1'];;
$b=$getchoice['feature2'];
$c=$getchoice['feature3'];
$d=$getchoice['feature4'];
$e=$getchoice['feature5'];
}
?>
<html>
<head>
</head>
<body>
<form method="POST">
<?php
echo
'
<input type="hidden" name="choice1" value="">
<input type="checkbox" name="choice1" value="checked" '.$a.' > Feature 1 <br>
<input type="hidden" name="choice2" value="">
<input type="checkbox" name="choice2" value="checked" '.$b.' > Feature 2 <br>
<input type="hidden" name="choice3" value="">
<input type="checkbox" name="choice3" value="checked" '.$c.' > Feature 3 <br>
<input type="hidden" name="choice4" value="">
<input type="checkbox" name="choice4" value="checked" '.$d.' > Feature 4 <br>
<input type="hidden" name="choice5" value="">
<input type="checkbox" name="choice5" value="checked" '.$e.' > Feature 5 <br>
';
?>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
$f1choice = $_POST['choice1'];
$f2choice = $_POST['choice2'];
$f3choice = $_POST['choice3'];
$f4choice = $_POST['choice4'];
$f5choice = $_POST['choice5'];

echo "1.";
echo $f1choice;
echo "<br />";
echo "2.";
echo $f2choice;
echo "<br />";
echo "3.";
echo $f3choice;
echo "<br />";
echo "4.";
echo $f4choice;
echo "<br />";
echo "5.";
echo $f5choice;

$kweri = "UPDATE `main_database`.`notification_table` SET `feature1` = '".$f1choice."', `feature2` = '".$f2choice."', `feature3` = '".$f3choice."', `feature4` = '".$f4choice."', `feature5` = '".$f5choice."' WHERE `notification_table`.`username` = 'carl'";
mysql_query($kweri);
}
?>
</body>
</html>


PROBLEM


My problem now is that I have to refresh the page to have the updated checkbox to appear since this was only done on php, I have no experience in javascript at all but I think it's the best way to show my current textbox on realtime, however, I have no idea where to start or if there is another way I could go about showing my checkbox on realtime.


EXTRA PROBLEM (This has something to do with my system but not regarding this code. If you guys could take a look at this problem it would mean a lot.)


As you guys have seen, the table above was just to keep track of what a user's preference regarding notifications would be. But the system doesn't stop there, I need to figure out how to pass notifications after a feature has been used. What my idea was is that I should add an extra sql command after every feature to put what has happened on a different table. Example would be registration, after the insert command for the registration details to be saved, I would also insert that, user "example" has "registered" on "date" in a separate table, namely "notif_table". My columns would be, username, action and date so my notifications page can show that "User" has "Registered" on "January 18, 2015".


But then again, that was just my theory on notifications and I'm very open to suggestions and corrections.





Aucun commentaire:

Enregistrer un commentaire