codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  PHP swapping images  wysn at 14:47 on Monday, March 01, 2004
 

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

  Re: PHP swapping images  Troy Wolf at 18:09 on Monday, March 01, 2004
 

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!

Troy Wolf: site expert
SnippetEdit Website Editor


  Re: PHP swapping images  wysn at 21:31 on Monday, March 01, 2004
 

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&currency_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.....

  Re: PHP swapping images  brian500 at 10:08 on Thursday, March 25, 2010
 

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









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: How to run ASP code on server automatically wrt date & time
•  Re: Running ASP Program From Visual Basic Form
•  Re: PHP swapping images
•  Re: dereferenceing a string to a constant name
•  DB2 Query Problem
•  Re: How to make href enabled and disabled???
•  Re: where can i download javax.speech package
•  Re: Can javascript preload swf files?
•  Re: Can javascript preload swf files?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010