Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Saiman70

Technical User
Mar 5, 2009
10
IT
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=" </a>
<a href=" sono </a>
<a href=" </a>
<a href=" </a>
<a href=" </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
 
You are mixing Javascript with PHP, so its hard to say exactly, but normally:

echo $row[1];

would be enough to get the description to display.

However since you are generating a javascript array for the image paths, you'd need to generate a description array for the descriptions also, and call that sing javascript in the same way you call the image.


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

And then in your js function you'd need to cal the appropriate description.

Code:
...
backBtn = document.getElementById('back2'),
n = photos.length-1;
if (dir == "next") {
which = (which < n) ? which + 1 : which;
image.src = photos[which];
[red]document.write(descriptions[which]);[/red]
backBtn.style.display = "inline";
if (which == n) {
fwdBtn.style.display = "none";

That's the general idea, though you'll likely have to play around with the document.write to get it to display where you want to.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thinking a bit more about it, perhaps instead of using document.write, you can change the innerHTML property of an object that is near the image to display the description.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi

I thank you very much for your help. It works
The only thing to fix is that thefirst pic, (out of the description counter) miss the description,. I have to fix that

thanks !! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top