1

Из бд нужно вытащить id, для $_GET запроса, чтобы показывать нужное изображение. Сам запрос получается пустым, не знаю как справить.

$handle = opendir('./img');     //Читаем файлы из папки /img/
while ($check = readdir($handle)) { 
    global $bd;
    $id_query = "SELECT id FROM images";
    $img_id = mysqli_query($id_query, $bd);
    echo $img_id;
    if ($check == '.' || $check == '..') continue;  
    makeThumbnail('img/'.$check,'testdir/'.$check,200,200);
    if (isset($_GET['img']) && $_GET['img'] == $img_id ) {      
?>
    <a href="/">
        <img src="img/<?=$check?>">
    </a>
<?php } else { ?>
    <a href="/?img=<?=$img_id?>">
        <img src="testdir/<?=$check?>">
    </a>
<?php
}



}
closedir($handle);

При выводе $img_id

Warning: mysqli_query() expects parameter 1 to be mysqli, string given

В чем ошибка?

1 ответ 1

1

Потому что вы перепутали параметры местами, должно быть:

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

В вашем случае:

$img_id = mysqli_query($bd, $id_query);
5
  • По началу я также подумал, но перепроверил в мануале + на практике выдало Catchable fatal error: Object of class mysqli_result could not be converted to string
    – Lolik123
    31 янв 2016 в 18:51
  • @Lolik123 надо не думать, а читать документацию. 31 янв 2016 в 18:57
  • 1
    Catchable fatal error: Object of class mysqli_result could not be converted to string, все правильно т.к. $img_id это mysqli_result . $img_id = mysqli_query($bd, $id_query); var_dump($img_id->fetch_array());
    – Yuriy
    31 янв 2016 в 19:02
  • array(2) { [0]=> string(2) "33" ["id"]=> string(2) "33" }
    – Lolik123
    31 янв 2016 в 19:06
  • 1
    $img_id = mysqli_query($bd, $id_query); $img_id = $img_id->fetch_array(); $img_id = $img_id['id'];
    – Yuriy
    31 янв 2016 в 20:03

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.