PHP - Array And Extract Problems?
I'd like some help debuging my code, I can't seem to figure out why it isn't creating the variables... Here it is:
<?php $template_settings = array( "index"=>"index.php", "announcements"=>"announcements.php" ); extract($template_settings, EXTR_PREFIX_ALL, "template_"); echo $template_index; ?> No matter what I do $template_index still equals null and I'm wondering what I'm doing wrong. There are no errors of anykind. Similar TutorialsThis topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321546.0 Hi, I am very new to PHP and apologies if this question has already been answered in another thread.
I am trying to extract the information from one array into another when some search criteria is matched.
Here is an example array ($original):
Array ( [ 1234567 ] => Array ( [name] => john ) [ 3456 ] => Array ( [name] => johnny ) [ 45673 ] => Array ( [name] => james ) [ 987 ] => Array ( [name] => jamie ) [ 5628721 ] => Array ( [name] => Simon ))
So if I searched for the string john, jo, joh then the new array ($filtered) should be as follows:
Array ( [ 1234567 ] => Array ( [name] => john ) [ 3456 ] => Array ( [name] => johnny ))
I was trying to do this using array_search & preg_match but have been struggling.
Any help would be much appreciated!
I am new to coding and I am trying to write a simple business registration app. a foreach loop populates a select list and a nested loop checks to see if something new is being added. If so write to the DB. Great. Only part of it is working, I am getting the correct businessId but the categoryId is an array: 188 Array 189 Array 190 Array 191 Array 192 Array 195 Array 196 Array Here is the code: Code: [Select] <form method="post" action="?"> <table> <tr><td class="picklist"><?php echo $pickMessage; ?> <select name="bizCatSelect[]" size="4" multiple> <?php $sql = "SELECT categoryId FROM categories"; $sth = $dbh->prepare($sql); $sth-> execute(); $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); foreach($result as $value) { if($addRecord == 1) { $selected = false; if(in_array($value, $bizCatSelect)) // $row[1] { $sql = "INSERT INTO businessCat(businessId,categoryId) VALUES(:bizId, :bizCatSelect)"; $sth = $dbh->prepare($sql); $sth->bindValue(':bizId', $bizId, PDO::PARAM_STR); $sth->bindValue(':bizCatSelect', $bizCatSelect, PDO::PARAM_STR); $query = $sth->execute(); $params = array($bizId, $bizCatSelect); // $row[0] $value print_r($params); //$resp = $sth->execute($query, $params); echo "<option selected=\"$value\">$value</option>\n"; // $row[1] $selected = true; } if($selected == false){echo "<option value=\"$value\">$value</option>\n";} } else{ echo "<option value=\"$value\">$value</option>\n";} //echo "<option value=\"$value\">$value</option>\n"; } ?> </select> </td> <td class="addlist"> <table> <tr><td class="formLable">Business Name:</td> <td><input type="text" name="bizName" size="40" maxlength="255" value="<?php echo $bizName; ?>"></td> </tr> <tr><td class="formLable">Address:</td> <td><input type="text" name="bizAddress" size="40" maxlength="255" value="<?php echo $bizAddress; ?>" ></td> </tr> <tr><td class="formLable">City:</td> <td><input type="text" name="bizCity" size="40" maxlength="128" value="<?php echo $bizCity; ?>" ></td> </tr> <tr><td class="formLable">Telephone:</td> <td><input type="text" name="bizTele" size="40" maxlength="64" value="<?php echo $bizTele; ?>" ></td> </tr> <tr><td class="formLable">URL:</td> <td><input type="text" name="bizUrl" size="40" maxlength="255" value="<?php echo $bizUrl; ?>" ></td> </tr> </table> </td> </tr> </table> <p><input type="hidden" name="addRecord" value="1"> <?php if($addRecord == 1) {echo "<p><a href=\"?\">Add another business</a></p>";} else {echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Add Business\">";} ?> </p> </form> I just can't seem to get this last part, any suggestions? AL I've been trying to get this to work for a few days now and can't seem to get anywhere with it! Any help is very much appreciated. I am creating a number generator where the user is required to insert the maximum number and generate rate. Maximum number is the highest number that the script will go to, and generate rate is how many numbers should be created. When the script runs, the numbers are stored into a MySQL database. The MySQL database creates a unique ID number so it can be recalled at a later date. The user then needs to go to Sorting.php and selects the record they wish to use. The numbers from this record are then counted and then stored into an array. If the numbers 2,5,5,0,2,2,1,3,5,1 where generated, the output of this new array will be: [5] => 3 [3] => 1 [2] => 3 [1] => 2 => 1 (These arrays can be of any length) I now need to extract this data and show it on screen. I don't know how to approach it. Format example: Number 5 appears 3 times Number 3 appears 1 times Number 2 appears 3 times Number 0 appears 1 times Sorting.php <?php $db1 = new Number_Information(); $db1->openDB(); $sql = "select * from GeneratedNumber"; $result = $db1->getResult($sql); if (!$_POST) { //page loads for the first time ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select the ID (If you have just generated a number, it will be the last one): <!--This is the drop down menu--> <select name="ID"> <?php while ($row = mysql_fetch_assoc($result)) { echo "<option value='{$row['ID']}'> {$row['ID']} </option>"; } ?> </select> <br /> <input type="submit" value="Continue" /> </form> <?php } else { $ID = $_POST['ID']; //This will contain the value that was selected in the drop down menu above. $result = mysql_query("SELECT NUMBERS2 FROM GeneratedNumber WHERE ID='{$ID}'"); //This tells the script to select NUMBERS2 contents which is assosiated with the ID. while ($row = mysql_fetch_array($result)) $NUMBERS2 = $row['NUMBERS2']; echo "$NUMBERS2"; //Testing reasons - remove it later. echo "<br />"; //same as above echo "$ID"; // as above. echo "<br />"; //as above //Convert NUMBERS2 back into an array when inserted into table from Generator.php $NUMBERS = explode(",", $NUMBERS2); // Counts how many times a number appears //******************************************************************************************************************* //IF ALL ELSE FAILS, REVERT BACK TO THIS. //print_r(array_count_values($NUMBERS)); //It will only print the statement, but gives you a good building block when things WILL go wrong. //******************************************************************************************************************* rsort($NUMBERS); print_r(array_count_values($NUMBERS)); (The questions when editing posts are hard. I've needed to Google both of them:() Hi - I have an array which is created from a session variable I must have constructed my array wrong, as for the life of me I can not extract the individual values. I have tried innumerable $key=>$value combinations. I must be doing something stupid, maybe it is obvious, but not to me. I'll be darn grateful if you can help me ! Many Thanks MY array looks like this: Code: [Select] Array ( [quantity] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 ) [name] => Array ( [0] => Ribs Large pack 20 pieces [1] => 25 Piece Bag [2] => Sirloin Steak [3] => 50 piece bag of Scalops [4] => Sirloin Steak ) [prodid] => Array ( [0] => 17 [1] => 28 [2] => 27 [3] => 25 [4] => 27 ) ) The CodeIgniter form which generated this array looks like this: Code: [Select] <?php foreach ( $_SESSION['openorders'] as $key=>$value) { ?> <tr align="center"> <td width="30"><?php $data=array('name' =>'quantity[]','value'=>$value['quantity']); echo form_input($data); ?></td> <td><?php echo $value['prodid']; ?></td> <td><?php echo $value['name'];?></td> <td><?php echo $value['ordervalue']; ?></td> <td><?php echo $value['pricelb']; ?></td> <td align="right"><?php echo form_checkbox('delete','delete',FALSE); echo form_hidden('prodid[]', $value['prodid']); echo form_hidden('name[]', $value['name']); echo form_hidden('orderid', $value['orderid']); $totalordervalue += $value['ordervalue']; } ?> Hello everyone, I have been trying several things,recently, and I can't figure out how to get a series of numbers, grouped together as a string of number, instead of it adding or grabbing the last number that was randomly generated. I'm wanting to save it in a variable (of course), so I can pass it though a query when it is needed. foreach($array as $number){ echo $number; } $array is the variable where it is an array but all the randomly generated numbers are stored there. All / any help would be gratefully appreciated. I'm a newbie . I've been stuck on this error message for 2 days: I get this error message: extract() expects parameter 1 to be array, boolean given in C:\x\xampp\htdocs\user_personal.php on line 30 Code: [Select] <?php $query = 'SELECT about_me, job, hobbies, contact FROM site_user u JOIN site_user_profile p ON u.user_id = p.user_id WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); mysql_close($db); ?> I think joining table is hard, I just want to create a profile that would be linked to a user name. Please be my friend and help me so I can have PHP phun time. I have a function that is supposed to find the email address of the user that's logged in my application. going by their ID:
function getUserEmail($userID){ $sqll="SELECT id,email FROM users WHERE id='".$userID."'"; $result1=mysql_query($sqll); $row11=mysql_fetch_assoc($result1); $processor=$row11["email"]; return $processor; }What I'm trying to do is incorporate that into sending a simple email to the person that's logged in after they submit a file. But the email is not being sent and I'm getting this message: Warning: mail() expects parameter 1 to be string, array given Here is what I have for sending the email : $sendto = getUserInfo($_REQUEST[1][email]); $subject = "File recieved"; $message = "Hello " . getUser($_REQUEST["user"]) . ". you successfully submitted: $title"; mail($sendto, $subject, $message);How do I extract just the email address to prevent giving the array? My array is $arr = array( 'global' => array( array('tabs', 'tabs', 'tabs', array( 'Main' => 'main', 'Gallery' => 'galleryID', 'mera' => 'mera', )), array('main','div', 'div'), array('egice', 'Eice', 'text', '', ''), array('closeHere', 'closeHere', 'closeHere'), array('galleryID','div', 'div'), array('gallery', 'Gallery #1', 'image', '', ''), array('closeHere', 'closeHere', 'closeHere'), array('networking', 'div', 'div'), array('siLype', 'SiLype', 'text', '', ''), array('gpXCge', 'GpXCge', 'toggle_button', '1', 'Yes', 'No', ''), array('closeHere', 'closeHere', 'closeHere'), array('mera', 'div', 'div'), array('maimera', 'Maimera', 'repeatedText', 'resYI', 'GYL',''), array('closeHere', 'closeHere', 'closeHere'), array( 'moures','div', 'div'), array('meLmo', 'MeLmo', 'text', '', ''), array('cYSlot', 'CYSlot', 'text', '', ''), array('closeHere', 'closeHere', 'closeHere'), array('clT', 'clT', 'clT'), ), );
Simply, I want to split the main array to multiple arrays
I had tried here to do it but I can’t Problem: "Warning: extract() expects parameter 1 to be array, null given in C:\x\xampp\htdocs\pages\user_personal.php on line 32" - error also found on lines 33 and 38. and none of the information is displayed. Goal: I'm trying to retrieve profile information and multiple user inserted pictures and display the pictures through a while loop from one query. <?php $query = 'SELECT u.name_id, i.bio, i.exhib, p.product_code FROM user u LEFT JOIN profile i ON u.name_id = i.name_id LEFT JOIN ecomm_products p ON u.name_id = p.product_code WHERE u.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '" and p.name = "' . mysql_real_escape_string($_SESSION['name'], $db) . '"'; $result = mysql_query($query, $db) or die(mysql_error()); extract($bio); //line 32 extract($exhib); //line 33 $odd = true; while ($row = mysql_fetch_array($result)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; extract($rows); line 38 echo '<td><a href="' . $dir . '/' . $row['product_code'] . '.jpg">'; echo '<img src="' . $thumbdir . '/' . $row['product_code'] . '.jpg">'; echo '</a></td>'; echo '</tr>'; } echo "</table>"; echo "<p>"; ?> <ul> <li>Biography: <?php echo $bio; ?></li> <li>Exhibitions: <?php echo $exhib; ?></li> </ul> So I have been working on my website for a while which all is php&mysql based, now working on the social networking part building in similar functions like Facebook has. I encountered a difficulty with getting information back from a link. I've checked several sources how it is possible, with title 'Facebook Like URL data Extract Using jQuery PHP and Ajax' was the most popular answer, I get the scripts but all of these scripts work with html links only. My site all with php extensions and copy&paste my site links into these demos do not return anything . I checked the code and all of them using file_get_contents(), parsing through the html file so if i pass 'filename.php' it returns nothing supposing that php has not processed yet and the function gets the content of the php script with no data of course. So my question is that how it is possible to extract data from a link with php extension (on Facebook it works) or how to get php file executed for file_get_contents() to get back the html?
here is the link with code&demo iamusing: http://www.sanwebe.c...-php-and-jquery
thanks in advance.
Hello,
Can anyone tell me what I'm doing wrong here? I am trying to run a query against a table for scenes from movies. Each movie would have up to 8 scenes. For the life of me I can't get this loop to work. The movie id is being passed in the url, tested to make sure it's being passed and it is. The code is pasted below.
require_once ('../mysqli_connect.php'); $movie_id = $_GET['movie_id']; $q = "SELECT * FROM scenes WHERE movie_id = $movie_id"; $r = @mysqli_fetch_array($dbc, $q); $row = @mysqli_fetch_array($r, MYSQLI_ASSOC); while ($row = @mysqli_fetch_array($r, MYSQLI_ASSOC));{ echo '<a href=" '.$row['scene_id'].'.mp4 ">'.$row['scene_name'].'</a>';}In advance thanks a million!! Edited by Zane, 28 May 2014 - 10:01 AM. i have a users online section and i am using an aray and implode so the comma is displayed on every username but the last, but it displays the same usernames several times. This could be due to the switch i am using to define user group. Heres the code: $online_query = $db->query("SELECT user_id, user_group, user_username FROM ".DB_PREFIX."sessions"); while ($online_info = mysql_fetch_object($online_query)) { switch($online_info->user_group) { case 1: $userClass = 'admin'; break; case 2: $userClass = 'mod'; break; case 3: case 0: default: $userClass = 'user'; break; } $users2[] = "<span class=\"{$userClass}\">{$online_info->user_username}</span>"; echo '<p>' . implode(', ', $users2) . '</p>'; } is there something i am doing wrong? I am trying my hand at using an array i have never done it before, and I am having some problems getting it work work. if someone could point me in the right direction? Thanks <?php $active_keys = array(); foreach($_GET['img'] as $key => $filename) { if(!empty($filename)) { $active_keys[] = $key; } } ?> Having problem with a bit of code. I am trying to fetch data from the database, I have used mysql_fetch_array before, and even in later bits of code. I want to use this data for an IF statement later on. The IF statement isn't there, because this code is catching somewhere. The fetch array is working fine, and it echos out the correct row in database that it should. The issue, it stops displaying code that follows it. In the code, I have put a comment (// Code kills here ....) where the code is killing. I have identified the few lines of code that is killing the script. You can see the page.. The number 71 is what is supposed to be supplied by the query and array. This is the page as it is with the trouble code. Here is the page without the trouble bit of code, and it displays all that it should. But it doesn't have the functionality I want to build in with the array obviously. Here is the code with highlight bit of trouble: /source/userinfo.php Code: [Select] <?php include ("db.php"); $get_info = mysql_query ("SELECT * FROM registrations WHERE u_id=$uid AND appid=$appid" , $link2); //Begin Trouble Code while ($check = mysql_fetch_array($get_info)) { echo $check['assign_id']; } //End Trouble Code // Code kills here, for some reason.... Proper assign_id displayed, but it kills script. $count = mysql_num_rows($get_info); if ($count >= 1) { $get_jos_info = mysql_query ("SELECT * FROM jos_users WHERE id=$appid" , $link); $get_avatar = mysql_query ("SELECT * FROM jos_comprofiler WHERE user_id=$appid" , $link); while ($avatar_link = mysql_fetch_array($get_avatar)) $avatarurl = $avatar_link['avatar']; echo $avatar_link['avatar']; echo "<table border='0' width='70%' align='center' cellpadding=5>"; while ($rowteam = mysql_fetch_array($get_info)) { while ($rowjos = mysql_fetch_array($get_jos_info)) { $urlbegin = "<img src='http://versionxlegends.com/images/comprofiler/tn"; $urlend = "'>"; echo "<tr><td width=100% align=center colspan=2>".$urlbegin.$avatarurl.$urlend."</td></tr>"; echo $avatar; echo "<tr><td width=40% align=right><strong>Registration #</strong></td><td width=60% align=center>$rowjos[id]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Username</strong></td><td width=60% align=center>$rowteam[username]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Name</strong></td><td width=60% align=center>$rowteam[name]</td></tr>"; echo "<tr><td width=40% align=right><strong>Provided Skype Username</strong></td><td width=60% align=center>$rowteam[skype]</td></tr>"; //Add script for lead only view Email Address. Team Member, field is hidden. Lead sees email and a YES/NO if email matches. If not, lead will email user to get email verification, to edit account before assignments occur. echo "<tr><td width=40% align=right><strong>E-Mail Address</strong></td><td width=60% align=center>$rowteam[email]</td></tr>"; echo "<tr><td width=40% align=right><strong>Registration Date</strong></td><td width=60% align=center>$rowjos[registerDate]</td></tr>"; // Add script for lead only view age. Team Member, field is hidden. Lead sees birthdate and/or age and a YES/NO if age matches. If not, lead will email user with ID verification e-mail, to verify age before assignments occur. echo "<tr><td width=40% align=right><strong>Age</strong></td><td width=60% align=center>$rowteam[age]</td></tr>"; }} echo "</table>"; } else { echo "Invalid URL. Registration does not exist"; } ?> This code is included within this page: viewregistration.php Code: [Select] <?php session_start(); $user_id = $_SESSION['user_id']; $uid = $_GET['u_id']; $appid= $_GET['appid']; include ("db.php"); $get = mysql_query ("SELECT * FROM registrations WHERE u_id = $uid AND appid=$appid", $link2); echo $get; ?> <!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=windows-1252" /> <title>Nuke Ice By ThemeKings</title> <link rel="stylesheet" type="text/css" href="nuke-ice.css" /> </head> <body> <div id="wrapper"> <div id="banner"> <div id="banner-edit"></div> </div> <div id="container"> <?php include ("sidebar.php"); ?> <div id="col-2"> <?php $uid = $_GET['uid']; $appid= $_GET['appid']; ?> <div class="CntBox"> <div class="CntHead"> <div class="CntHeadInfo">User Information</div> </div> <div class="CntFill"> <div class="CntInfo"> <?php include ("./source/userinfo.php"); ?> </div> </div> <div class="CntFooter"></div> </div> I included this bit of code so you can see some of the variables that were assigned in another file. Problem: my checkbox array chkBrand[] is not saving data when I click the save button called cmdSave. Each checkbox specifies a brand connected to a model number. Multiple brands can be connected to each model number. (Don't ask, it's what the customer wants.) So, if I check the checkbox in row 0 and row 3, only row 0 shows up. If I check the boxes in row 0, 1, 5, only rows 0, 1 show up in chkBrand and $newchkbrandarr. First, my routine to see which button is checked is at the top of the php file. Here it is. else if (isset($_POST['cmdSave'])) //Try to save items first. { $newchkbrandarr=$_POST['chkBrand']; //Checkbox for each brand. $oldchkbrandarr=$_SESSION['oldchkbrandarr']; $olddata=$_SESSION['olddata']; //Non-brand Fields strung together. $brandlist=$_SESSION['brandlist']; //List of brands displayed. crPrintarr('chkBrand raw',$_POST['chkBrand']); //DEBUG. Prints array to screen. //===At this point chkBrand[] contains: 1 //Turn nulls in checkboxes to zeros. $cnt=count($newchkbrandarr); for ($j=0; $j<$cnt; $j++) { $newchkbrandarr[$j]=$newchkbrandarr[$j]+0; } //for j //Make sure that at least one brand is checked. $cnt=count($newchkbrandarr); crPrintarr('newchkbrandarr',$newchkbrandarr); //DEBUG //===At this point, $newchkbrandarr contains: 1, 0 $s='Elements in newchkbrandarr cnt='.$cnt; $s.=', count brandlist='.count($brandlist); crDebug($s); //DEBUG $cnt2=0; $cnt=count($newchkbrandarr); //Find number of elements. for ($j=0; $j<$cnt; $j++) { $cnt2=$cnt2+$newchkbrandarr[$j]+0; //$s='arrpos '.$j.': newchkbrandarr='.($newchkbrandarr[$j]+0).', cnt2='.$cnt2; //crDebug($s); //DEBUG } # for j Here is my code to construct the array of checkboxes, one per table row. Each checkbox has its array position explicitly defined as $x. $x starts at zero, and is incremented by 1 for each table row (each check box). $x=0; while ($row = mysqli_fetch_array($result)) { $br=trim($row['brand']); //Brand name to display $brandvar=$br; $brandlist[]=$br; //Save every found brand for later. //First find if brand is checked on table "brands". $query2 = "SELECT brand ". "FROM brands ". "WHERE ". "(partid=".$partidvar.") ". "AND (brand='".$br."') ". "ORDER BY brand ". ";"; $cntchk=crqryCount($query2,false); //If $cntchk>0 then brand is checked. //$s="Is brand stored already? <br/>$query2"; //crDebug($s); //DEBUG $query2 = "SELECT brand ". "FROM zzbrands ". "WHERE (brand='".$br."') ". "AND (prodnameoverride=1) ". "ORDER BY brand ". ";"; $override=crqryCount($query2,false); //Can this brand override product name? $s="\n"; $s.='<tr><td>'. '<input type="text" value="'.$br.'" id="txtBrand[]" name="txtBrand[]" '. 'size="20" readonly class="mydisabled" />'; $s.='<td align="center">'; $s.='<input type="checkbox" name="chkBrand['.$x.']" '. 'id="chkBrand['.$x.']" value="1" '; if ($cntchk>0) { $s.='checked="checked" '; $oldchkbrandarr[$x]=1; } else { $oldchkbrandarr[$x]=0; } $s.='/>'; Any ideas what I might be missing? I have a db table with 1500 street names inside - id, tfare, ptown, pcode, area. The 'area' column is specific to the company i work for and each street belongs to an 'area' number defined by the company. Currently each area is '0' - unassigned. The company areas are numbered 1 - 18. I need to list each street (LIMIT 10 at a time), and have an input box for the area to be edited and saved. The following code works perfectly well when dealing with 1 record at a time (LIMIT 0, 1), but breaks when i change the LIMIT to 10. I'm trying to show the dinosaur management that we need to upgrade our paper, yes, paper system to computers. I'm a transport manager, but in my spare time since 2004 I'm fluent in HTML and CSS, but only in the last few months really decided to give PHP and MySQL a *real* go. I'm 'guessing' I need to look into arrays for this to work? I've tried searching about but I dont even know how to articulate what i need to search for, so I have to publicly ask for help via this long winded post, sorry Here is my code: <?php include($_SERVER['DOCUMENT_ROOT'].'/!SYSTEM/bootstrap.php'); if(isset($_POST['savearea'])) { $id = $_POST['hideID']; $area = $_POST['area']; $sql = "UPDATE bmth_streetindex SET area='$area' WHERE id='$id'"; if ($query = mysql_query($sql)or die(mysql_error())) { print "saved ???"; } } // grab data from bmth street index where the area is = 0 (which means its area is un-assigned) $sql = "SELECT * FROM bmth_streetindex WHERE area='0' LIMIT 0, 10"; $rs = mysql_query($sql) or die(mysql_error()); print $HTML::form('action="" name="inputAreaForm" method="POST"')."\n\n"; // 'while' thru and print them 1 at a time while($row = mysql_fetch_array($rs)) { $id = $row['id']; $tfare = $row['tfare']; $ptown = $row['ptown']; $pcode = $row['pcode']; $area = $row['area']; $urlQ = $tfare. ", " .$ptown. ', ' .$pcode; print "<div>\n"; print "\n<input type=\"hidden\" name=\"hideID\" value=\"$id\">"; print "\n[$id] $tfare, $ptown, $pcode "; print "\nArea <input type=\"text\" name=\"area\" value=\"$area\" />"; print "\n<input type=\"submit\" name=\"savearea\" value=\"Save Area\">"; print "\n<a href=\"http://www.google.com/maps?q=$urlQ&hl=en&ie=UTF8&z=17\" target=new>SHOW ON MAP</a>"; print "\n<>\n<hr>\n\n"; } print $HTML::endForm(); ?> Thank you for taking the tie to read this, I hope someone can point me in the right direction for what i need to look into making this work The code here is suppose to allow the user to match up a word ($word) with a list of definitions ($word_defs). I can't get the list of definitions to stick. When the user does make a guess it shows that he is always correct. How can i fix these problems? Outside entry code: Code: [Select] <?php require_once "include/session.php"; require_once "include/word_defs.php"; $word = array_keys($word_defs); $word_defs = array_unique(array_values($word_defs)); $params = (object) $_REQUEST; $session = new Session(); if (isset($params->guess)) { $word = $params->word; if ( $params->word == $word_defs[$term] ) { $response = "correct"; } else { $response = "incorrect"; } $choices->word_def[$params->word_def] = "selected"; } else { $word = $word[ rand( 0, count($word)-1 ) ]; } ?> Body code: Code: [Select] word: <?php echo $word ?> <form action="?" method="get"> definition: <select name="word_defs"> <?php foreach ($word_defs as $word_def): ?> <option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option> <?php endforeach ?> </select> <input type="submit" name="guess" value="Guess" /> <input type="hidden" name="word" value="<?php echo $word?>" /> </form> <h3><?php echo $response ?></h3> Hi All,
I'm new to PHP (not to coding) - and I've been able to bang out most answers using books, the web and brue force - but this one has me stumped.
(If it's been covered before, sorry, I'm being lazy for not searching)...
So, here's the problem:
I have a call to my internal system that returns XML data via a SOAP call.
The call works great - data is returned as I would expect.
Like I've read, I put said data into a variable usng simpleXML like this: $xml = simplexml_load_string($response3); ($response3 being where the raw data is)
When I do a var_dump of $xml, I get this:
SimpleXMLElement Object ( [ICProductAvailByWhseResult] => SimpleXMLElement Object ( [errorMessage] => SimpleXMLElement Object ( ) [arrayAvailability] => SimpleXMLElement Object ( [ICProductAvailByWhse.output.Availability] => Array ( [0] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) [1] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) [2] => SimpleXMLElement Object ( [productCode] => xxx [description1] => yyy [description2] => zzz [warehouse] => aaa [netAvailable] => bbb ) **** Edited, I got real data, not xxx,yyy, etc... **** Now the issue: It seems like I have everything in place - all I need now is to get my data off to variables for display. I've tried everything I can think of and I just can't seem to get it. I ran $xml->getName() and it gave me: ICProductAvailByWhseResult So, simple I think, I should be able to print something like $xml->ICProductAvailByWhseResult[0]->warehouse and I should get something, right? Nope. So I try $xml->ICProductAvailByWhseResult[1]->warehouse and I get a notice that I'm trying to get to a property of a non-object. What am I missing? I come from a VB backgound, so I understand array's and such - but this one has be stumped. And help would be greatly appreciated... Thanks!! |