Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 15 su 15

Discussione: Immagini, PHP e MySQL

  1. #11
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    33
    Un micro progresso è stato fatto. Ora riesco a visualizzare in random una foto, ma a me ne servono due affiancate. Posto il codice.

    @include 'config.php';
    $sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat='Paesaggi,Ritratti,Macro' ORDER BY RAND() limit 2";
    $result = @mysql_query($sql) or die(mysql_error ());
    $row = @mysql_fetch_array($result);
    $id_img = $row['foto_id'];
    $type = $row['foto_type'];
    $img = $row['foto'];
    if (!$id_img)
    {
    echo "Id sconosciuto";
    }else{
    @header ("Content-type: ".$type);
    echo $img;
    echo $img;
    }

  2. #12
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    33
    Ho provato a fare così, ma non mi stampa a video la seconda immagine. La query funziona perché se la provo in phpmyadmin mi restituisce due risultati. Come faccio a stampare le due immagini a video?
    <?
    @include 'config.php';
    $sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat='Paesaggi,Ritratti,Macro' ORDER BY RAND() limit 2";
    $result = @mysql_query($sql) or die(mysql_error ());
    $row = @mysql_fetch_array($result);
    $id_img = $row['foto_id'];
    $type = $row['foto_type'];
    $img = $row['foto'];
    if (!$id_img)
    {
    echo "Id sconosciuto";
    }else{
    @header ("Content-type: ".$type);
    echo $img;
    echo $img;
    }
    ?>

  3. #13
    Utente di HTML.it L'avatar di m4rko80
    Registrato dal
    Aug 2008
    residenza
    Milano
    Messaggi
    2,655
    <?
    @include 'config.php';
    $sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat='Paesaggi,Ritratti,Macro' ORDER BY RAND() limit 2";
    $result = @mysql_query($sql) or die(mysql_error ());

    while($row = @mysql_fetch_array($result)){
    $id_img = $row['foto_id'];
    $type = $row['foto_type'];
    $img = $row['foto'];
    if (!$id_img)
    {
    echo "Id sconosciuto";
    }else{
    @header ("Content-type: ".$type);
    echo $img;
    echo $img;
    }
    }


    ?> devi ciclare l'array

  4. #14
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    33
    Ciao, sai che c'ero arrivato! Però non funziona, sempre e solo un'immagine. Ho pensato: può essere che le immagine siano sovrapposte? Ho provato a inserire ritorni fra i due echo, ma niente. Altre idee?

  5. #15
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    33
    Ancora visualizza una sola immagine, ma nel frattempo ho provato ad inserire la scelta randomizzata della categoria. Mi da il seguente errore Parse error: syntax error, unexpected ',' in /opt/lampp/htdocs/sito/visualizza3.php on line 3. Posto il codice:<?
    @include 'config.php';
    $catList = ('Paesaggi', 'Ritratti');
    $i = rand(0,2);
    $catSel = $catList[$i];
    $sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat = ".$catSel." ORDER BY RAND() limit 2";
    $result = @mysql_query($sql) or die(mysql_error ());
    while($row = @mysql_fetch_array($result)){
    $id_img = $row['foto_id'];
    $type = $row['foto_type'];
    $img = $row['foto'];
    if (!$id_img)
    {
    echo "Id sconosciuto";
    }else{
    @header ("Content-type: ".$type);
    echo $img;
    echo $img;
    }
    }
    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.