PHP - Null Result Set Being Returned
Need some help finding out why this is returning a null result set:
The below code is giving me a result set of an integer set to "0" (the id), a "word"and "def" both set to NULL. It's failing at my "Error #2" point. var_dumps on $id, $word, and $def all give the null output. Each $category is being shown when I var_dump($category).
I know this shouldn't be the case because when I run this straight in PHPMyAdmin I get a non-null result set.
(Not sure why my indentation is not carrying over to the forum. Sorry about that.)
<?php session_start(); if(!isset($_SESSION['loopcatch']) || $_SESSION['loopcatch']==null || !is_int($_SESSION['loopcatch'])){ $_SESSION['loopcatch']=0; } if($_SESSION['loopCatch'] > 1){ //Email error die(); } require 'dbConnect.php'; $categories=array('business', 'music', 'film', 'drum'); //Pull Quotes //Query to Pull random quote $mainQuery="SELECT `r1`.`id`, `r1`.`word`, `r1`.`def` FROM `dictionary` AS `r1` JOIN (SELECT (RAND() * (SELECT MAX(`id`) FROM `dictionary`)) AS `id`) AS `r2` WHERE `r1`.`id` >= `r2`.`id` AND `category`=? AND `checked`=0 ORDER BY `r1`.`id` ASC LIMIT 1"; //prepare quotes query if($prepareQuote=mysqli_prepare($conn, $mainQuery)){ //filter through each category foreach($categories as $category){ //Bind the variable to the quotes query mysqli_stmt_bind_param($prepareQuote, "s", $category); //execute quotes statement mysqli_stmt_execute($prepareQuote); //Store quotes result set mysqli_stmt_store_result($prepareQuote); //Check how many rows are returned if(mysqli_stmt_num_rows($prepareQuote) > 0){ //Bind results to variables mysqli_stmt_bind_result($prepareQuote, $id, $word, $def); //If $id, $word, or $def is null abort and email error if(!is_null($id) && is_numeric($id) && !is_null($word) && !is_null($def)){ while($row=mysqli_stmt_fetch($prepareQuote)){ mysqli_autocommit($conn, FALSE); //Input into second table $updateQuery="UPDATE `quotes` SET `word`=?, `def`=? WHERE `category`=?"; //prepare insert query if($updateQuote=mysqli_prepare($conn, $updateQuery)){ //Bind the variables to the insert query mysqli_stmt_bind_param($updateQuote, "sss", $word, $def, $category); //execute insert statement mysqli_stmt_execute($updateQuote); //Store insert quote result set mysqli_stmt_store_result($updateQuote); //Check how many rows are returned on insert quote query if(mysqli_stmt_affected_rows($updateQuote) > 0){ //If query run sucessfully insert and update; if not rollback. //mark quote checked $checkedQuery="UPDATE `dictionary` SET `checked`=1 WHERE `id`=?"; //prepare checked query if($checkedQuote=mysqli_prepare($conn, $checkedQuery)){ mysqli_stmt_bind_param($checkedQuote, "i", $id); //execute checked statement mysqli_stmt_execute($checkedQuote); //Store checked quote result set mysqli_stmt_store_result($checkedQuote); //Check how many rows are returned on checked quote query if(mysqli_stmt_affected_rows($checkedQuote > 0)){ mysqli_commit($conn); } else{ echo 'Error #6 '; mysqli_rollback($conn); } } else{ echo 'Error #5'; //Email error die(); } } else{ echo 'Error #4'; mysqli_rollback($conn); } } else{ echo 'Error #3'; //Email error die(); } } } else{ echo 'Error #2'; //Query returned blank result set - Email Error } } else{ //If zero rows returned, uncheck rows in table for that specific category and re-run the query. $uncheckQuery="UPDATE `dictionary` SET `checked`=0 WHERE `category`=?"; if($uncheckQuotes=mysqli_prepare($conn, $uncheckQuery)){ //Bind the variable to the query mysqli_stmt_bind_param($uncheckQuotes, "s", $category); //execute statement mysqli_stmt_execute($uncheckQuotes); //Store result set mysqli_stmt_store_result($uncheckQuotes); //Check how many rows are returned if(mysqli_stmt_affected_rows($uncheckQuotes) > 0){ $_SESSION['loopCatch']++; header("Location: ./pullDailyQuotes.php"); } else{ //Email error } } } } } else{ //Email error echo 'Error #1'; die(); } ?> Edited by HDRebel88, 01 June 2014 - 08:54 PM. Similar TutorialsHello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible. I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. Hi all !
I have a piece of code he
$result = display_all(fcon, $var1, $var2); function display_all( // defined in another file $query = "SELECT one, two, three four, index1, index2 FROM numbers WHERE index1 = $var1 LIMIT 0, 1"; $result = mysqli_query($fcon, $query); return ($result); )and then I use the returned variable $result to display the value as follows:- while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>".$one."</td>"; echo "<td>".$two."</td>"; echo "<td>".$three. "</td>"; echo "<td>".$four. "</td>"; echo "<td>".$index1. "</td>"; echo "</tr>"; }and this displays the n rows of data returned. Now I have started using prepared statements and the function is now function display_all{ $query = "SELECT one, two, three four, index1 FROM numbers WHERE index1 = ? LIMIT 0, 10"; $stmt = $conn->prepare($query); $stmt->bind_param('i',$var) if($stmt->execute()) { $stmt->bind_result($one, $two, $three, $four, $index1); $stmt->store_result(); } return($stmt); }However the returned $stmt object is unable to display the n rows of data since it shows null values. I assume that this is not the right way to use the $stmt object to display data. I must be missing something. So I request you guys to help me with this. Thanks loads. Edited by ajoo, 23 December 2014 - 11:24 AM. hi all, i have a script in where the user enters there post code and it will provide a price for delivery, how would i echo "please contact us for price" if the db record for the price is (null) or empty?? <?php mysql_connect ("localhost", "root","password") or die (mysql_error()); mysql_select_db ("postcode"); $term = $_POST['term']; $sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large "); while ($row = mysql_fetch_array($sql)){ echo '<br/> Postcode: '.$row['postcode']; echo '<br/> Town: '.$row['town']; echo '<br/> County: '.$row['county']; echo '<br/> Small: £'.$row['price_s']; echo '<br/> Medium: £'.$row['price_m']; echo '<br/> Large: £'.$row['price_l']; echo '<br/><br/>'; } ?> Hi, I have results from a MySQL table column which does an echo into a table cell, but some of the results from the table column is be empty, so is there a way to fill in the blanks with text like "No data"?
I am trying to update the database with isset to set the value of the variable to either null or the value entered by the user. Currently, if no value has been entered null is being set as a string causing the date field to populate with zeros. How do I code it so that it populates or sets the value as null and not as string null?
Here's my code: (yes I know sql injections it's still in development )
<?php I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? When I submit the login form its not returning anything and it was working until I added in the $remember part so I'm wondering why its still not returning TRUE. Code: [Select] /** * Login user on the site. Return TRUE if login is successful * (user exists and activated, password is correct), otherwise FALSE. * * @param string * @param string * @param int * @return bool */ function login($username, $password, $remember) { $this->ci->load->model('kow_auth/users'); $user_data = $this->ci->users->get_user_by_username($username); if ($user_data) { $regenFromPostPW = $this->ci->genfunc->reGenPassHash($password, $user_data->password2); if ($regenFromPostPW == $user_data->password) { $this->ci->session->set_userdata(array( 'xtr' => 'yes', 'user_id' => $user_data->user_id, 'username' => $user_data->username, 'status' => $user_data->users_statuses_id, 'role' => $user_data->users_roles_id )); if ($remember == 1) { $timeTOexpire = time()+(60*60*24*31*2); $this->input->set_cookie('xtrcook', '1', $timeTOexpire); } else { $cookie = trim(get_cookie('xtrcook')); if ($cookie || is_numeric($cookie)) { delete_cookie('xtrcook'); } } $this->clear_login_attempts($user_data->user_id); $this->ci->users->insert_session($this->ci->session->userdata('session_id'), $this->ci->session->userdata('user_id'), $this->ci->genfunc->getRealIpAddr(), $this->ci->genfunc->getUserOS()); return TRUE; } else { $this->increase_login_attempt($user_data->user_id); } } else { return NULL; } } Am currently using this code, and actually thinking about it should split the query to an include in order to allow for other database drivers, on the chance we may decide to ditch the old MySQL. But I digress from the question. Code: [Select] include($lib."dbconfig.php"); $q = 'SELECT * FROM file WHERE this = "'.$that'"; $result = mysql_query($q); if (mysql_num_rows($result) > 0) If the query doesn't pick up a row I'm getting this error yo, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\webpages\*\*\admin.php on line 553 So what would be a better way of testing if the query was successful? It's been quite a while since I have coded in PHP and I am running into difficulties looping through the returned response from an API. I am pretty comfortable in my PHP skills, but for some reason I keep getting caught up trying to loop through the following... Many of the returns from the API include several more layers of Objects, the example below is about the most simplistic return from the API.
I'm sure I'm just missing something easy and any help or example code simply looping through and echoing each result would be greatly appreciated!! Ideally I would like to be able to loop through both of the scenarios below.
I did a var_dump on the response and here is what I get:
array (size=1) 'Body' => object(stdClass)[6] public 'userContext' => object(stdClass)[8] public 'convCred' => object(stdClass)[10] ... public 'valid' => boolean true public 'isPasswordExpired' => boolean false public 'cbId' => int 0083802121 public 'cnId' => int 1000545 public 'locale' => string 'en_US' (length=5) public 'tncVersion' => int 2 public 'applicationId' => string 'ECFDA1FDBC00270772870CDC1786FFED' (length=32) public 'cbConvCred' => object(stdClass)[9] ... public 'preferenceInfo' => object(stdClass)[7] ... public 'lastLoginTime' => int 1406729928 public 'loginCount' => int 282 public 'passwordRecovered' => boolean false public 'emailAddress' => string 'abc@123.com' (length=11) public 'loginName' => string 'TEST' (length=8) public 'userId' => int 15932274 public 'userType' => object(stdClass)[14] public 'userTypeId' => int 1 public 'userTypeName' => string 'normal_user' (length=11) public 'isConfirmed' => boolean falseIf I jsonencode and jsondecode the response this is what I get: object(stdClass)[13] public 'Body' => object(stdClass)[17] public 'userContext' => object(stdClass)[18] public 'convCred' => object(stdClass)[19] ... public 'valid' => boolean true public 'isPasswordExpired' => boolean false public 'cbId' => int 0083802121 public 'cnId' => int 1000545 public 'locale' => string 'en_US' (length=5) public 'tncVersion' => int 2 public 'applicationId' => string 'ECFDA1FDBC00270772870CDC1786FFED' (length=32) public 'cbConvCred' => object(stdClass)[20] ... public 'preferenceInfo' => object(stdClass)[21] ... public 'lastLoginTime' => int 1406729953 public 'loginCount' => int 283 public 'passwordRecovered' => boolean false public 'emailAddress' => string 'abc@123.com' (length=11) public 'loginName' => string 'TEST' (length=8) public 'userId' => int 15932274 public 'userType' => object(stdClass)[24] public 'userTypeId' => int 1 public 'userTypeName' => string 'normal_user' (length=11) public 'isConfirmed' => boolean false Hi all, I really need some help getting values from the usps api Well not getting them but using them. I get the values but I need to extract the info to use in a form. This is the class im using Code: [Select] <?php require_once("xmlparser.php"); class USPS { var $server = "http://testing.shippingapis.com/ShippingAPITest.dll"; var $user = "****"; var $pass = "****"; var $service = ""; var $dest_zip; var $orig_zip; var $pounds; var $ounces; var $container = "None"; var $size = "REGULAR"; var $machinable; var $country = "USA"; function setServer($server) { $this->server = $server; } function setUserName($user) { $this->user = $user; } function setPass($pass) { $this->pass = $pass; } function setService($service) { /* Must be: Express, Priority, or Parcel */ $this->service = $service; } function setDestZip($sending_zip) { /* Must be 5 digit zip (No extension) */ $this->dest_zip = $sending_zip; } function setOrigZip($orig_zip) { $this->orig_zip = $orig_zip; } function setWeight($pounds, $ounces=0) { /* Must weight less than 70 lbs. */ $this->pounds = $pounds; $this->ounces = $ounces; } function setContainer($cont) { $this->container = $cont; } function setSize($size) { $this->size = $size; } function setMachinable($mach) { /* Required for Parcel Post only, set to True or False */ $this->machinable = $mach; } function setCountry($country) { $this->country = $country; } function getPrice() { if($this->country=="USA"){ // may need to urlencode xml portion $str = $this->server. "?API=RateV2&XML=<RateV2Request%20USERID=\""; $str .= $this->user . "\"%20PASSWORD=\"" . $this->pass . "\"><Package%20ID=\"0\"><Service>"; $str .= $this->service . "</Service><ZipOrigination>" . $this->orig_zip . "</ZipOrigination>"; $str .= "<ZipDestination>" . $this->dest_zip . "</ZipDestination>"; $str .= "<Pounds>" . $this->pounds . "</Pounds><Ounces>" . $this->ounces . "</Ounces>"; $str .= "<Container>" . urlencode($this->container) . "</Container><Size>" . $this->size . "</Size>"; $str .= "<Machinable>" . $this->machinable . "</Machinable></Package></RateV2Request>"; } else { $str = $this->server. "?API=IntlRate&XML=<IntlRateRequest%20USERID=\""; $str .= $this->user . "\"%20PASSWORD=\"" . $this->pass . "\"><Package%20ID=\"0\">"; $str .= "<Pounds>" . $this->pounds . "</Pounds><Ounces>" . $this->ounces . "</Ounces>"; $str .= "<MailType>Package</MailType><Country>".urlencode($this->country)."</Country></Package></IntlRateRequest>"; } $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $str); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // grab URL and pass it to the browser $ats = curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); $xmlParser = new xmlparser(); $array = $xmlParser->GetXMLTree($ats); //$xmlParser->printa($array); if(count($array['ERROR'])) { // If it is error $error = new error(); $error->number = $array['ERROR'][0]['NUMBER'][0]['VALUE']; $error->source = $array['ERROR'][0]['SOURCE'][0]['VALUE']; $error->description = $array['ERROR'][0]['DESCRIPTION'][0]['VALUE']; $error->helpcontext = $array['ERROR'][0]['HELPCONTEXT'][0]['VALUE']; $error->helpfile = $array['ERROR'][0]['HELPFILE'][0]['VALUE']; $this->error = $error; } else if(count($array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'])) { $error = new error(); $error->number = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['NUMBER'][0]['VALUE']; $error->source = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['SOURCE'][0]['VALUE']; $error->description = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['DESCRIPTION'][0]['VALUE']; $error->helpcontext = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['HELPCONTEXT'][0]['VALUE']; $error->helpfile = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['HELPFILE'][0]['VALUE']; $this->error = $error; } else if(count($array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'])){ //if it is international shipping error $error = new error($array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR']); $error->number = $array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['NUMBER'][0]['VALUE']; $error->source = $array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['SOURCE'][0]['VALUE']; $error->description = $array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['DESCRIPTION'][0]['VALUE']; $error->helpcontext = $array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['HELPCONTEXT'][0]['VALUE']; $error->helpfile = $array['INTLRATERESPONSE'][0]['PACKAGE'][0]['ERROR'][0]['HELPFILE'][0]['VALUE']; $this->error = $error; } else if(count($array['RATEV2RESPONSE'])){ // if everything OK //print_r($array['RATEV2RESPONSE']); $this->zone = $array['RATEV2RESPONSE'][0]['PACKAGE'][0]['ZONE'][0]['VALUE']; foreach ($array['RATEV2RESPONSE'][0]['PACKAGE'][0]['POSTAGE'] as $value){ $price = new price(); $price->mailservice = $value['MAILSERVICE'][0]['VALUE']; $price->rate = $value['RATE'][0]['VALUE']; $this->list[] = $price; } } else if (count($array['INTLRATERESPONSE'][0]['PACKAGE'][0]['SERVICE'])) { // if it is international shipping and it is OK foreach($array['INTLRATERESPONSE'][0]['PACKAGE'][0]['SERVICE'] as $value) { $price = new intPrice(); $price->id = $value['ATTRIBUTES']['ID']; $price->pounds = $value['POUNDS'][0]['VALUE']; $price->ounces = $value['OUNCES'][0]['VALUE']; $price->mailtype = $value['MAILTYPE'][0]['VALUE']; $price->country = $value['COUNTRY'][0]['VALUE']; $price->rate = $value['POSTAGE'][0]['VALUE']; $price->svccommitments = $value['SVCCOMMITMENTS'][0]['VALUE']; $price->svcdescription = $value['SVCDESCRIPTION'][0]['VALUE']; $price->maxdimensions = $value['MAXDIMENSIONS'][0]['VALUE']; $price->maxweight = $value['MAXWEIGHT'][0]['VALUE']; $this->list[] = $price; } } return $this; } } class error { var $number; var $source; var $description; var $helpcontext; var $helpfile; } class price { var $mailservice; var $rate; } class intPrice { var $id; var $rate; } ?> This is how Im getting the info Code: [Select] <?php require("usps.php"); $usps = new USPS; //http://production.shippingapis.com/ShippingAPI.dll //http://testing.shippingapis.com/ShippingAPITest.dll $usps->setServer("http://production.shippingapis.com/ShippingAPI.dll"); $usps->setUserName("****"); //Express, First Class, Priority, Parcel, Library, BPM, Media, or ALL $usps->setService("All"); $usps->setDestZip("21061"); $usps->setOrigZip("85284"); $usps->setWeight(4, 2); $usps->setContainer("Flat Rate Box"); $usps->setCountry("USA"); $usps->setMachinable("true"); $usps->setSize("Regular"); $price = $usps->getPrice(); print_r($price); ?>and that gives me this result Code: [Select] USPS Object ( [server] => http://production.shippingapis.com/ShippingAPI.dll [user] => **** [pass] => **** [service] => All [dest_zip] => 21061 [orig_zip] => 85284 [pounds] => 4 [ounces] => 2 [container] => Flat Rate Box [size] => Regular [machinable] => true [country] => USA [zone] => 8 [list] => Array ( [0] => price Object ( [mailservice] => Express Mail Hold For Pickup [rate] => 49.70 ) [1] => price Object ( [mailservice] => Express Mail [rate] => 49.70 ) [2] => price Object ( [mailservice] => Express Mail Flat Rate Envelope Hold For Pickup [rate] => 18.30 ) [3] => price Object ( [mailservice] => Express Mail Flat Rate Envelope [rate] => 18.30 ) [4] => price Object ( [mailservice] => Priority Mail [rate] => 18.35 ) [5] => price Object ( [mailservice] => Priority Mail Flat Rate Envelope [rate] => 4.95 ) [6] => price Object ( [mailservice] => Priority Mail Small Flat Rate Box [rate] => 5.20 ) [7] => price Object ( [mailservice] => Priority Mail Medium Flat Rate Box [rate] => 10.95 ) [8] => price Object ( [mailservice] => Priority Mail Large Flat Rate Box [rate] => 14.95 ) [9] => price Object ( [mailservice] => Parcel Post [rate] => 12.29 ) [10] => price Object ( [mailservice] => Media Mail [rate] => 4.05 ) [11] => price Object ( [mailservice] => Library Mail [rate] => 3.85 ) ) ) I would like to be able to just pull out some of the mailservice and rate portions to use them later on in the form, like say a dropdown box but I do not know how to just isolate each item. For instance turn that result into a 3 item select box with these options Express Mail - $49.70 Priority Mail - $18.35 Parcel Post - $12.29 Hope that makes sense. Any help appreciated. So I am accessing a web service and it returns a bunch of values, I am able to grab and print the first value, but I can't figure out how to print the second value. PHP Code that works Code: [Select] <?php //Web service that works fine $client = new SoapClient("http://www.domain.com/sc001.asmx?WSDL"); $sc001 = $client->$NT(array('var1'=>$var1)); //Grab the value tag and print it from web service call and in this case prints 001 $tag = $sc001->NTResult->results->TaggedText->tag; echo $tag; ?> But how do I get it to print the second tag that equals 120? I've tried this Code: [Select] <?php $tag2 = $sc001->NTResult->taggedResults->tag; ?> and this Code: [Select] <?php $tag2 = $sc001->NTResult->taggedResults->TaggedText->tag; ?> and this Code: [Select] <?php $tag2 = $sc001->NTResult->results->TaggedText->taggedResults->TaggedText->tag; ?> But neither work. The var_dump for is sc001 is: Code: [Select] object(stdClass)#9 (1) { ["NTResult"]=> object(stdClass)#10 (2) { ["count"]=> int(1) ["results"]=> object(stdClass)#11 (1) { ["TaggedText"]=> object(stdClass)#12 (2) { ["tag"]=> string(3) "001" ["taggedResults"]=> object(stdClass)#13 (1) { ["TaggedText"]=> array(27) { [0]=> object(stdClass)#14 (2) { ["tag"]=> string(4) "120" ["textArray"]=> object(stdClass)#15 (1) { ["string"]=> array(2) { [0]=> string(28) "Rocks " [1]=> string(14) "Big Rocks" } } } } } } } } } } } and the XML return from the service is: Code: [Select] <?xml version="1.0" encoding="utf-8" ?> - <TaggedTextArray xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.domain.com/sc001"> <count>1</count> - <results> - <TaggedText> <tag>001</tag> - <taggedResults> - <TaggedText> <tag>120</tag> - <textArray> <string>Rocks</string> <string>Big Rocks</string> </textArray> </TaggedText> Maybe the question is, how do you handle a SOAP returned array? I'm not sure, any help is appreciated. Thanks, sanchez Hi I have a couple of phpbb forums on my web space. One is randomly throwing people off and it is getting far worse. I have traced down the issue to the IP address. Phpbb stores the IP address and session id and checks that they match. If not it throws the user out. The session ids seem to be there OK, but the IP addresses aren't. When it causes a problem the IP address seems to be returned as "::" (yes, 2 colons). I have used the following routine to try and obtain a relevant IP address and it to returns "::" Code: [Select] function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } Any ideas? All the best Keith Hi guys, I am working with an old script at the moment, there is one page which just will not populate the table results. I have tried running multiple debugging commands but the only one it flags is the line displaying Quote last; saying it's not a used function. If I comment out this line, no errors are produced but the results do not enter the table. Can anyone shed some light on this please, I've spent hours and hours and banging my head against a brick wall would probably be more constructive right now. Many thanks indeed for any help or advice. <?php mysql_connect("localhost", "$db_user","$db_upwd") or die ("Error - Could not connect: " . mysql_error()); mysql_select_db("$database"); $query="select host,count(*) from badc_mis_prog group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); $count=0; $hosts=array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); array_push($hosts, $html_hlname,$row[1],0); $count++; } $query="select host,count(*) from badc_mis_prog where reported=1 group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); for ($i=0; $i<($count*3); $i+=3) { if ($hosts[$i] == $html_hlname) { $hosts[($i+2)]=$row[1]; last; } } } for ($i=0 ; $i<(($count-1)*3); $i+=3){ for ($j=$i+3 ; $j<($count*3); $j+=3){ if ($hosts[($i+1)] < $hosts[($j+1)]){ $temp=array(); $temp[0]=$hosts[$i]; $temp[1]=$hosts[($i+1)]; $temp[2]=$hosts[($i+2)]; $hosts[$i]=$hosts[$j]; $hosts[($i+1)]=$hosts[($j+1)]; $hosts[($i+2)]=$hosts[($j+2)]; $hosts[$j]=$temp[0]; $hosts[($j+1)]=$temp[1]; $hosts[($j+2)]=$temp[2]; } } } print "<br><br><br><center><table border=\"1\">\n"; print "<tr><td>Host Name</td><td>Hosted</td><td>Reported</td><td>Ratio H/R</td></tr>\n"; for ($i=0; $i<($count*3); $i+=3) { if ($hosts[($i+1)]<15){ break;} printf ("<tr><td> %s </td><td> %d </td><td> %d </td><td>%.1f %%</td></tr>\n",$hosts[$i],$hosts[($i+1)],$hosts[($i+2)],(($hosts[($i+2)]/$hosts[($i+1)])*100)); } print "</table></center>\n"; ?> if i want to display upcoming events and only want to show the top 3? Hello. I am interested in taking a result returned from a database and having it displayed in a certain way/style on the user's screen; For example, the user enters text into a field and hits "submit" - the data is saved in the database then displayed to the user (This part I have working just fine so far due to help I received here.) My question is if I would like to, for example, have said text not simply dumped to the top of the screen, inline, but nicely formatted in a boxed, text area, I assume I will use HTML/CSS, and I was wondering if anyone had any good links/tutorials regarding this topic so I may look further into it (my search thus far has not turned up the correct topic or results). Thank-you in advance for any assistance. ~Matty Probably a silly question, but say you have a value in a mysql database that (naturally) can be either be blank or have characters in it. If in my PHP I am doing a check to see if that returned field from the database HAS or DOES NOT HAVE a value entered in it, what is the proper way to do it? For example, you could do either of the following below (and I'm sure there are probably 10 other ways to do it as well). Is one of these quicker/more efficient than the other? I know it probably does not matter in the grand scheme of things because it's such a quick check either way, but if one way is more "proper" than the other, please let me know... Code: [Select] if ($mysqlvalue!=="") OR if (strlen($mysqlvalue>0)) OR Have a web page that displays a number of update forms depending on the amout of records that get returned from a mysql query, if query returns 4 records then the page will display 4 identical forms, the trouble i'm having is getting the each of the 4 forms to display a different record as at the moment they all show just first record of query. I have played around with loops but not getting anywhere which may be due to my limited knowledge code for page is below Code: [Select] <?php $numberofrow =mysql_num_rows($Recordset1); for($counter = 1;$counter<=$numberofrow;$counter++){ ?> <label for="hometeam2"></label> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <label for="hometeam"></label> <input name="fixid" type="text" id="fixid" value="<?php echo $row_Recordset1['FixtureID']; ?>" /> <input name="hometeam" type="text" id="hometeam2" value="<?php echo $row_Recordset1['hometeamname']; ?>" /> <label for="homescore"></label> <input name="homescore" type="text" id="homescore" value="<?php echo $row_Recordset1['homescore']; ?>" /> <label for="awayscore"></label> <label for="fixid"></label> <input name="awayscore" type="text" id="awayscore" value="<?php echo $row_Recordset1['awayscore']; ?>" /> <label for="awayteam"></label> <input name="awayteam" type="text" id="awayteam" value="<?php echo $row_Recordset1['awayteamname']; ?>" /> <input type="submit" name="update" id="update" value="Submit" /> <input type="hidden" name="MM_update" value="form1" /> Hello, I'm new on this forum and i have not seen the rules to post a code, so i will try to explain my best : I have learned the basics of php during the past few days and i have a php code that is supposed to read parameters in several fields of a Mysql database and to return those parameters as variables in an array. (well that's how i understand it... please correct me if i'm wrong) So here the code and the part that doesn't seem to work properly (colored in red) : //I have changed the following values which are confidential... $DBName = "MyDatabase"; $DBHostName = "MyMysqlServer"; $DBUserName = "MyUsername"; $DBPassword = "MyPassword"; $Table = "MyTable"; //The fields which are in MyTable : // MemberID SMALLINT // MemberName VARCHAR(20) // MemberPassword VARCHAR(20) // MemberEmailAddress VARCHAR(50) // MemberDateTimeInscription VARCHAR(19) //Reading member parameters echo"<br>Reading the parameters of a member."; echo"<br>Defining the parameters of the member to read."; $CurrentName = "Ashley"; $CurrentPassword = "65hl3y"; $CurrentEmailAddress = "Ashley@HisDomain.com"; echo"<br>Trying to start a connection with the Mysql server."; mysql_connect($DBHostName,$DBUserName,$DBPassword) OR DIE(mysql_error()); echo"<br>Selecting the table."; mysql_select_db($DBName) OR DIE(mysql_error()); echo"<br>Searching for the fields corresponding to the CurrentName."; $Query = "SELECT * FROM ".$Table." WHERE MemberName = '".$CurrentName."'"; $Result = mysql_query($Query) or die(mysql_error()); echo"<br>Returning the parameters stored in the fields."; while($Row = mysql_fetch_array($Result,MYSQL_ASSOC)){ /////This is the start of the part that does not seem to work properly. $MemberId = $row["MemberId"]; $MemberName = $row["MemberName"]; $MemberPassword = $row["MemberPassword"]; $MemberEmailAddress = $row["MemberEmailAddress"]; $MemberDateTimeInscription = $row["MemberDateTimeInscription"]; echo"<br>MemberId : ".$MemberId; echo"<br>MemberName : ".$MemberName; echo"<br>MemberPassword : ".$MemberPassword; echo"<br>MemberEmailAddress : ".$MemberEmailAddress; echo"<br>MemberDateTimeInscription : ".$MemberDateTimeInscription; /////This is the end of the part that does not seem to work properly. } echo"<br>Ending the connection with the Mysql server."; mysql_close(); All of echo are here for debug, i'm a beginner with php. This is what the php page shows : Reading the parameters of a member. Defining the parameters of the member to read. Trying to start a connection with the Mysql server. Selecting the table. Searching for the fields corresponding to the CurrentName. Returning the parameters stored in the fields. MemberId : MemberName : MemberPassword : MemberEmailAddress : MemberDateTimeInscription : Ending the connection with the Mysql server. I don't understand why the variables $MemberId, $MemberName, $MemberPassword, $MemberEmailAddress, $MemberDateTimeInscription are empty. Your advices are welcome, Thanks, |