|
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
|
|
|
|
|
|
|
|