It is necessary to extract the value from the database (phpMyAdmin) and make one of them checked
- Open a picture in a new tab, if not displayed - As Lan
- If absolutely any, then when outputting in a loop, you can add a condition: if the loop variable = 0, then add checked - Vadim Prokopchuk
- Please use the key combination Ctrl + G to add a picture to the question - Mikhail Vaysman
|
1 answer
First we create a connection to the database:
<? $link = mysqli_connect('хост', 'пользователь', 'пароль', 'имя бд'); if(mysqli_connect_errno()) { echo 'Ошибка подключения к БД ('.mysqli_connect_errno().'): '.mysqli_connect_error(); exit(); } ?> Creating a function that, when called, pulls out a value of type:
function getPosts() { global $link; $sql = "SELECT * FROM `таблица твоя` ORDER BY id DESC LIMIT 0, 21"; $result = mysqli_query($link, $sql); $posts = mysqli_fetch_all ($result, 1) ; return $posts; } Now we call it and create a loop:
<?$posts = getPosts();?> <? foreach($posts as $post): ?> Картинка: <?=$post['image']?> Время: <?=$post['time']?> И тд At the end of the cycle: <? endforeach; ?> <? endforeach; ?> <? endforeach; ?> This is how you pull out any values from the database. You just need to think about how to get the checked value.
- why session_start (); ??? - L. Vadim
- Yes, this is a line of my code just :) did not notice, I will correct it - Anatoly
|