PHP - Is This Foreach() Correct/possible?
I have a foreach() that I want to run and I want to check before I test it out if this is even possible or how I would do this correctly if it isn't. I have 3 arrays that all pull data from a database earlier in the script. These three all "match" so that they all belong to the same product, but they are from different queries. I want a foreach() to extract data from all 3 of them and insert that into a database until the arrays run out of data.
foreach (($titles_list as $title) && ($prices_list as $price) && ($services_list as $service_id)) { mysql_query("INSERT INTO product_invoices (name, invoice_id, price, quantity, date_time, service_id) VALUES('$title', '$invoice_id', '$price', '$today_slashes', '$service_id')") or die(mysql_error()); } Hopefully you see where I'm going with this. Similar TutorialsBelow is my output on the browser: Student: Kevin Smith (u0867587) Course: INFO101 - Bsc Information Communication Technology Course Mark 70 Grade Year: 3 Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B Session: AAB Session Mark: 72 Session Weight Contribution 20% Session: AAE Session Mark: 67 Session Weight Contribution 40% Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B Session: AAD Session Mark: 61 Session Weight Contribution 50% Now where it says course mark above it says 70. This is incorrect as it should be 65 (The average between the module marks percentage should be 65 in the example above) but for some stange reason I can get the answer 65. I have a variable called $courseMark and that does the calculation. Now if the $courseMark is echo outside the where loop, then it will equal 65 but if it is put in while loop where I want the variable to be displayed, then it adds up to 70. Why does it do this. Below is the code: Code: [Select] $sessionMark = 0; $sessionWeight = 0; $courseMark = 0; $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { $sessionMark += round($row['Mark'] / 100 * $row['SessionWeight']); $sessionWeight += ($row['SessionWeight']); $courseMark = ($sessionMark / $sessionWeight * 100); if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong>" round($courseMark) "<strong>Grade</strong> <br><strong>Year:</strong> {$row['Year']}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; I think the problem is that it is outputting the answer of the calculation only for the first session mark. How in the while loop can I do it so it doesn't display it for the first mark only but for all the session marks so that it ends up showing the correct answer 65 and not 72? It's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355772.0 I'm not sure if the title explains it very well, but here is an image of it. I am trying to figure out how to access the option selected (equal, not equal, etc.), along with its input box, for each column (the checkboxes on the right) selected. The purpose of this is to allow a non-programming administrator user to create a custom query to access information. I can find out which checkboxes are selected no problem, but finding the accompanying drop-down option and input box is difficult for me. How do I do this? If you have a suggestion on how to change it, I'm very open. Thank you in advance! Code: [Select] if(!isset($_POST['submit'])) { echo " <form method='post'> <table> <tr> <td valign='top'>SELECT</td> <td valign='top'> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='fields[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> </tr>"; } echo " </table> </td> <td valign='top'>FROM allocations</td> <td valign='top'>WHERE</td> <td> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='column[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> <td> <select name='operator[]'> <option value='='>equals</option> <option value='<>'>does not equal</option> <option value='>'>greater than</option> <option value='<'>less than</option> <option value='>='>greater than or equal to</option> <option value='<='>less than or equal to</option> <option value='LIKE'>is like</option> </select> </td> <td><input type='text' name='criteria[]'></td> </tr>"; } echo " </table> </td> <td valign='top'><input type='submit' value='Process Query' name='submit' class='submit'></td> </tr> </table> </form>"; } else { echo "<b>Fields to edit:</b> "; foreach ($_POST['fields'] as $fields) { echo $fields,", "; } echo "<br><br>"; echo "<b>Columns to query:</b> "; foreach ($_POST['column'] as $columns) { echo $columns," HERE IS THE SPOT, "; } } hi i would like to know why this doesnt work .the problem is that it doesnt give me multiple tr-s like td-s.it only works for one tr and multiple td-s. help apreciated
<html><head> </head> <body> <?php function myt($border,$column,$row,$words){ $table="<table border='".$border."'>"; if($column==1){ $table.='<tr>'; for($i=1;$i<=$row;$i++){ $table.="<td>".$words."</td>"; };//end of for $table.='</tr>'; }//end of if else{ for($i=1;$i<=$column;$i++){ $table.="<tr border='".$border."'>"; for($i=1;$i<=$row;$i++){ $table.='<td>'.$words.'</td>'; } $table.='</tr>'; };//end of column for };//end of else $table.="</table>"; return $table; };//end of function //echo myt (1,1,10,'word'); WORKS!!! echo myt(1,2,4,'lalalala'); ?> </body> </html> Edited by Maq, 16 May 2014 - 02:18 PM. Hi, Is this the correct way to go by setting cookies for my login 'remember' functionality?, I've posted the relevant login and logout code. Login: <?php session_start(); //some code... if (isset($_POST['remember'])) { $expire = time() + 1728000; // Expire in 20 days $site_domain = 'phpfreaks.com'; //example $_SESSION['username'] = $_POST['username']; //don't worry this has been validated :D $username = $_SESSION['username']; //some sql query to fetch code.. $code = $row['code']; setcookie('username', $username, $expire, NULL, ".$site_domain", NULL, TRUE); setcookie('code', $code, $expire, NULL, ".$site_domain", NULL, TRUE); } ?> Logout: <?php session_start(); if (isset($_COOKIE['username'])) { $expire = time() - 1728000; // Expire in 20 days $site_domain = 'phpfreaks.com'; //example $username = $_SESSION['username']; //some sql query to fetch code.. $code = $row['code']; setcookie('username', $username, $expire, NULL, ".$site_domain", NULL, TRUE); setcookie('code', $code, $expire, NULL, ".$site_domain", NULL, TRUE); } unset($_SESSION['username']); $_SESSION = array(); session_destroy(); ?> Please tell me if it looks good to go and/or any improvements. PS: I want it accessible on all areas of the domain (including subdomains and paths etc.), and HTTP ONLY (so js can't access it) - I believe I've set the right parems? Hi,
I have upgraded my server from PHP 5.3.3 to version 5.5 and I'm now having a few problems with some code.
This line gives a fatal error of:
Call to undefined function session_is_registered()
if (session_is_registered("isAuthenticated") && ($_SESSION ['isAuthenticated'] = "loggedIn"))It appears this is depreciated? How can I solve this? Good Morning, I am literally just starting out with php but wanted to clarify whether I should be creating .php files or .html files. I have found a page which states: "For Windows or IIS servers - You do not have an .htaccess file. Windows IIS servers also cannot run php on html pages. Your only option for windows IIS servers is to use .shtml or .php pages with the php option from the reader." Is this correct and does this mean that I should always err on the side of caution and use .php files instead of .html file? Thanks in advance, Mark Hi, just a quick question. Should functions really be used for tasks such as in my example below? I’m attempting to use some for smaller tasks to improve readability and reduce code repetition. Or should they be used for larger tasks?
functions.php
function accessDenied(){ $_SESSION[‘error’] = "You cannot view that page, you wally"; header(‘location: error.php’); exit; }page.php if(!$loggedin){ accessDenied(); } Edited by paddy_fields, 12 August 2014 - 08:44 AM. $ error = trim( strip_tags($_GET['error']) ); VS $strip_error = strip_tags($_GET['error']) ; $trim_error = trim($strip_error);Which method is correct way? Also I am first striping and trimming is it wright way. could you please advice me. Thank you Edited by thilakan, 16 October 2014 - 05:50 AM. I have using gmdate() to get the GMT time but as it does not take in to account daylight saving the time is one hour behind. Does anyone have a fix that can work out the correct time what ever time of year it is? As I am currently having to change the code each time the time changes. hello. how can i code this so that if the page is an admin page i get the admin template and if the page is a public page i get the public template i seem to be having trouble with my function and if statements this is the code Code: [Select] //$layout gets the header.php and the footer.php function include_layout($layout){ //this part find all pages Zone. zone is either Admin or Public $pageZone = Pages::find_all(); foreach ($pageZone as $pageZones){ $Pzone = $pageZones->zone; } //this part gets the template id that is set for admin and public $tempBS = BasicSettings::find_by_id(1); $atID = $tempBS->adminTemp_id; $ptID = $tempBS->publicTemp_id; // if page is admin get the admin template if ($pZone = "admin"){ $Atemp = Templates::find_adminTemp($atID); $ATname = $Atemp->name; include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); } // if page is public get the public template if($pZone = "public"){ $Ptemp = Templates::find_publicTemp($ptID); $PTname = $Ptemp->name; include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } } to help you understand what im doing i have put a // description above each part of code. the problem is that i get the header echoed out twice. if i change the if to an if else like this... Code: [Select] if ($pZone = "admin"){ $Atemp = Templates::find_adminTemp($atID); $ATname = $Atemp->name; include(TEMP.DS.$ATname.DS.'layouts'.DS.$layout); }else if($pZone = "public"){ $Ptemp = Templates::find_publicTemp($ptID); echo $PTname = $Ptemp->name; include(TEMP.DS.$PTname.DS.'layouts'.DS.$layout); } i only get 1 header but the public template does not work template this is because if i echo out Code: [Select] echo $PTname = $Ptemp->name; i get nothing so. how can i code it so that if the page is an admin page i get the admin template and if the page is a public page i get the public template thanks ricky Hi, Im pretty much self taught when it comes to php, never read any books just picked things up as i go, and im looking for some advice on how i build my pages as i believe im not approaching it correctly. Basically i build an index.php, this contains my header, footer, and any menus i may have, then for my content pages, in this case products, contact, about us i use use an include so these content pages just have content. Now by doing this my address bar looks like this index.php?location=contact.php for the sake of google and search results and so on, am i limiting my ability to be found by not using a differant file for each page? should i include a header, footer, menu etc within my content pages rather than the other way around? Thanks in advance for any advice. Hello all, I'm trying to write a joomla page that will import LinkShare banners into the banner component. The problem I'm having is that LinkShare doesn't seem to always have the correct image size listed. If I use their dimensions, the images come out skewed and bad looking. So I'm trying to use getimagesize, to get the real dimensions, and it's still not working. Please take a look, and let me know if you have any suggestions. Code: [Select] <?php define('_JEXEC', 1); define('JPATH_BASE', dirname(__FILE__)); define('DS', DIRECTORY_SEPARATOR); require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php'); require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php'); $mainframe =& JFactory::getApplication('site'); $user =& JFactory::getUser(); If (($user->gid) === '25') { $token = "mylinksharetoken"; // required $status = "approved"; //application status name $mid = $_POST['mid']; $cat = $_POST['cat']; $size = $_POST['size']; //optional, use -1 as the default value. $campaignID = "-1"; //optional, use -1 as the default value $page = "1"; //optional, use 1 as a default value $startdate = ""; //formatted MMDDYYYY - optional, use an empty set as the default value (//). $enddate = ""; //formatted MMDDYYYY - optional, use an empty set as the default value (//). if (isset($_POST['submit'])) { $feed = simplexml_load_file("http://lld2.linksynergy.com/services/restLinks/getBannerLinks/{$token}/{$mid}/{$cat}/{$startdate}/{$enddate}/{$size}/{campaignID}/{$page}"); $children = $feed->children('http://endpoint.linkservice.linkshare.com/'); $entries = $children->return; foreach ($entries as $entry) { $sourcecode=GetImageFromUrl($details->imgURL); $name=md5(mt_rand()); $path = '/home/mysite/tmp/imgtmp/'; $savefile = fopen($path.$name, 'w'); fwrite($savefile, $sourcecode); list($realwidth, $realheight) = getimagesize($path.$name); $details = $entry->children('http://endpoint.linkservice.linkshare.com/'); $image = "<a href=\"{$details->clickURL}\" target=\"_NEW\">"; $image .= "<img src=\"{$details->imgURL}\" border=\"'0\" height=\"{$realheight}\" width=\"{$realwidth}\" title=\"{$details->name}\" alt=\"{$details->name}\" />"; $image .= "</a><img border=\"0\" height=\"1\" width=\"1\" src=\"{$details->showURL}\" />"; echo $image . "<br>\n"; fclose($savefile); @unlink($path.$name); } } ?> <form name="form1" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> Categories<select name="cat"> <option value="-1">All Categories</option> <option value="17">Business & Career</option> <option value="150">B-to-B</option> <option value="151">Employment</option> <option value="152">Real Estate</option> <option value="18">Department Store</option> <option value="153">Clothing</option> <option value="154">Gifts</option> <option value="155">Home</option> <option value="247">Jewelry</option> <option value="19">Family</option> <option value="156">Baby</option> <option value="157">Education</option> <option value="158">Entertainment</option> <option value="159">Pets</option> <option value="21">Telecommunications</option> <option value="211">Equipment</option> <option value="212">Long Distance</option> <option value="213">Wireless</option> <option value="1">Hobbies & Collectibles</option> <option value="101">Art</option> <option value="102">Auctions</option> <option value="103">Collectibles</option> <option value="2">Auto</option> <option value="104">Accessories</option> <option value="105">Cars</option> <option value="106">Rentals</option> <option value="3">Clothing & Accessories</option> <option value="207">Children</option> <option value="107">Accessories</option> <option value="108">Men</option> <option value="109">Women</option> <option value="246">Jewelry</option> <option value="4">Computer & Electronics</option> <option value="110">Hardware</option> <option value="111">Consumer</option> <option value="112">Software</option> <option value="5">Entertainment</option> <option value="113">Books/Magazines</option> <option value="114">Music</option> <option value="115">Videos</option> <option value="6">Financial Services</option> <option value="116">Banking/Trading</option> <option value="117">Credit Cards</option> <option value="118">Loans</option> <option value="7">Food & Drink</option> <option value="218">Candy</option> <option value="119">Cigars</option> <option value="120">Gourmet</option> <option value="121">Wine</option> <option value="8">Games & Toys</option> <option value="122">Children</option> <option value="123">Educational</option> <option value="124">Electronic</option> <option value="9">Gift & Flowers</option> <option value="125">Gifts</option> <option value="126">Flowers</option> <option value="127">Greeting Cards</option> <option value="10">Health & Beauty</option> <option value="229">Prescription</option> <option value="128">Bath/Body</option> <option value="129">Cosmetics</option> <option value="130">Vitamins</option> <option value="11248">Medical Supplies & Services</option> <option value="11">Home & Living</option> <option value="232">Improvement</option> <option value="131">Bed/Bath</option> <option value="132">Garden</option> <option value="133">Kitchen</option> <option value="12">Mature/Adult</option> <option value="134">Apparel</option> <option value="135">Books</option> <option value="136">Entertainment</option> <option value="13">Office</option> <option value="137">Equipment</option> <option value="138">Home Office</option> <option value="139">Supplies</option> <option value="14">Sports & Fitness</option> <option value="140">Clothing</option> <option value="141">Collectibles</option> <option value="142">Equipment</option> <option value="15">Travel</option> <option value="245">Vacations</option> <option value="143">Airline</option> <option value="144">Car</option> <option value="145">Hotel</option> <option value="16">Internet & Online</option> <option value="149">Programs</option> <option value="146">Services</option> <option value="147">Development</option> <option value="148">Hosting</option> <option value="16249">Online Dating</option> <option value="20">Miscellaneous</option> <option value="210">Other, Other Products/Services</option> </select> <?php $merchantlist = simplexml_load_file("http://lld2.linksynergy.com/services/restLinks/getMerchByAppStatus/{$token}/{$status}"); $children2 = $merchantlist->children('http://endpoint.linkservice.linkshare.com/'); $entries2 = $children2->return; echo "Manufacturers: <select name=\"mid\">\n"; echo "<option selected value=\"-1\">All Manufacturers</option>\n"; foreach ($entries2 as $entry2) { $details2 = $entry2->children('http://endpoint.linkservice.linkshare.com/'); echo "<option value=\"{$details2->mid}\">{$details2->name}</option>\n"; } echo "</select>"; ?>Size: <select name="size"> <option selected value="-1">Any Size</option> <option value="1">468x60 - Full Banner <option value="2">392x72 - Mid Banner</option> <option value="9">160x600 - Wd Skyscrp</option> <option value="10">120x600 - Skyscraper</option> <option value="11">180x150 - Rectangle</option> <option value="12">336x280 - Large Rect</option> <option value="3">234x60 - Half Banner</option> <option value="13">300x250 - Med Rect</option> <option value="14">250x250 - Sq Pop-up</option> <option value="15">240x400 - Vert Rect</option> <option value="4">125x125 - Sq Button</option> <option value="5">120x90 - Button 1</option> <option value="6">120x60 - Button 2</option> <option value="7">88x31 - Micro Bar</option> <option value="8">120x240 - Vert Banner</option> <option value="0">0x0 - Other</option> <option value="16">728x90 - Leader-board</option> <option value="17">720x300 - Pop-Under</option> <option value="18">550x480 - Pop-Up Large</option> <option value="19">300x600 - Half Page Ad</option> <option value="20">305x64 - X-Large</option> <option value="21">215x64 - Large</option> <option value="22">167x30 - Medium</option> <option value="23">112x20 - Small</option> </select> <input name="submit" type="submit" value="submit" /> </form> <?php } else { echo "not logged in"; die(); } function GetImageFromUrl($link) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch,CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 0); $result=curl_exec($ch); curl_close($ch); return $result; } ?> i know i have it wrong, cant figure it out. anybody able to help? Code: [Select] echo "<td align='center'><a href="#" onmouseover="alert('" . $customer . " <br /> " . $address . "');return false">" . $customer . "</a></td>"; Hi,
just joined today.
I am using a variable to chose a template dependent on when the user is logged in it shows a search box or not if they haven't. As a php beginner I just want to know if this is the correct method or should I be declaring 'template' somewhere specific.
It is only used in this one file.
I hope I've used the code tags correctly...
<php? include_once("login_status.php") If(user_login==true){ $template="template_top.php" ...web page with search box }else{ ...web page without search box $template="template_top_NoSearch.php" } ?> <html> <?php include_once($template); ?> </html> What is the correct way to use the backslash here? I am using an ftp script and retrieving the brand directory name through url. I want to catch it if they try to use \ in the url to list all directories. Code: [Select] elseif($_GET[f]=="\") { echo "You have entered an invalid vendor."; $_SESSION['brand_path'] = "INVALID"; } I am having problems with this code sometimes it works other times it doesnt I cant figure out why. <?php session_start(); $xml = simplexml_load_file("xmlmonstor/skeleton.xml"); //get the hp, if it exists if (!isset($_SESSION['player_hp'])) { $player_hp = 30; } else { $player_hp = $_SESSION['player_hp']; } if (!isset($_SESSION['mob_hp'])) { $mob_hp = $xml->mob_hp; } else { $mob_hp = $_SESSION['mob_hp']; } // Set amount of starting turns if (!isset($_SESSION['turns'])) { $turns = 500; } else { $turns = $_SESSION['turns']; } $first = mt_rand(1,100); //find out who goes first if ($first < 60) { $player_damage = 5; $mob_hp -= $player_damage; } else { $mob_attack = $xml->attack; $player_hp -= $mob_attack; } if ($player_hp <= 0) { header("Location:south.php?p=defeat"); $turns = $turns - 1; $_SESSION['turns'] = $turns; exit(); } if($mob_hp <= 0) { header("Location:south.php?p=victory"); $turns = $turns - 1; $_SESSION['turns'] = $turns; exit(); } //Gotta store them back in sessions $_SESSION['player_hp'] = $player_hp; $_SESSION['mob_hp'] = $mob_hp; $_SESSION['turns'] = $turns; ?> Am I setting the sessions right or is there a better way to do it? Thanks I was wanting to make some kind of session timeout ability, just purely out of curiosity. I have tried going off my own theory, before looking at any tutorials, well have looked a bit but tried getting the jist and having a go myself the next day (anyways that being said), this code he Code: [Select] <?php ini_set('display_errors', 1); session_name("jeremysmith_test_session"); session_start(); $_SESSION['start_time'] = time(); if($_SESSION['start_time'] < $_SESSION['start_time'] + 500) { printf("Time out be out dated!"); } Just does not seem to want to work, is there any reason for this, that you could think of? I appreciate any replies, Jeremy. is there anything wrong with this statement: it just won't execute: session_start(); if ($_SESSION['dstatus']==F) { header("Location: http://www.orgpict.com/downloadform.php"); exit; } |