Skyphoxx Posted November 12, 2007 Share Posted November 12, 2007 Hello everyone, I have an HTML file with this piece of code: <img src='/phpfundthermo/thermo.php?max=3000¤t=1300'> What this code does is invoke the file thermo.php and sets variables "max" and "current", effectivley displaying a thermometer that is about 1/3 full. What I would like to know is, how can I build a form that will replace whatever current equals. Right now it equals 1300. I could use "find and replace" but what if I don't remember what the current variable currently equals? Is there a way that I can build a form that would search for that variable and replace it with what I type in the form? Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 12, 2007 Share Posted November 12, 2007 Ideally, you would be storing the current number in a database of some type. Then, you can simply update the database value and dynamically render all your img tags. I'm guessing, based on your question, though, that this is not how your site is set up? Quote Link to comment Share on other sites More sharing options...
Skyphoxx Posted November 12, 2007 Author Share Posted November 12, 2007 Correct, although I do have a couple databases set up, I don't have one for the php script in question. I found a script for a thermometer, and it works great, but the variables need to be typed in the referencing code on the html page it's displayed on. My client doesn't know html or php, so I want to make a form for them to update it without having to call me all the time. Quote Link to comment Share on other sites More sharing options...
gin Posted November 13, 2007 Share Posted November 13, 2007 <form method="post" action=""> <input type=hidden name=max value=3000> <input type=text name=current> <input type=submit name=submit value=submit> </form> Then at the top, before the thermometer is displayed (probably at the very very top of the page): if ($_POST['submit'] == 'submit') $current = $_POST['current']; This should bypass the need for the URL variables. Quote Link to comment Share on other sites More sharing options...
Skyphoxx Posted November 13, 2007 Author Share Posted November 13, 2007 I'm so sorry in Advance. I am somewhat of a PHP newB. I can read most of it and dismantle some, but the last post was a bit confusing. Attached is a zip of all the files in this problem. Could you take a look and tell me in detail how to use what was just posted? Thanks, and again sorry. If you don't want to download the zip, I'll try to do my best in describing how this currently works. Under my HTTPDOCS folder I have two folders. phpfundthermo (this is the processing script and images for the thermometer) and replace (this houses the html php file with the instance of the thermometer, and the file with the form to update it.) Contents of phpfundthermo folder: burst.jpg therm.jpg thermbar.jpg thermo.php <? error_reporting(7); // Only report errors Header("Content-Type: image/jpeg"); function code2utf($num){ //Returns the utf string corresponding to the unicode value //courtesy - romans@void.lv if($num<128)return chr($num); if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128); if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128). chr(($num&63)+128); return ''; } #$font = "/usr/local/fonts/ttf/arial.ttf"; $font = "c:/windows/fonts/georgia.ttf"; $unit = ($HTTP_GET_VARS['unit']) ? $HTTP_GET_VARS['unit'] : 36; // ascii 36 = $ $t_unit = ($unit == 'none') ? '' : code2utf($unit); $t_max = ($HTTP_GET_VARS['max']) ? $HTTP_GET_VARS['max'] : 0; $t_current = isset($HTTP_GET_VARS['current']) ? $HTTP_GET_VARS['current'] : 0; $finalimagewidth = max(strlen($t_max),strlen($t_current))*25; $finalimage = imagecreateTrueColor(60+$finalimagewidth,405); $white = imagecolorallocate ($finalimage, 255, 255, 255); $black = imagecolorallocate ($finalimage, 0, 0, 0); $red = imagecolorallocate ($finalimage, 255, 0, 0); imagefill($finalimage,0,0,$white); ImageAlphaBlending($finalimage, true); $thermImage = imagecreatefromjpeg("therm.jpg"); $tix = ImageSX($thermImage); $tiy = ImageSY($thermImage); ImageCopy($finalimage,$thermImage,0,0,0,0,$tix,$tiy); /* thermbar pic courtesy http://www.rosiehardman.com/ */ $thermbarImage = ImageCreateFromjpeg('thermbar.jpg'); $barW = ImageSX($thermbarImage); $barH = ImageSY($thermbarImage); $xpos = 5; $ypos = 327; $ydelta = 15; $fsize = 12; // Set number of $ybars to use, calculated as a factor of current / max. if ($t_current > $t_max) { $ybars = 25; } elseif ($t_current > 0) { $ybars = $t_max ? round(20 * ($t_current / $t_max)) : 0; } // Draw each ybar (filled red bar) in successive shifts of $ydelta. while ($ybars--) { ImageCopy($finalimage, $thermbarImage, $xpos, $ypos, 0, 0, $barW, $barH); $ypos = $ypos - $ydelta; } if ($t_current == $t_max) { ImageCopy($finalimage, $thermbarImage, $xpos, $ypos, 0, 0, $barW, $barH); $ypos -= $ydelta; } // If there's a truetype font available, use it if ($font && (file_exists($font))) { imagettftext ($finalimage, $fsize, 0, 60, 355, $black, $font,$t_unit."0"); // Write the Zero imagettftext ($finalimage, $fsize, 0, 60, 10+(2*$fsize), $black, $font, $t_unit."$t_max"); // Write the max if ($t_current > $t_max) { imagettftext ($finalimage, $fsize+1, 0, 60, $fsize, $black, $font, $t_unit."$t_current!!"); // Current > Max } elseif($t_current != 0) { if ($t_current == $t_max) { imagettftext ($finalimage, $fsize, 0, 60, 10+(2*$fsize), $red, $font, $t_unit."$t_max!"); // Current = Max } else { if (round($t_current/$t_max) == 1) { $ypos += 2*$fsize; } imagettftext ($finalimage, $fsize, 0, 60, ($t_current > 0) ? ($ypos+$fsize) : ($ypos+(4*$fsize)), ($t_current > 0) ? $black : $red, $font, $t_unit."$t_current"); // Current < Max } } } if ($t_current > $t_max) { $burstImg = ImageCreateFromjpeg('burst.jpg'); $burstW = ImageSX($burstImg); $burstH = ImageSY($burstImg); ImageCopy($finalimage, $burstImg, 0,0,0,0,$burstW, $burstH); } Imagejpeg($finalimage); Imagedestroy($finalimage); Imagedestroy($thermImage); Imagedestroy($thermbarImage); ?> Contents of replace folder: thermo_instance.php (Currently CHMODDED to 777) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?PHP if ($_POST['submit'] == 'submit') $current = $_POST['current']; ?> <img src='/phpfundthermo/thermo.php?max=3000¤t=1300'> </body> </html> update_thermo_instance.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Replace and Find Script</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p> </p> <form method="post" action="http://www.teamexterran.com/replace/thermo_instance.php"> <input type=hidden name=max value=3000> <input type=text name=current> <input type=submit name=submit value=submit> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.