|
Help...
I have a database of images on my web page and would like to have a swap function, such that when the user clicks on the image, a description will appeare in its place, from the database...this would be a big help...
|
|
|
What do you already know? Are you a complete beginner? Or do you already know how to connect to the database and read the values? Do you just need to know the DHTML/javascript side of this solution? Or the backend PHP/database methods as well?
I imagine a good solution would be to read from the database 1. The image (or path to the image) and 2. the description.
Then have your PHP loop through the recordset building 2 javascript arrays in the page output -- one array of images and one of descriptions.
echo "imgArray[".$rowCnt."] = \"".$imgFileName."\";";
echo "descArray[".$rowCnt."] = \"".$imgDescription."\";";
|
|
Then, when your PHP writes each <img> to the page, you include an id that uses the array index.
In each img tag, you include appropriate event handlers.
echo "<div id='imgDiv".$rowCnt."' onmouseover=\"ShowDescription (".$rowCnt.")\" onmouseout=\"ShowImage(".$rowCnt.")\"><img src='".$imgFileName."'></div>";
|
|
The line above inside your recordset loop would produce lines that look like this:
<div id='imgDiv1' onmouseover="ShowDescription(1)" onmouseout="ShowImage(1)"><img src='/forum/img/some_image.jpg'></div>
|
|
You said you wanted the description to swap with the image onclick, but would mouseover be better? It creates a more dynamic page--sometimes a page visitor will not know to click, but they will move the mouse around to see what happens. (My opinion of course.)
In your page output, you'd create a javascript section with functions to handle the swapping.
function ShowImage(idx) {
id = "imgDiv" + idx;
e = document.getElementById(id);
img = "<img src='" + imgArray(idx) + "'>";
e.innerHTML = img;
}
function ShowDescription(idx) {
id = "imgDiv" + idx;
e = document.getElementById(id);
e.innerHTML = descArray(idx);
}
|
|
I haven't tested this code, I just typed directly into the forum reply box. Bad thing is I usually average 2 errors per 1 line of code, so you can expect to have to clean this up!
|
|
|
|
|
Many thanx 4 getting back, yep am a complete novice...but really want to learn.
This i know is really basic code, but it is my first attempt...
<?php
$db = mysql_connect("localhost", "d00sn");
mysql_select_db("d00sn_products",$db);
$dbQuery="SELECT * FROM chefs_clothing order by chefs_clothing_id";
$result = mysql_query($dbQuery,$db);
?>
<!-- Product Image Title -->
<TR>
<?php
$count_id=0;
while (($chefs_clothing_Info=mysql_fetch_array($result))) {
if ($count_id>3) {
$count_id=0;
?>
</TR>
<TR>
<?php
}//if
$chefs_clothing_id=$chefs_clothing_Info["chefs_clothing_id"];
$name=$chefs_clothing_Info["name"];
$image=$chefs_clothing_Info["image"];
$description=$chefs_clothing_Info["description"];
$price=$chefs_clothing_Info["price"];
$euros=$chefs_clothing_Info["euros"];
echo " <TD class=text width=184 bgcolor=#FDC089 onClick=goto(http://kenbane.infc.ulst.ac.uk/~d00sn/)>
<HR WIDTH=30% ALIGN=CENTER COLOR=#FFFFCC><div align=center>
<FONT COLOR=#2F3161><STRONG>$name</STRONG></font>".
" <HR WIDTH=60% ALIGN=CENTER COLOR=#FFFFCC onClick=goto('http://kenbane.infc.ulst.ac.uk/~d00sn/)>
<div align=center>$image".
" <HR WIDTH=30% ALIGN=CENTER COLOR=#FFFFCC><div align=center>
<a href=index.php><FONT COLOR=#2F3161><STRONG><U>Click for Description</U></STRONG></A></font></div>".
" <HR WIDTH=45% ALIGN=CENTER COLOR=#FFFFCC><div align=center>
<FONT COLOR=#2F3161><STRONG>£ $price / € $euros</STRONG></font></div>
<a href=http://www.projectspool.com/convert_currency.php?currency_from=GBP¤cy_to=EUR&amount=$price&bgcolor=D3DDED&txtcolor=000000 target=_blank onclick=window.open(this.href, this.target, 'height=100,width=100,resizable=no,toolbar=no,scrollbars=no,statusbar=no,menubar=no,locationbar=no');
return false;>Currency Converter </a>".
" <HR WIDTH=60% ALIGN=CENTER COLOR=#FFFFCC><div align=center>".
" <HR WIDTH=90% ALIGN=CENTER COLOR=BLACK><div align=center></TD>";
$count_id++;
}//while
?>
I really appreciate ur help.....
|
|
|
vysvedčenie bolo ako za celý rok. Mládež mala ohromný výber možnostÃ. Začali pracovať náboženské združenia DEM (dorast evanjelickej mládeže ), SEM (združenie evanjelickej mládeže), SKM (spolok katolÃckej mládeže), kde sa trochu modlilo a počúvali náboženské prednášky, ale hlavne hodne hral ping-pong, volejbal, konali kultúrne programy, spoločenské hry a hodne tancovalo pri gramofóne. Veľmi rozÅ¡Ãrené boli čitateľské kluby Jaroslava Foglara pri časopise Vpřed s prÃlohou Rýchle Å¡Ãpy. Podobali sa skautu. Členovia lovili bobrÃkov odvahy(napr. o polnoci prejsť cez cintorÃn), mlčania (24 hod. mlčať), prvej pomoci( zdravotnÃctvo), zručnosti, Å¡portu atp. Naplno fungoval aj nekatolÃcky skaut, Sokol organizoval cvičenie na náradà a gymnastiku . Na sokolských ihriskách sa hrali volejbalové zápasy a pestovala atletika. Začal byť v móde tanec boogie-woogie, do nekonečna sa púšťali platne big-bandu Glena Millera, opakovane sa chodilo do kina na film Zasnežená romanca s krasokorčuliarkou Sonjou Henie, kde Millerova kapela hrala. Prvý raz sa žaslo nad hudbou G.Gershwina. Mládež sa naučila rehotať nad filmami s Laurelom a Hardym. Bežali westernové filmy. Nakladateľstvá o prekot vydávali preklady amerických a anglických autorov. Zásobovanie sa zlepÅ¡ilo, ale predsa eÅ¡te stále platil lÃstkový systém (každý občan dostal na mesiac plachty papiera s vytlačenými poukážkami na mlieko, maslo, múku, cukor, mäso, údeniny, textil, mydlo,
============================= reverse mortgage american family insurance columbus travel insurance orlando investment property
|
|
|
|
|
|
|
|