query issue : print the second field of a my sql table

Discussion in 'PHP' started by divbox, Apr 8, 2009.

  1. #1
    Hello.
    I got this
    $sql = "SELECT * FROM notturna ORDER BY descrizione";
    $result = mysql_query ($sql);

    while ($row = mysql_fetch_row($result))
    {

    if ( $item == 0 ) { $_primafoto = $row[0]; }
    echo "photos[".$item."]=\"notturna/".$row[0].".jpg\";";


    $item=$item+1;
    }

    }
    ?>

    function arrow()
    {

    document.getElementById( "back2" ).style.display = "none";

    }

    function changePic(dir) {
    var image = document.images.photoslider,
    fwdBtn = document.getElementById('forward2'),
    backBtn = document.getElementById('back2'),
    n = photos.length-1;
    if (dir == "next") {
    which = (which < n) ? which + 1 : which;
    image.src = photos[which];
    backBtn.style.display = "inline";
    if (which == n) {
    fwdBtn.style.display = "none";
    }
    } else if (dir == "back") {
    which = (which > 0) ? which - 1 : which;
    image.src = photos[which];
    fwdBtn.style.display = "inline";
    if (which === 0) {
    backBtn.style.display = "none";
    }

    }
    return false;
    }


    </script>

    </head>

    <body OnLoad="arrow()">

    <div class="container2">
    <div id="logo" > <img title="logo" src="logo2.jpg"></div>

    <div class="menu">


    <a href="http://paolobergomifoto.altervista.org">Home </a>
    <a href="http://paolobergomifoto.altervista.org">Chi sono </a>
    <a href="http://paolobergomifoto.altervista.org/gallerie.html">Gallerie </a>
    <a href="http://paolobergomifoto.altervista.org/contatti.html">Contatti </a>
    <a href="http://paolobergomifoto.altervista.org">Credits </a>

    </div>

    <div id="backnotturna">

    <a href="#" onclick="return changePic('back');">
    <img id="back2" style="border:0px" src="indietro.jpg"></a>
    </div>
    <div class="centro">
    <div class="gruppofoto2"><a href="gallerymacro.php">Macro</a><a href="gallerypaesaggi.php">Paesaggi</a><a href="galleryritratti.php">Ritratti</a><a href="gallerybn.php">B&N</a><a href="gallerynotturna.php">Notturna</a><a href="galleryvarie.php">Varie</a><img src="notturna/<?php echo $_primafoto; ?>" name="photoslider">

    </div>
    </div>
    <div id="forward"><a href="#" onclick="return changePic('next');"> <img id="forward2" style="border:0px" src="avanti.jpg"></a>
    </div>
    <div class="inizio"><a href="#" onclick="which=1; changePic('back');return false" >Torna all'inizio della gallery</a>
    </div>
    <div id="footer">Created by Paolo Bergomi</div>
    </div>



    The table in db has also a second field that in the query is represented by the variable $row[1] . this is the description of the pictures.
    I have an issue cause i don't know how to do to show the content of this field using the query above.
    The pictures is correctrly showed in the gallery, and my target is to add the relative description.(as i wrote, is the second field in the table)
    any idea ?

    cheers
    paolo :)
     
    divbox, Apr 8, 2009 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Why is all the image descriptions on the second row of your database table instead of in a field on the same record as the images? Perhaps you could do a MySQL export of your table into SQL format and paste it in here so we can see the structure of your table. This would help someone be able to solve your problem of displaying the descriptions next to your images. Without this I would only be able to make a stab in the dark at what the solution might be.
     
    Weirfire, Apr 8, 2009 IP
  3. divbox

    divbox Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello Weirfeire

    thanks for your reply. I got a soluition here, i built an array for the description.
    here it is:

    In Js:

    var text=new Array()
    function arrow()
    {
    
    document.getElementById( "back2" ).style.display = "none";
    
    }
    
    function changePic(dir) {
      var testo = document.getElementById( 'testo' );
        var image = document.images.photoslider,
            fwdBtn = document.getElementById('forward2'),
            backBtn = document.getElementById('back2'),
            n = photos.length-1;
          
        if (dir == "next") {
            which = (which < n) ? which + 1 : which;
            image.src = photos[which];
              testo.innerHTML = text[ which ];
            backBtn.style.display = "inline";
            if (which == n) {
                fwdBtn.style.display = "none";
            }
         
        } else if (dir == "back") {
            which = (which > 0) ? which - 1 : which;
            image.src = photos[which];
              testo.innerHTML = text[ which ];
            fwdBtn.style.display = "inline";
            if (which === 0) {
                backBtn.style.display = "none";
            }
            
        }
        return false;
    }
    PHP:


    In php:
    echo "text[".$item."]=\"".$row[1]."\";";
    PHP:
    i html

    <div id='testo'></div>
    PHP:

    it all works

    :)
     
    divbox, Apr 9, 2009 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Glad you got a solution mate :)
     
    Weirfire, Apr 9, 2009 IP
  5. divbox

    divbox Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes;)
    thx
    The only issue I got now is to print thedescription of the first image load in default ($primafoto)

    bye
     
    divbox, Apr 9, 2009 IP