简体   繁体   中英

change mysql datetime to php datetime-local not working by strtotime()

I have mysql table with datatime type and i want it to show in php/html table

while($row = mysqli_fetch_assoc($result)) {
$time1 = strtotime($row["Request Date"]);
$myFormatForView = date("d/m/y g:i A", $time1);

output

11/02/15 10:18 AM

now i tried this code to work with html table

<td>  <input type='datetime-local' id='txt_dateid_".$i."' value=".$myFormatForView."  disabled></td>

but i am not getting any output

full code

 <?php
        include_once "connector.php";

        $sql = "SELECT * FROM $tablename";
        $result = mysqli_query($db,$sql);

        $i=0;
        $row=0;
        if (mysqli_num_rows($result) > 0) {


            while($row = mysqli_fetch_assoc($result)) {
                        $time1 = strtotime($row["Request Date"]);
                                    $myFormatForView = date("d/m/y g:i A", $time1);
                                echo ($myFormatForView);
               echo
                 "
                <tr>
                 <td size='20' align='center'>  <input type='text' id='txt_orderid_".$i."'value=" . $row["Order ID"]. " disabled> </td>                      
                 <td>  <button type='button' id='btn_update_".$i."'  onclick='myFunction($i)'>update</button> </td>
                 <td>  <button type='button' id='btn_delete_".$i."'  onclick='DeleteFunction($i)'>delete</button> </td>
                 <td>  <input type='datetime-local'  id='txt_dateid_".$i."'value="  . $myFormatForView. " disabled></td>
                 <td>  <input type='text' id='txt_timeid_".$i."'class='txt_id_".$i."'     value="  . $row["Fixed Time"]. " disabled></td>
                 <td>  <input type='text' id='txt_toolid_".$i."'     class='txt_id_".$i."'   value="  . $row["Tool"]. " disabled> </td>
                 <td>  <input type='text' id='txt_nameid_".$i."'         class='txt_id_".$i."'    value="  . $row["Name"]. " disabled> </td>
                 <td>  <input type='text' id='txt_emailid_".$i."'        class='txt_id_".$i."'    value="  . $row["Email"]. " disabled> </td>
                 <td>  <input type='text' id='txt_countid_".$i."'    class='txt_id_".$i."'    value="  . $row["Country Entered"]. " disabled> </td>


      </tr>

                 ";
                $i++;
            }

edit 1 :

this code also does not work

<td> <input type='datetime-local' id='txt_dateid_".$i."' 'value'=".$myFormatForView." disabled></td>

看到请求日期列,我要填写

Edit 2:

Error Spotted you haven't put quotes in value '' . Use this

<td>  <input type='datetime-local' id='txt_dateid_".$i."' value='".$myFormatForView."'  disabled></td>

Hope this helps you

You have there missing spaces between attributes ( id and value ) and missing quotes around the value attribute:

<td>  
    <input type='datetime-local' id='txt_dateid_" . $i . "' value='" . $myFormatForView . "' disabled>
</td>

Note: for better reading I've indented input in td and put there optinal spaces around dots . .

you have mistaken here

<td>  <input type='datetime-local' id='txt_dateid_".$i." 'value=".$myFormatForView."  disabled></td>

replace this line with below one

<td>  <input type='datetime-local' id='txt_dateid_".$i."' 'value='".$myFormatForView."'  disabled></td>

You have missed the quotes for value attribute. Try this:

<td>  <input type='datetime-local' id='txt_dateid_".$i."' value='".$myFormatForView."'  disabled></td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM