-4

I have a 7 check-boxes(monday,tuesday,wed,thur,friday,sat,sunday) and each of these tag i am having start and end time tag. Down below you can see the picture of the design

HERE IS THE DESIGN

Now in database there is couple of entries like 1st id is having monday and bluh..bluh. You can see the picture of the database

<form  id="checking" method="POST" >
        <?php   
        $data=new User();
        // in row it is array of the database details
        $row=$data->Display('date');

    $checkbox='';
    $days = ["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
    $out[]='<table>';
        for($i = 1; $i <=7; $i++){
            $out[]= '<tr>';
            $out[]= '<td><input type="checkbox" name="events[]" value="'.$i.'" />'.$days[$i].'</td>';
            $out[]= '<td><input type="text" name="start'.$i.'" value="'.$row[$i]['starttime'].'" />da</td>';
            $out[]= '<td><input type="text" name="end'.$i.'" id="endTime'.$i.'" />End Time</td>';
            $out[]= '</tr>';
        }
        $out[]='<table>';
        echo join($out);
?>
       <br/> <button  id="sub"  name="btnregister">Submit</button>      
        </form>

DATABASE PICTURE

Now here is the trick- Fetch the details from the database and display it in input fields and if monday is having then it should checked that checkbox.

I really do not know what type of code i write and how i can print weekend name and should checked the checkbox if enteries is entered in database.

8
  • 1
    we need to see code examples of what you've tried so far to help you Commented May 22, 2019 at 17:49
  • first you try it and show us code what you done? Commented May 22, 2019 at 17:50
  • @MohitKumar I really do not know how i do it. I can display the data in input field but how it will know that monday value should only enter in monday Commented May 22, 2019 at 18:00
  • Check this or here for some examples . Commented May 22, 2019 at 18:02
  • @Swati So when i will fetch the data from database then how it will know that it should go on which input tag Commented May 22, 2019 at 18:06

1 Answer 1

0

Hope this will helps you...

<?php
// Create connection
$con=mysqli_connect("hostname","username","pass","dbname");

$result = mysqli_query($con,"SELECT * FROM table_name"); 
while($row = mysqli_fetch_array($result))
  {
    $a=$row['field_name'];

?>
<input type="checkbox" name="week[]" value="monday" <?php if(in_array("monday",$a)) { ?> checked="checked" <?php } ?> >
<input type="checkbox" name="week[]" value="tuesday" <?php if(in_array("tuesday",$a)) { ?> checked="checked" <?php } ?> >
<input type="checkbox" name="week[]" value="Wednesday" <?php if(in_array("Wednesday",$a)) { ?> checked="checked" <?php
 } ?> >
<?php
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

what is field_name
field_name is colum name which you want ?
See the question carefully. I want to print Monday Tuesday....go on then in database it will checked which is having in database same for the text tags.... Here is the problem how should print weekend name with your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.