PHP - Changing Image
Any chance you could help me out with some probably simple code ? I need to change an image when the script change state. So instead of $Streamstatus "off"or "on" I would like to change an image. Cheers
Code: [Select] <?php $request = 'http://api.own3d.tv/liveCheck.php?live_id='; $arg = 'Zerkilive'; $session = curl_init($request.$arg); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); if (preg_match("/true/",$response, $result)) { $streamStatus="on"; $color="green"; } else { $streamStatus="off"; $color="red"; } echo $streamStatus; ?> Similar TutorialsHi! I am currently making a really simple photo blog. The query fetches every reference to the images which are stored on the server. I have a problem when it comes to dynamically cycling through these though. After running the query, I store each image reference in a twodimensional array like this: [["id"], ["date"], ["title"], ["filename"]] (an Array of Arrays). The image displays just fine by doing this: $pointer; //starting from the last element (image) in the array <img src="images/gallery/<?php echo $images[3][$pointer] ?>" alt="<?php echo $images[2][$pointer] ?>"> The problem is that, when I update the pointer, say for instance pointer++, the current image on the screen doesnt update. I know for a fact that the pointer updates, because I have echoed it. The basic idea is to have a previous and next link just under the image, so that the viewer can cycle the available images. Any help is greatly appreciated Please keep in mind, im a newbi at php as well as these forums, and I just started using it this week. I have some background in C programing and know a little VB. I am currently trying to make a php based webpage that has 5 different images on it. I want each image to change with respect to what is written in a text file within the server space. So to better explain this, I have a text file that is named "status.txt". status.txt contents: active inactive active active active I want the first image to change to a different image if I change the first line of the text file to be inactive instead of active and the 2nd image to change if I change the 2nd line (inactive) to active and so forth on all the other images. I do know that i need to open the file, then read the file with fopen and fread and set what the contents that i read from the file equal to some variable (still not 100% sure im using the functions right). but im not sure how to set up the code so the image will change with respect to what is read from the text aka what the variable is equal too. I thought it would be a simple if statement but it seems more complicated then that. and futhermore, im not sure where to place the open file, should i do this in the header? so every time website refreshes, is opens the file and reads the txt file and changes with respect to that? Any help would be great! Thank you in advance. Hi
I'm trying to change an image when a certain link is clicked. The image is a logo of a company and the links that will be clicked is english, arabic, and Chinese.
So if someone clicks on Chinese then the logo changes to the Chinese version of the normal logo.
Here is my html
<?php $langArabic=''; $langChinese=''; $langSpanish=''; $langEng=''; $linkArabic=getSEOLink($page_id); $linkChinese=getSEOLink($page_id); $linkSpanish=getSEOLink($page_id); $linkEng=getSEOLink($page_id); $queryLink = mysql_query("SELECT * FROM $_SEO_TABLE WHERE `id_page`='".$page_id."'"); if(mysql_num_rows($queryLink) > 0){ $resultLink = mysql_fetch_object($queryLink); if($resultLink->url != ''){ $linkEng = $_HTTP_ADDRESS."".$resultLink->url; if($page_id == 1 || $page_id == '1'){ $linkEng = $_HTTP_ADDRESS; } } if($resultLink->url_arabic != ''){ $linkArabic = $_HTTP_ADDRESS."".$resultLink->url_arabic; } if($resultLink->url_chinese != ''){ $linkChinese = $_HTTP_ADDRESS."".$resultLink->url_chinese; } if($resultLink->url_spanish != ''){ $linkSpanish = $_HTTP_ADDRESS."".$resultLink->url_spanish; } } switch (urlExtension()) { case 'html': $langClass = ''; $langEng='langActive'; $langTag='en'; break; case 'ar': if($page->title_arabic == ''){ $langClass = '_arabic'; }else{ $langClass = '_arabic'; } $langArabic='langActive'; $langTag='ar'; break; case 'es': $langClass = ''; $langSpanish='langActive'; $langTag='es'; break; case 'cn': $langClass = ''; $langChinese='langActive'; $langTag='cn'; break; default: $langClass = ''; $langEng='langActive'; $langTag='en'; } ?> <a class="main-logo<?php echo $langClass;?>" href="javascript:void(0);"><img src="<?php echo $_HTTP_ADDRESS;?>images/logo-letters.png" /></a> <div class="language-selection-wrapper<?php echo $langClass;?> overlay-bg<?php echo $langClass;?> border-bottom-white<?php echo $langClass;?> padding-level-one<?php echo $langClass;?>"> <div class="language-inner-wrapper<?php echo $langClass;?>"> <a class="<?php echo $langEng;?>" href="<?php echo $linkEng;?>">English</a><span>|</span> <a class="<?php echo $langArabic;?>" href="<?php echo $linkArabic;?>">العربيّة</a><span>|</span> <a class="<?php echo $langSpanish;?>" href="<?php echo $linkSpanish;?>">Español</a><span>|</span> <a class="<?php echo $langChinese;?>" href="<?php echo $linkChinese;?>">中文</a> <div class="clearboth"></div> </div> Hi, I am changing my ISP and need to import my databases.
Do I I have to create a new datarbase or can I change my database name to import?
My new host has a different database prefix ie: -web147xxxxxxxx
My old one was arewene1_wor1.
Many thanks.
As I am VERY new to PDO, can someone help me in converting the below 2 codes so that I can setup the testing site knowing at least this part works. Below is the old SQL that I need to convert but don't have to foggiest on where to start. If I can get some help with this I can slowly work through the rest of my site with a bit more ease. LOGIN CODE: <?php if($_POST['submit']){ $Username = protect($_POST['Username']); $Password = protect(sha1($_POST['Password'])); if(!$Username || !$Password){ echo "<center>Please enter your <b>Username</b> and <b>Password</b>!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Username</b> or <b>Password</b> you supplied is incorrect!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."' AND Password = '".$Password."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Password</b> you supplied is incorrect!</center>"; }else{ $row = mysql_fetch_assoc($res); if($row['Active'] != 1){ echo "<center>Your login has been <b>deactivated</b>, Please contact your Manager for assistance.</center>"; }else{ header('Location: secure.php'); $time = date('U')+7200; //2 Hours mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); $_SESSION['uid'] = $row['id']; }}}}} ?> ACCESS GRANTED (Each Page): <?php if(strcmp($_SESSION['uid'],"") == 0){ printf("<script>location.href='index.php'</script>"); }else{ $time = date('U')+7200; //2 Hours $update = mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); } ?>
Salting passwords... How can you update the salting without getting all the users to change their password? Is the salting set in stone once created? Hi, I have a second website under the same domain www.lucyeleanorbrown.com/weddings.html which I wanted to change to www.weddings.lucyeleanorbrown.com, I have been looking around for PHP for this but am unsure of what to search for, could anyone give me a suggestion? Thank you Hi guys, i have a system and was asked to develop the site with the current system. These are sometimes a pain but it is an old system and i'm trying to change the url's which is seems to be hard to do with this kind of code. set_time_limit(60); include 'includes/config.php'; include 'includes/logfile.php'; include 'includes/databasefile.php'; include 'includes/templatefile.php'; $log = new cLog; $db = new cDatabase; //first run ssl check if necessary if ($_SERVER['SERVER_PORT'] == "80" && $sslredirect == 1) { header ("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?" . $_SERVER['QUERY_STRING']); exit(0); } //first, determine page requested list ($junk, $request) = split ("\?/", $_SERVER['REQUEST_URI']); list ($uri, $data) = split ("!", $request); $uriarray = split ("/", $uri); //check for login/logout request list ($junk, $request) = split ("\?", $_SERVER['REQUEST_URI']); if ($request == 'login') { header ("Location: login.php"); exit(0); } else if ($request == 'logout') { header ("Location: logout.php"); exit(0); } if ($data != "") { //parse internal variables $dataarray = split ("&", $data); foreach ($dataarray as $line) { list ($cmd, $val) = split ("=", $line); $arr_cmds[$cmd] = urldecode ($val); } } $pagename = $db->escape($uriarray[count($uriarray)-2]); $sectionname = $db->escape($uriarray[count($uriarray)-3]); if ($pagename == "") { $pagename = "home"; } if ($sectionname == "") { $sectionname = "home"; } $urlpagename = $pagename; $urlsectionname1 = $sectionname; $urlsectionname2 = $db->escape($uriarray[count($uriarray)-4]); //handle any commands, then redirect back to page $cmd = $_REQUEST['cmd']; if ($cmd == "-displayelement") { $elementid = $db->escape($_REQUEST['elementid']); if ($_REQUEST['surpresshtml'] == "") { echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'></head>\n"; } if ($_REQUEST['global'] == "1") { $query = $db->query("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); } else { $query = $db->query("select ComponentName, Data from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //find matching component and launch display function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) { include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'display'), $data); break; } } if ($_REQUEST['surpresshtml'] == "") { echo "</body></html>\n"; } exit (0); } else if ($cmd == '-editelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); $pageid = $r['PageID']; //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); if ($adminflag != "1") { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid')"); } echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } else if ($cmd == '-editglobalelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { echo "Security - Out of bounds"; exit(0); } $query = $db->query ("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); $query = $db->query("update table_globalelements set Data = '$data' where (ElementID = '$elementid')"); echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } //lookup page details $query = $db->query("select p.PageID, p.PageTitle, p.SectionID, p.TemplateID, p.UserID, p.LastUpdate, p.SectionName, s.SectionTitle, s.GroupID, s.Protected, p.Keywords, p.PageName from table_pages as p left join table_sections as s on s.SectionName = p.SectionName where (p.PageName = '$pagename' and s.SectionName = '$sectionname') limit 1"); if (!$pagedetails = $db->fetch_array($query)) { echo "404"; exit(0); } //check for privileges section if ($pagedetails[8] != "" && $pagedetails[8] != "0") { $sectionname = stripslashes($pagedetails[6]); if (!isset($_SESSION['Username']) && !isset($_REQUEST['Username'])) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } else { $username = $db->escape ($_REQUEST['Username']); $password = $db->escape ($_REQUEST['Password']); if ($username == "") { $username = $db->escape ($_SESSION['Username']); } if ($password == "") { $password = $db->escape ($_SESSION['Password']); } $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } if ($_SESSION['GroupID'] != $pagedetails[8]) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } } else { //check login details if user appears to be already logged in if (isset($_SESSION['Username'])) { $username = $db->escape ($_SESSION['Username']); $password = $db->escape ($_SESSION['Password']); $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } } //load template $tplate = new cTemplate($pagedetails['TemplateID'], $pagedetails['PageID']); $tplate->loadtemplate(); //add logout button if (isset($_SESSION['UserID'])) { echo "<div align='center'><small><a href='index.php?logout'>logout</a></small></div>\n"; } //log request if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $log->writelog("/$sectionname/$pagename", "Access"); In the includes/templatefile.php file the code is like: function parsetemplate($templatefile) { global $db, $pageid, $pagedetails, $fullbaseurl, $adminemail; //first, find internal metacodes $pagetitle = stripslashes($pagedetails[1]); $lastupdate = date('l dS \of F Y h:i:s A', $pagedetails[5]); $sectiontitle = stripslashes($pagedetails[7]); $sectionname = stripslashes($pagedetails[6]); $templatefile = str_replace ("!PAGETITLE!", $pagetitle, $templatefile); $templatefile = str_replace ("!ADMINEMAIL!", $adminemail, $templatefile); $templatefile = str_replace ("!REQUEST_DOCUMENTID!", $_REQUEST['DocumentID'], $templatefile); $templatefile = str_replace ("!SECTIONTITLE!", $sectiontitle, $templatefile); $templatefile = str_replace ("!LASTUPDATE!", $lastupdate, $templatefile); $templatefile = str_replace ("!URL!", $_SERVER['REQUEST_URI'], $templatefile); $templatefile = str_replace ("!FULLBASEURL!", $fullbaseurl, $templatefile); $templatefile = str_replace ("!KEYWORDS!", $pagedetails[10], $templatefile); if ($_SESSION['UserID'] != "") { $templatefile = str_replace ("!LOGINDETAILS!", "- You are logged in as " . $_SESSION['Username'], $templatefile); } else { $templatefile = str_replace ("!LOGINDETAILS!", "", $templatefile); } $templatefile = str_replace ("!SECTIONLINK!", $fullbaseurl . "?/" . $sectionname . "/Home/", $templatefile); What i am getting via the links a Code: [Select] http://www.mydomain.com/?/Shop/Home/ How do i get rid of the "?" mark and the "/Home/". The /Home/ is also stored in the Database. I have tried a number of solutions by getting rid of the "?" and "/Home/" but i get the 404 error as the code shows. Can you please help with this? okay i need help with this part of code i need to set time 00:00 to 24:00 Code: [Select] $vrijeme_otvoreno = "$rv_od_h:$rv_od_min"; $vrijeme_zatvoreno = "$rv_do_h:$rv_do_min"; if ($vrijeme_otvoreno =="00:00" && $vrijeme_zatvoreno == "00:00") { $vrijme_zatvoreno = "24:00"; echo $vrijeme_zatvoreno; } echo "$vrijeme_otvoreno - $vrijeme_zatvoreno <br>"; i get echo 00:00 - 00:00 and i need it to be 00:00 - 24:00 Hi, I'm using the following code: <td>$row[color]</td> and the possible values for this field are 1, 2 and 3. But I want the return to be red for 1, blue for 2, and green for 3. How do I write it so that instead of getting a row of 1's, 2's and 3's, I change those numbers to their corresponding colors? Thanks! Hey folks, I have made a cart. My output of the cart ( when I receive a mail of the order ) is like this "3,2,4,2" ,, the numbers are the id's of the items, but instread of the id's of the items, I would like to have the names of the items as an output in mail.php, column in sql table is also 'name' what should I do ?? the cart http://fhcs.be/cart-demo4/ thanks in advance index.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session require_once('mail.php'); session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Welkom, plaats uw order</h1> </div> <div id="booklist"> <h1>Warme dranken</h1> <?php $sql = 'SELECT * FROM products WHERE cat=2'; $result1 = $db->query($sql); $output1[] = '<ul>'; while ($row = $result1->fetch()) { $output1[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output1[] = '</ul>'; echo join('',$output1); ?> <h1>Cocktails</h1> <?php $sql = 'SELECT * FROM products WHERE cat=3'; $result2 = $db->query($sql); $output2[] = '<ul>'; while ($row = $result2->fetch()) { $output2[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output2[] = '</ul>'; echo join('',$output2); ?> </div> </body> </html> mail.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); session_start(); if($_POST['sendemail'] == 'Email') { $info =($_POST['cart']); $headers = 'From: Sender <from@fhcs.be>'; mail('to@fhcs.be', 'Subject', $info, $headers); echo $_POST["cart"]; echo 'Your mail has been sent'; } else { echo 'Your mail was not sent'; } ?> cart.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$name.'</td>'; $output[] = '<td>€'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>€'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> functions.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$name.'</td>'; $output[] = '<td>€'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>€'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Hi Guys, I have a list of branches in a database table with the following collumns, Ter BranchName BranchAddress BranchTel BranchEmail BranchLink Ter = Terriotory ID However every time i update a branch using the edit.php code it always sets the Ter as 1 again! Rather than leaving it the same. The actual field is read-only to prevent that from happening. It then always comes up with the error Duplicate entry '1' for key 1 but thats because there is already a branch with Ter=1 include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql = "UPDATE `ter` SET `Ter` = `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); <form action='' method='POST'> <p><b>Territory:</b><br /><input name='Ter' type='text' value='<?= stripslashes($row['Ter']) ?>' size="3" readonly="readonly" /> <p><b>Branch Name:</b><br /><input name='BranchName' type='text' value='<?= stripslashes($row['BranchName']) ?>' size="50" /> <p><b>Address:</b><br /> <textarea name="BranchAddress" cols="40" rows="5"><?= stripslashes($row['BranchAddress']) ?></textarea> <p><b>Telephone:</b><br /><input name='BranchTel' type='text' value='<?= stripslashes($row['BranchTel']) ?>' size="15" /> <p><b>Email:</b><br /><input name='BranchEmail' type='text' value='<?= stripslashes($row['BranchEmail']) ?>' size="50" /> <p><b>Link:</b><br /><input name='BranchLink' type='text' value='<?= stripslashes($row['BranchLink']) ?>' size="50" /> <p><input type='submit' value='Save' /><input type='hidden' value='1' name='submitted' /> </form> <? } ?> Any Ideas? Cheers, S Hi all I have a string called $voucher_code which is a value used to deduct or add value to a shopping cart. If the value is a minus I need it to show the minus sign, or if it's a plus value, it needs to show a plus sign. Here's my code: <strong>£ -".number_format(($voucher_code),2)."</strong> How do I modify the above code to show + instead of -- which it does at the moment? Many thanks for your help Pete // SESSION TEST if ($_SESSION['username']) { require_once("../mysql.php"); // Find Username from Session ID // Find Username from ID $finduser="SELECT username FROM users WHERE id='$_SESSION[username];'"; $finduserquery=mysql_query($finduser)or die(mysql_error()); $userfetch = mysql_fetch_array($finduserquery); // Set Username Variable $userfromid = $userfetch['username']; echo "lol" . ucwords($userfromid); } else { } Everytime I load this page more than once when logged in, it seems to turn the variable blank. Therefore making the user not be able to view other pages that use a session. Help? Thanks Hi, I've got the follow array: Query: Code: [Select] SELECT concat(monthname(gl_date),", ",year(gl_date)) as "monthYear", concat(DATE_FORMAT(gl_date,"%d-%m-%Y"),", ",gl_venue) as "dateVenue", DATE_FORMAT(gl_date,"%d-%m-%Y")as "date", gl_venue as "venue", gl_city as "city", gl_postcode as "postcode", gl_text as "description", concat(DAYOFMONTH(gl_date), MONTHNAME(gl_date),".png") AS "imageName" FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date Array: Code: [Select] $array = array(); $array['gigs'] = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $array['gigs'][] =$row; } $output = json_encode($array); This returns JSON like this: - Code: [Select] { "gigs": [ { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, { "monthYear": "May, 2011", "dateVenue": "19-05-2011, O'Neill's", "date": "19-05-2011", "venue": "O'Neill's", "city": "Peterborough", "postcode": "PE1 1SQ", "description": "This one is another outing for Jason and Darren's acoustic duo, the pair will be playing a selection of their favourite songs as well as some tunes from the guards set.<br \/>\r\n<br \/>\r\n19:00 to 21:00", "imageName": "19May.png" }, {.......next record I'd like the data to be arranged by the 'monthYear' field....something like this... Code: [Select] { "gigs": [ "monthYear": "May, 2011" { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, {......all gigs for 'May, 2011' } "monthYear": "June, 2011" {....records for 'June, 2011' so 'gigs'=>'monthYear'=>'other records' I've tried all sorts of combinations of putting the '$row['monthYear']' field in different places in the array, but I seem to loose data by doing so for some reason. any input greatly appreciated. Darren Hi, I'm having a problem with a hidden input value not changing on the browser after a request. I can change the value and alert or console log the new value but it won't change the DOM. Here's the section I'm having problems with:
xhr.onload = function() { if (xhr.status === 200) { var data = JSON.parse(this.responseText); $(".token").attr('value', data.token); alert($(".token").val()); } else { console.log('Something went terribly wrong...'); } }; Edited by Millertime1, 16 August 2014 - 03:34 PM. hello guys i have a project with Georgian calendar but when i contact to the developer they tell me we not support any other calendar so you must do this alone or get help from local developer. as manager i need to have basic knowledge from what is under my control. so please guide me to how change Georgian to Persian (jalali) calendar. i done translating from en to per but the most problem is the calendar. project address: https://drive.google.com/open?id=1eKestInuUiUJHotYltNuVsqRGnq4ujNN thank you for your attention and your kind best regards Hi I'm using a form that uses number_format. It works fine until the number in question gets into the thousands. I can enter "3000", click Calculate and it comes back as "3,000.00" which is perfect. But if I click Calculate again, it changes to "3.00". How can I get it to remain "3,000.00"? Here's the code: Code: [Select] <form action="test.php" method="POST" > <?php if (empty($_POST['data1'])) { $number = ''; } else { str_replace(",","",$_POST['data1']); $number = number_format((double)$_POST['data1'],2); } ?> <input type="text" style="40" name="data1" value="<?php echo $number; ?>"> <input type="submit" name="submitCalc" value="Calculate" /><br /> <a href="test.php">Reset Form</a> </form> I have a db with db with date and the format for the date is 1975-12-22 and I want them to appear as 1975-DEC-22 I don't mind changing the date from date to varchar to make this happen maybe pulling each record and using find and replace or something. What would be the best way to make this happen. thanks in advance. Unfortunately, I have got nearly zero knowledge in PHP. I'm just trying to add a drop-down menu on my website which will turn the prices in USD to other currencies. I'm trying hard to learn but it's too difficult for me at the moment. Here are codes written by someone else which I want to modify and apply to my website. I've tried the second PHP on my WAMP local server but it returns nothing. Both files were in the same folder. I don't know if these codes are correct. I'd appreciate if someone could tell me if the codes are wrong or they just don't work on WAMP server. Sorry the codes are quite long. Thanks in advance. Code: [Select] <?php /* File: currencyexchange.php Author: Gary White Last modified: July 6, 2005 Copyright (C) 2005, Gary White This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the included GNU General Public License for more details. If you received this file without the gpl.txt file, you may view it at: http://www.gnu.org/copyleft/gpl.html See the readme.txt file for usage. July 6, 2005 added the RON, Romania New Leu, to the currency list. */ // this simply gets an array of possible currency countries and names $allCurrencies=getCurrencyNames(); class currencyExchange{ ///////////////////////////////////////////////////////////////////////////////////////// // Public Properties // Note that these properties are public, but the values are all generated internally. // You should consider them read only during normal usage. // The only one you may want to access would be the $localFile property, if you wanted // to change the name of the local file used to cache a copy of the data. ///////////////////////////////////////////////////////////////////////////////////////// // $Supplier property will be the European Central Bank, assuming we get the data var $Supplier=""; // $Date property is the date of the exchange rate publication var $Date=""; // $Rates property is an associative array of rateobj objects with the three letter identifier as the array keys var $Rates=array(); // $Source property will be either "Local" or "Remote" depending on where the data comes from var $Source=""; // $Error property will contain any error messages generates along the way var $Error=""; // $localFile property is the file name used to cache a local copy of the XML file var $localFile="currencies_local.xml"; // $url property is the URL of the XML file at the European Central Bank var $url="http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"; ///////////////////////////////////////////////////////////////////////////////////////// // Public Methods ///////////////////////////////////////////////////////////////////////////////////////// function getData(){ $olderr=error_reporting(0); $this->Source="Local"; if(file_exists($this->localFile)){ // load it $this->xml=@file_get_contents($this->localFile); $this->parse(); // check if it's a weekend // what day of the week is it? $weekday=date("w"); // if it's a Sunday or Saturday if($weekday==0 || $weekday==6){ // go back to last Friday $date=date("Y-m-d",strtotime("last Friday")); } else { $date=date("Y-m-d"); } // if the date in the local file is not the same // as our current date, or last Friday for weekends if($this->Date!=$date){ // clear the data $this->clearData(); // get the remote file $this->xml=$this->getRemoteFile($this->url); if($this->parse()){ $this->Source="Remote"; // write the remote file data to a local copy of the file $this->saveLocalCopy(); } } // if we have a local copy }else{ $this->xml=$this->getRemoteFile($this->url); if($this->xml) // write the remote file data to a local copy of the file $this->saveLocalCopy(); } if(!$this->xml) $this->error="Failed to get data"; else{ $this->parse(); } // sort our rates on the keys ksort($this->Rates); error_reporting($olderr); return count($this->Rates); } function getRemoteFile($url){ $curl_handle = curl_init(); // Where should we get the data? curl_setopt ($curl_handle, CURLOPT_URL, $url); // This says not to dump it directly to the output stream, but instead // have it return as a string. curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1); // the following is optional, but you should consider setting it // anyway. It prevents your page from hanging if the remote site is // down. curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1); // Now, YOU make the call. $buffer = curl_exec($curl_handle); // And tell it to shut down (when your done. You can always make more // calls if you want.) curl_close($curl_handle); // This is where i�d probably do some extra checks on what i just got. // Paranoia pays dividends. return $buffer; } function Convert($from, $to, $amount=1){ // Converts from one currency to another. The method expects at least two // parameters. The first param , $from, it the three letter identifier for // the currency you are converting from. The second param, $to, is the // three letter identifier for the currency you are converting to. The final // param, $amount, is the amount of the $from currency to convert. If omitted // the amount defaults to 1 and the function will return the amount of $to // currency that corresponds with 1 unit of the $from currency. if(array_key_exists($from, $this->Rates) && array_key_exists($to, $this->Rates)){ return ($amount * (($this->Rates[$to]->rate)/($this->Rates[$from]->rate))); }else{ $this->Error->Error = ""; if (!array_key_exists($from, $this->Rates)) $this->Error.="$from is not a recognized currency identifier "; if (!array_key_exists($from, $this->Rates)) $this->Error.="$to is not a recognized currency identifier"; return false; } } function setBaseCurrency($currency){ // This function converts all currencies to be based on one unit of // $base currency. It's only really useful if you want to output a // table of conversion factors. // get a factor to do our conversion based on our base currency $factor=$this->Rates[$currency]->rate; // modify the rates based on the base currency foreach(array_keys($this->Rates) as $k){ $rate=$this->Rates[$k]->rate / $factor; $this->Rates[$k]->rate=$rate; } return (count($this->Rates)>0); } ///////////////////////////////////////////////////////////////////////////////////////// // Private Methods // You should not need to call any of the following methods. ///////////////////////////////////////////////////////////////////////////////////////// function clearData(){ $this->Supplier=""; $this->Date=""; $this->Rates=array(); $this->Source=""; $this->xml=""; } function saveLocalCopy(){ $fp=fopen($_SERVER['DOCUMENT_ROOT'].$this->localFile,"w") or die("failed to write file"); fwrite($fp,$this->xml); fclose($fp); $this->parse(); $this->Source="Remote"; } function parse(){ if($this->xml){ $this->parser = xml_parser_create(); @xml_set_object($this->parser, $this); @xml_set_element_handler($this->parser, "startElement", "endElement"); @xml_set_character_data_handler($this->parser, "characterData"); $this->Rates['EUR']=new rateobj(); $this->Rates['EUR']->rate=1.00; $this->Rates['EUR']->currency="Euro"; xml_parse($this->parser, $this->xml, true) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); xml_parser_free($this->parser); } } function currencyExchange(){ $dir=pathinfo($_SERVER['PHP_SELF']); $dir=$dir['dirname']; $this->localFile="$dir/$this->localFile"; } function startElement($parser, $name, $attrs) { global $allCurrencies; $this->temp=""; $gwCurrencyExch=&$GLOBALS['gwCurrencyExch']; if($name=="CUBE"){ if(array_key_exists("TIME",$attrs)){ $this->Date=$attrs["TIME"]; } if(array_key_exists("CURRENCY",$attrs)){ $this->Rates[$attrs["CURRENCY"]]=new rateobj(); $this->Rates[$attrs["CURRENCY"]]->rate=$attrs["RATE"]; $this->Rates[$attrs["CURRENCY"]]->currency=$allCurrencies[$attrs["CURRENCY"]]; } } } function characterData($parser, $data){ $this->temp.=$data; } function endElement($parser, $name) { switch($name){ case "GESMES:NAME": $this->Supplier=$this->temp; break; case "GESMES:SUBJECT": $this->Report=$this->temp; break; } $temp=""; } } // end of ratelist class class gwSocket{ var $ClassName="gwSocket"; var $Version="0.6"; var $error=""; var $headers; var $maxRedirects=3; var $page=""; var $result=""; var $redirects=0; var $userAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"; function getUrl( $url ) { $retVal=""; $url_parsed = parse_url($url); $scheme = $url_parsed["scheme"]; $host = $url_parsed["host"]; $port = $url_parsed["port"]?$url_parsed["port"]:"80"; $user = $url_parsed["user"]; $pass = $url_parsed["pass"]; $path = $url_parsed["path"]?$url_parsed["path"]:"/"; $query = $url_parsed["query"]; $anchor = $url_parsed["fragment"]; if (!empty($host)){ // attempt to open the socket if($fp = fsockopen($host, $port, $errno, $errstr, 2)){ $path .= $query?"?$query":""; $path .= $anchor?"$anchor":""; // this is the request we send to the host $out = "GET $path ". "HTTP/1.0\r\n". "Host: $host\r\n". "Connection: Close\r\n". "User-Agent: $this->userAgent\r\n"; if($user) $out .= "Authorization: Basic ". base64_encode("$user:$pass")."\r\n"; $out .= "\r\n"; fputs($fp, $out); while (!feof($fp)) { $retVal.=fgets($fp, 128); } fclose($fp); } else { $this->error=$errstr; } $this->result=$retVal; $this->headers=$this->parseHeaders(trim(substr($retVal,0,strpos($retVal,"\r\n\r\n")))); $this->page=trim(stristr($retVal,"\r\n\r\n"))."\n"; if(isset($this->headers['Location'])){ $this->redirects++; if($this->redirects<$this->maxRedirects){ $location=$this->headers['Location']; $this->headers=array(); $this->result=""; $this->page=""; $this->getUrl($location); } } } return (!$retVal=""); } function parseHeaders($s){ $h=preg_split("/[\r\n]/",$s); foreach($h as $i){ $i=trim($i); if(strstr($i,":")){ list($k,$v)=explode(":",$i); $hdr[$k]=substr(stristr($i,":"),2); }else{ if(strlen($i)>3) $hdr[]=$i; } } if(isset($hdr[0])){ $hdr['Status']=$hdr[0]; unset($hdr[0]); } return $hdr; } } // end of gwSocket class class rateobj{ var $currency=""; var $rate=0; } function getCurrencyNames(){ $retVal['AED']="United Arab Emirates Dirham"; $retVal['AFA']="Afghanistan Afghani"; $retVal['ALL']="Albania Leke"; $retVal['ARS']="Argentina Peso"; $retVal['ATS']="Austria Schilling*"; $retVal['AUD']="Australia Dollar"; $retVal['BBD']="Barbados Dollar"; $retVal['BDT']="Bangladesh Taka"; $retVal['BEF']="Belgium Franc*"; $retVal['BGN']="Bulgaria Leva"; $retVal['BHD']="Bahrain Dinar"; $retVal['BMD']="Bermuda Dollar"; $retVal['BRL']="Brazil Reai"; $retVal['BSD']="Bahamas Dollar"; $retVal['CAD']="Canada Dollar"; $retVal['CHF']="Switzerland Franc"; $retVal['CLP']="Chile Peso"; $retVal['CNY']="China Yuan Renminbi"; $retVal['COP']="Colombia Peso"; $retVal['CRC']="Costa Rica Colone"; $retVal['CYP']="Cyprus Pound"; $retVal['CZK']="Czech Republic Koruny"; $retVal['DEM']="Germany Deutsche Mark*"; $retVal['DKK']="Denmark Kroner"; $retVal['DOP']="Dominican Republic Peso"; $retVal['DZD']="Algeria Dinar"; $retVal['EEK']="Estonia Krooni"; $retVal['EGP']="Egypt Pound"; $retVal['ESP']="Spain Peseta*"; $retVal['EUR']="Euro"; $retVal['FIM']="Finland Markkaa*"; $retVal['FJD']="Fiji Dollar"; $retVal['FRF']="France Franc*"; $retVal['GBP']="United Kingdom Pound"; $retVal['GRD']="Greece Drachmae*"; $retVal['HKD']="Hong Kong Dollar"; $retVal['HRK']="Croatia Kuna"; $retVal['HUF']="Hungary Forint"; $retVal['IDR']="Indonesia Rupiahs"; $retVal['IEP']="Ireland Pounds*"; $retVal['ILS']="Israel New Shekel"; $retVal['INR']="India Rupee"; $retVal['IQD']="Iraq Dinar"; $retVal['IRR']="Iran Rial"; $retVal['ISK']="Iceland Kronur"; $retVal['ITL']="Italy Lire*"; $retVal['JMD']="Jamaica Dollar"; $retVal['JOD']="Jordan Dinar"; $retVal['JPY']="Japan Yen"; $retVal['KES']="Kenya Shilling"; $retVal['KRW']="South Korea Won"; $retVal['KWD']="Kuwait Dinar"; $retVal['LBP']="Lebanon Pound"; $retVal['LKR']="Sri Lanka Rupee"; $retVal['LTL']="Lithuanian Lita"; $retVal['LVL']="Latvian Lat"; $retVal['LUF']="Luxembourg Franc*"; $retVal['MAD']="Morocco Dirham"; $retVal['MTL']="Malta Liri"; $retVal['MUR']="Mauritius Rupee"; $retVal['MXN']="Mexico Peso"; $retVal['MYR']="Malaysia Ringgit"; $retVal['NLG']="Dutch (Netherlands) Guilder*"; $retVal['NOK']="Norway Kroner"; $retVal['NZD']="New Zealand Dollar"; $retVal['OMR']="Oman Rial"; $retVal['PEN']="Peru Nuevos Sole"; $retVal['PHP']="Philippines Peso"; $retVal['PKR']="Pakistan Rupee"; $retVal['PLN']="Poland Zlotych"; $retVal['PTE']="Portugal Escudo*"; $retVal['QAR']="Qatar Riyal"; $retVal['ROL']="Romania Lei"; $retVal['RON']="Romania New Leu"; $retVal['RUB']="Russia Ruble"; $retVal['SAR']="Saudi Arabia Riyal"; $retVal['SDD']="Sudan Dinar"; $retVal['SEK']="Sweden Kronor"; $retVal['SGD']="Singapore Dollar"; $retVal['SIT']="Slovenia Tolar"; $retVal['SKK']="Slovakia Koruny"; $retVal['THB']="Thailand Baht"; $retVal['TND']="Tunisia Dinar"; $retVal['TRL']="Turkey Lira*"; $retVal['TRY']="Turkey New Lira"; $retVal['TTD']="Trinidad and Tobago Dollar"; $retVal['TWD']="Taiwan New Dollar"; $retVal['USD']="United States Dollar"; $retVal['VEB']="Venezuela Bolivare"; $retVal['VND']="Vietnam Dong"; $retVal['XAF']="CFA BEAC Franc"; $retVal['XAG']="Silver Ounce"; $retVal['XAU']="Gold Ounce"; $retVal['XCD']="Eastern Caribbean Dollar"; $retVal['XDR']="IMF Special Drawing Right"; $retVal['XOF']="CFA BCEAO Franc"; $retVal['XPD']="Palladium Ounce"; $retVal['XPF']="CFP Franc"; $retVal['XPT']="Platinum Ounce"; $retVal['ZAR']="South Africa Rand"; $retVal['ZMK']="Zambia Kwacha"; return $retVal; } ?> Code: [Select] <?php /* This is a sample file that demonstrates the usage of the currencyExchange class. For purposes of this example, make certain that currencyexchange_class.php is saved in the same directory as this file. */ //error_reporting(0); $path=pathinfo($_SERVER['PHP_SELF']); $path=$_SERVER['DOCUMENT_ROOT'].$path['dirname']; require_once("$path/currencyexchange_class.php"); $cx=new currencyExchange(); $cx->getData(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="imagetoolbar" content="no"> <meta name="mssmarttagspreventparsing" content="true"> <meta http-equiv="MSThemeCompatible" content="No"> <title>Currency Conversion Example</title> <style type="text/css"> body{ background-color: #eee; color: #333; font: small Verdana, Arial, Helvetica, sans-serif } #pricebox{ background-color: #f7f7f7; border:1px solid #000; margin: 50px auto; padding: 10px; width: 300px; } #pricebox h1, #pricebox h2, #pricebox p{ margin: 0; padding: 0; text-align: center; } h1{font-size: 160%;} h2{font-size: 140%;} </style> </head> <body> <div id="pricebox"> <h1>Get the New Widget</h1> <h2>Price $250.00 U.S. dollars</h2> <p><?php if ($euro=$cx->Convert("USD","EUR",250)){ $euro=number_format($euro,2); echo "€$euro Euros "; } if ($pound=$cx->Convert("USD","GBP",250)){ $pound=number_format($pound,2); echo "<br>\n£$pound British Pounds</p>\n" ."<p style=\"font-size:smaller;border-top: 1px solid #666;\">Non U.S. pricing based on exchange rates<br>\nin effect as of $cx->Date"; } ?></p></div> </body> </html> |