John Davidson

php - how to show db value in time type input box?

0 comments
Message:


Want to show previous data on the edit Page.


I'm trying this


<input type="time" name="opening_hour" value="{{ old('opening_hour', $restaurants->opening_hour) }}" class="form-control">

in Database, the opening_hour field is time type. value is 10:00:00


but when I try to show in time type input field it getting an error
array_key_exists(): The first argument should be either a string or an integer


What should I do in laravel blade?



My Answer:
You can achieve this by fetching the value from the database and then setting it as the default value for the time type input box. Here's an example code snippet to demonstrate this:

php
// Assuming you have already connected to your database

// Fetch the value from the database
$query = "SELECT time_column FROM your_table WHERE id = 1"; // Change the query according to your database structure
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$time_value = $row['time_column'];

// Display the time type input box with the fetched value as the default value
echo '';
?>


In this code snippet, we first fetch the value from the database using a SELECT query. Then, we store the fetched value in the `$time_value` variable. Finally, we display the time type input box with the fetched value set as the default value using the `value` attribute.

Make sure to replace `your_table`, `id`, `time_column`, and the database connection details with your actual values.

Rate this post

4 of 5 based on 8286 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us