PHP - Filter Same Data In An Array?
hi,
Im getting data from a database and store in an array. and there will be a lot of repeating data in the array. I would like to know if there is any function can filter the array and arrange in a nice position. or there's no way doing it and need to check it manually? appreciate for the help. thanks. Similar Tutorialsso I'm running a query on a database to get address's $address = $row['address']; it returns "1234 Test St" I want to be able to sort all the records by the street name without the numbers Hi,
I'm trying to make a program that filters data out of a website. Now I've got a problem.
For example, I've this line:
<td class="maintxt" width="200"><a href="profile.php?x=Stranger">Stranger</a></td><td class="maintxt" width="200">Godfather (96.76%)</td><td class="maintxt" width="200"><i><a href="clanprofile.php?x=Ettertjes">Ettertjes</a></i></td>Form this line I want to set the word "Stranger" in a variable, and do the same for the word "Godfather". What is the best method to do this? Thanks in advance, iRoot121 Hi All I have a script which imports values from a csv file created using excel. However there are several blank values within the file where the person creating it has used blank columns to create whitespace in the file. I have used array_filter to remove these from the array, however how do I remove the redundant keys and 'squash' everything together so it is nice and neat? eg import would be , ,id, , surname, ,firstname, ,DOB, , address, , which returns array after array_filter [1]-> id [3]->surname [5]->firstname [7]->DOB [9]->address I want to return as an array which would be Quote [0]-> id [1]->surname [2]->firstname [3]->DOB [4]->address Is there a function to do this or would I need to create a custom one? Hi ! I have an 2d array like this: column 1 column 2 column 3 $data[0][0] $data[0][1] $data[0][2] $data[0][0] RDR -1.3 0.001 $data[1][0] RQR 0.4 0.01 $data[2][0] DDR 1 0.00004 and more... Now i need to filter this data. I only need the rows with column 3 < 0.01 AND column2 > 1 or column 2 < -1 . I have this, but it doesn't work: $teller = 0; for($i = 0; $aantal>$i; $i++) { if($data[$i][2]<=0.01) { $p[$teller][0] = $data[$i][0]; $p[$teller][1] = $data[$i][1]; $p[$teller][2] = $data[$i][2]; $teller++; } } $teller2 = 0; for($i = 0; $teller>$i; $i++) { if($p[$i][1] < -1 || $p[$i][1] > 1 ) { #als de p value kleiner is dan 0.01 dan alles kopieren in een nieuwe array $r[$teller2][0] = $p[$i][0]; $r[$teller2][1] = $p[$i][1]; $r[$teller2][2] = $p[$i][2]; $teller2++; } } Can you help me? Hi - I am uploading Post variables off a form relating to products and customer orders. If a product has a quantity attached to it then all the POST variables relating to that product need to INSERTED into the DB. If a product has just an empty string in it's quantity variable, then that product does not get INSERTED. So I thought of 2 different approaches: A) I could filter the Quantity Post variable for a positive values then create a new array only containing products with positive quantities. B) I could loop through the product Id (ProdID) POST and using a condition pull out the products with a positive quantity for Insertion. I have been experimenting with B and have failed miserably. However I have succeeded excellently in building some code which INSERTS all the products regardless of their quantities ( see below ) - not ideal as it enters products with empty quantities. I would prefer to adapt what I have rather than throw it away. Can someone kind person give this student a hand with some advice in adapting what I have got ? MANY MANY THANKS ! Code: [Select] <?php function insert_tel_order(){ $lastname = $_POST['lastname']; $orderid = strtoupper(substr($lastname,0,3)).(substr(time(),-4)); //Creates a unique order number $customerid = $_POST['customerid']; $pickupdate = $_POST['pickupdate']; $deliverylocationid = $_POST['deliverylocationid']; $orderdate = $_POST['orderdate']; foreach ($_POST['prodid'] as $arrkey => $prodid){ $quantity = $_POST['quantity'][$arrkey]; $prodid = $_POST['prodid'][$arrkey]; $price = $_POST['price'][$arrkey]; $ordervalue = $quantity * $price; $sql =" INSERT INTO `order` (id, orderid,orderdate,customerid, deliverylocationid,pickupdate,prodid,price, quantity, ordervalue, status) VALUES ('', '$orderid',$orderdate,$customerid,$deliverylocationid,$pickupdate,$prodid,$price,$quantity,$ordervalue,'')"; $this->db->query($sql); } } ?> Hi guys, I'm trying to build an array to replicate the hierarchy in a menu: <ul> <li><a href="file1.html">text1</a></li> <ul> <li><a href="file2.html">text2</a></li> <li><a href="file3.html">text3</a></li> <li><a href="file4.html">text4</a></li> <li><a href="file5.html">text5</a></li> </ul> </ul> An i would like the output to be:
"text1" Here is my loop to go through the html hierarchy: foreach ($html2->find('ul') as $ul) { foreach ($ul->find('li') as $li) { foreach($li->find('a') as $a) { // need to filter out empty and index.html, tried if(!$->href = 'index.html) {do stuff} but didn't work $links2[] = $a->href ; $taxo2[] = $a->plaintext ; } } } This finds all the links but not the hierarchy, any ideas how to approach this? And also how to filter out blanks and references to index.html? Havent posted here in a while, been learning lots but im stuck on trying to unset/replace arrays that contain awkward key values.
[0] => 2021-06-02T19:40:00Z [1] => 2021-06-03T02:10:00Z [2] => 2021-06-03T01:10:00Z [3] => 2021-06-02T23:05:00Z [4] => 2021-06-02T23:05:00Z [5] => 2021-06-02T23:07:00Z [6] => 2021-06-02T23:20:00Z [7] => 2021-06-02T18:20:00Z [8] => 2021-06-03T00:10:00Z [9] => 2021-06-03T00:40:00Z The json Im using is constantly updated, not sure why tmrw's dates June 3rd are at the top for their API design =[ Not good at regex. preg_replace/etc. Im desperate id use array search manually if I knew how to simple parse out tmrw's dates. I have unlimited API calls so I reckon it don't matter, here's what Ive been playing with $oddsdata = 'https://pinnacle.datafeeds.net/api/json/odds/pinnacle/v3/60/baseball/mlb/moneyline?api-key=a71b8fe8e9eb957db549aaa5d99797a4'; $readodds = file_get_contents($oddsdata); $odds = json_decode($readodds, true); $today = date("Y-m-d"); $tmrw = date('Y-m-d', strtotime( $today . " +1 days")); foreach($odds['games'] as $key => $val): $gidRE[$key]["gid"] = $val["gameUID"]; $startOdds[$key]["start"] = $val["startDate"]; $homeTeams[$key]["hteam"] = $val["homeTeam"]; $awayTeams[$key]["ateam"] = $val["awayTeam"]; $Price[$key]["betPrice"] = $val["betPrice"]; $BookOdds[$key]["book"] = $val["sportsbook"]; $BetName[$key]["betName"] = $val["betName"]; $Live[$key]["Live"] = $val["isLive"]; endforeach; $endgidd = end(array_keys($gidRE)) + '1'; $endz = end(array_keys($odds['games'])); for ($l = 0; $l < $endz; ++$l) { $OddsAll[] = array_merge($gidRE[$l], $startOdds[$l], $homeTeams[$l], $awayTeams[$l], $Price[$l], $BetName[$l]); }
hi every1 im driveing crazy with this... i have a database with a field with descriptions of products named "DESCRIP" in the main page i have a text field where user write the words to search for i wanrt make an "SELECT * FROM models where descrip like xxx OR descrip like xxx... bla bla bla" i wrote this code but send me an error... waht can be wrong??? $word='"SELECT * FROM models WHERE descrip LIKE ' ."'"; $srched=$_POST['words']; $pieces = explode(" ", $srched); $all=count($pieces)-1; for($i=0;$i<=$all;$i ++) { $word = $pieces[$i] ."'"; if($i!=$all) { $word .= $word . ' OR descrip like ' . "'"; } else { $word .= $word .'"' . ";"; } } $colname=$word; mysql_select_db($database_zero1, $zero1); $query_srch = $colname; $buscar = mysql_query($query_srch, $zero1) or die(mysql_error()); $row_srch = mysql_fetch_assoc($srch); $totalRows_srch = mysql_num_rows($srch); tnx in advcd I am creating a football predictor game and have a table in the database to hod all my users i have written a query to pull all out the users that have made a prediction that day with their predictions made i have put this into an array so my array will hold all the user details 1 being their userId I have set the order by on the query to userId so I get all the same users predictions in 1 block. I now want to extract all the predictions for each user and put these into their own array but I don't know which users the array will hold, how many users their will be, or how many predictions each user would have made so i'm not sure how to create this array i'm quite new to php can anyone help me with this Hi, i'm new here and hope i've finally found a forum where i can find the perfect solution for my questions.
Well since a year now i started to work with PHP and still now and then there are some things where i seize on. My question is on of those situations.
I have the following code:
if (isset($_POST)){ foreach ($_POST as $key => $value){ if (!empty($value)){ $update_rma_detail_stmt = $dbh->prepare("UPDATE rma_detail SET $key = ? WHERE rd_rma_nr = ?"); $update_rma_detail_stmt->bindParam(1, $value); $update_rma_detail_stmt->bindParam(2, $getadmrmaid); $update_rma_detail_stmt->execute(); } } }All i want is when there is an empty (not filled in) input field because it is not mandatory the foreach still continuous to the end. When i use if (!empty($value)){It still outputs these error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ' ' However, when i dont use i got an other error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' It is however so that the datetime is the very first empty field it come across when looping. I think my if (!empty($value)){ is doing the right thing but still gives error's on integers. Can it be? I allready tried to use trim() or array_filter() but because i previously never used it i dont know if i am doing it the right way so any help is welkom! Thanks! Edited by Raz3rt, 20 May 2014 - 02:56 AM. Say I have this array: Code: [Select] array( 0 => time 1 => time 2 => to 3 => to 4 => to 5 => fly ); and 2 variables - $occMin and $occMax as number of occurrences. If: Code: [Select] $occMin = 2; $occMax = 3; I want to produce sorted list with most occurrences at the top: Code: [Select] array( 0 => array('to', 3), 1 => array('time', 2) ); My face just melted at the thought of even beginning to tackle this. Is this somewhat possible? would it require a monster function or am I missing some native php functions which could lend a hand? I'm creating a tool for building project proposals for clients, with pricing. I have a database with two tables: services and clients. The services table looks like this: Code: [Select] | code | name | cost | +-------------+-------------+------+ | logo_design | Logo design | 10 | | web_design | Web design | 20 | The clients table looks like this: Code: [Select] | id | client | logo_design | web_design | +----+---------+-------------+------------+ | 1 | Walrus | yes | yes | | 2 | Narwhal | no | yes | How would I link the results from these two tables so that I only pull out the services each person wants from the database? Here is what I have so far: Code: [Select] <? $sql = "SELECT * FROM services"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo $row{'name'} . ': $' . $row{'cost'} . '<br />'; } ?> This, of course, displays all the services, with all the prices, like so: Logo design: $10 Web design: $20 I want to add something here so that based on the selected client, we see only the services/prices they selected (ol' Narwhal's page would not show the "Logo Design" line). I've got the data from "clients" pulled in to this page as well, but don't know how to relate it to "services." Thanks in advance! Let me know if I've left out any info that would help you to point me in the right direction. Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. Using curl_multi, I have loaded up 3 url's and then printed the array. 1) How can I also set a timestamp on output to let me know when each url was run? 2) How can I explode the array to only display the data and timestamp, excluding the text "Array ( =>", "[1] =>", "[2] =>" and " )"? Code <?php function multiRequest($data, $options = array()) { // array of curl handles $curly = array(); // data to be returned $result = array(); // multi handle $mh = curl_multi_init(); // loop through $data and create curl handles // then add them to the multi-handle foreach ($data as $id => $d) { $curly[$id] = curl_init(); $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d; curl_setopt($curly[$id], CURLOPT_URL, $url); curl_setopt($curly[$id], CURLOPT_HEADER, 0); curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1); // post? if (is_array($d)) { if (!empty($d['post'])) { curl_setopt($curly[$id], CURLOPT_POST, 1); curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']); } } // extra options? if (!empty($options)) { curl_setopt_array($curly[$id], $options); } curl_multi_add_handle($mh, $curly[$id]); } // execute the handles $running = null; do { curl_multi_exec($mh, $running); } while($running > 0); // get content and remove handles foreach($curly as $id => $c) { $result[$id] = curl_multi_getcontent($c); curl_multi_remove_handle($mh, $c); } // all done curl_multi_close($mh); return $result; } $data = array(array(),array()); $data[0]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Pearl+Jam&output=json'; $data[1]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Black+Eyed+Peas&output=json'; $data[2]['url'] = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=Nirvana&output=json'; $r = multiRequest($data); print_r($r); ?> Output Array ( => Pearl Jam [1] => Black Eyed Peas [2] => Nirvana ) Preferred Output 01:00:01 Pearl Jam 01:00:02 Black Eyed Peas 01:00:03 Nirvana Hello, I have a variable called $Price, We are getting it through Mysql Database using While loop. We getting the data from database in ordered by ID. Now then i have requirement to store that data into Low to High form ... Like we are receiving $price lke unordered form .. 50 14 35 25 00 145 52 Here i just want to store it in Low to high form like 00, 14,25,35 ... and so on .. Please suggest me the appropriate code. While($myrow=mysql_fetch_array($result, MYSQL_ASSOC)) { some codes return value $price. // want to store in array } $array($price) // here want to store in Low to high with key value. Hi,
I'm working on a project and I've run into a problem and I can't seem to figure out how to fix it or even what is wrong no matter how much I google. I have data in an xml file that I need to read and use to create an array.
Here is the XML (food.xml):
<?xml version="1.0" encoding="UTF-8"?> I need to pull data out of google's merchant API. The resulting array I am getting is confusing me though and I am not sure how to pull the data I need from it. How would I get all the "name" fields out of the array or say product titles? Either to just print to screen or save to another variable? I'm currently pulling the data in the json format. Google offers both json and atom. I figured json would be easier? I thought I could just do something like $result['name'] but that doesn't seem to be working. Here's my code, and a snippet of the output. Code: [Select] <?php $result = json_decode(file_get_contents('https://www.googleapis.com/shopping/search/v1/public/products?key=key&country=US&q=digital+camera&alt=json'), true); echo "<pre>"; var_dump($result); echo "</pre>"; ?> [code] array(10) { ["kind"]=> string(17) "shopping#products" ["etag"]=> string(57) ""q_Cz93YRTLuwHgwpLYFnNN97DNM/Yat9tcRJVFxzoZmXA_0H3Qp-HuI"" ["id"]=> string(37) "tag:google.com,2010:shopping/products" ["selfLink"]=> string(125) "https://www.googleapis.com/shopping/search/v1/public/products?country=US&q=digital+camera&alt=json&startIndex=1&maxResults=25" ["nextLink"]=> string(126) "https://www.googleapis.com/shopping/search/v1/public/products?country=US&q=digital+camera&alt=json&startIndex=26&maxResults=25" ["totalItems"]=> int(833935) ["startIndex"]=> int(1) ["itemsPerPage"]=> int(25) ["currentItemCount"]=> int(25) ["items"]=> array(25) { [0]=> array(4) { ["kind"]=> string(16) "shopping#product" ["id"]=> string(66) "tag:google.com,2010:shopping/products/1113342/17031817732574057954" ["selfLink"]=> string(103) "https://www.googleapis.com/shopping/search/v1/public/products/1113342/gid/17031817732574057954?alt=json" ["product"]=> array(15) { ["googleId"]=> string(20) "17031817732574057954" ["author"]=> array(2) { ["name"]=> string(7) "Walmart" ["accountId"]=> string(7) "1113342" } ["creationTime"]=> string(24) "2011-07-07T18:51:04.000Z" ["modificationTime"]=> string(24) "2011-10-16T21:59:30.000Z" ["country"]=> string(2) "US" ["language"]=> string(2) "en" ["title"]=> string(66) "Canon Powershot Sx30-is Black 14.1mp Digital Camera W/ 35x Optical" ["description"]=> string(187) "Canon PowerShot SX30-IS 14MP Black Digital Camera:14.1 megapixel resolutionDelivers excellent picture quality24-840mm wide-angle zoom lensLets you get up close with the 35x optical zoom2." ["link"]=> string(117) "http://www.walmart.com/ip/Canon-14.1-MP-SX30/14972590?sourceid=1500000000000003142050&ci_src=14110944&ci_sku=14972590" ["brand"]=> string(5) "Canon" ["condition"]=> string(3) "new" ["gtin"]=> string(14) "00013803127348" ["gtins"]=> array(1) { [0]=> string(14) "00013803127348" } ["inventories"]=> array(1) { [0]=> array(5) { ["channel"]=> string(6) "online" ["availability"]=> string(7) "inStock" ["price"]=> float(349.99) ["shipping"]=> float(2.97) ["currency"]=> string(3) "USD" } } ["images"]=> array(1) { [0]=> array(1) { ["link"]=> string(71) "http://i.walmartimages.com/i/p/00/01/38/03/12/0001380312734_500X500.jpg" } } } } [1]=> array(4) { ["kind"]=> string(16) "shopping#product" ["id"]=> string(65) "tag:google.com,2010:shopping/products/3622330/1688520904457034451" ["selfLink"]=> string(102) "https://www.googleapis.com/shopping/search/v1/public/products/3622330/gid/1688520904457034451?alt=json" ["product"]=> array(15) { ["googleId"]=> string(19) "1688520904457034451" ["author"]=> array(2) { ["name"]=> string(11) "Apple Store" ["accountId"]=> string(7) "3622330" } ["creationTime"]=> string(24) "2010-10-21T20:31:02.000Z" ["modificationTime"]=> string(24) "2011-10-14T21:10:06.000Z" ["country"]=> string(2) "US" ["language"]=> string(2) "en" ["title"]=> string(39) "Canon PowerShot SX130 IS Digital Camera" ["description"]=> string(532) "Record In Stereo Sound, Then Play Back Your Videos Instantly On You Computer. The Sx130 Is Is All About Creativity, With Fun New Scene Modes Like Miniature Effect For Movies, And Fisheye Effect For Artistically Distorted Stills. While You're Having Fun Creating, The Camera's Smart Flash Exposure And Advanced Smart Auto Systems Are Ensuring That Every Image Is The Best It Can Be. Add The Digic 4 Image Processor, 12.1 Megapixels And Canon's Optical Image Stabilizer, And You've Got The Ideal Camera For Making The Good Times Last." ["link"]=> string(112) "http://store.apple.com/us/go/product/H2807ZM/A?aosid=p228&affiliateID=10262&cid=AOS-US-SHOPIP-Google&site=Google" ["brand"]=> string(5) "Canon" ["condition"]=> string(3) "new" ["gtin"]=> string(14) "00013803127386" ["gtins"]=> array(1) { [0]=> string(14) "00013803127386" } ["inventories"]=> array(1) { [0]=> array(4) { ["channel"]=> string(6) "online" ["availability"]=> string(7) "inStock" ["price"]=> float(229.95) ["currency"]=> string(3) "USD" } } ["images"]=> array(1) { [0]=> array(1) { ["link"]=> string(177) "http://storeimages.apple.com/1819/as-images.apple.com/is/image/AppleInc/H2807?wid=600&hei=600&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp" } } } } [2]=> array(4) { ["kind"]=> string(16) "shopping#product" ["id"]=> string(66) "tag:google.com,2010:shopping/products/1113342/13850367466326274615" ["selfLink"]=> string(103) "https://www.googleapis.com/shopping/search/v1/public/products/1113342/gid/13850367466326274615?alt=json" ["product"]=> array(15) { ["googleId"]=> string(20) "13850367466326274615" ["author"]=> array(2) { ["name"]=> string(7) "Walmart" ["accountId"]=> string(7) "1113342" } ["creationTime"]=> string(24) "2011-07-04T19:48:28.000Z" ["modificationTime"]=> string(24) "2011-10-16T21:59:30.000Z" ["country"]=> string(2) "US" ["language"]=> string(2) "en" ["title"]=> string(67) "Canon Powershot Sx130-is Black 12.1mp Digital Camera W/ 12x Optical" ["description"]=> string(599) "Canon PowerShot SX130-IS 12.1MP Digital Camera:12.1-megapixel resolutionDelivers excellent picture qualityWide-angle zoom lensLets you get up close with the 12x optical zoom3.0" widescreen LCD displayEnjoy easy focus selection and photo viewingShoot HD videoRecord movies in 720p HD format on the Canon black 12.1MP digital cameraSmart Flash Exposure PowerShot SX130-IS determines the correct flashUseful new scene modesMiniature Effect for movies and Fisheye for capturing imagesSmart AutoSelects the proper settings based on 28 predefined shooting situationsMulti-format memory slotCanon black 12." ["link"]=> string(219) "http://www.walmart.com/ip/Kodak-Playsport-Video-Camera-Value-Bundle-w-Bonus-4GB-Memory-Card-Camera-Yellow-Float-Strap-Rechargeable-Battery-Charger/14972582?sourceid=1500000000000003142050&ci_src=14110944&ci_sku=14972582" ["brand"]=> string(5) "Canon" ["condition"]=> string(3) "new" ["gtin"]=> string(14) "00013803127386" ["gtins"]=> array(1) { [0]=> string(14) "00013803127386" } ["inventories"]=> array(1) { [0]=> array(5) { ["channel"]=> string(6) "online" ["availability"]=> string(7) "inStock" ["price"]=> float(179.99) ["shipping"]=> float(2.97) ["currency"]=> string(3) "USD" } My aim is to make an enquiry form and its database name is ashish and table name is mydata...everytime i am inserting data and then displaying it on the browser with the use of print_r getting each input data twice...attacthing my code ..help me..thanx in advance this file is form.php <?php include("dbconnect.php"); include("cwfunction.php")?> <form name="form1" action="#" method="post"> Name<input name="stuname" type="text" value=""><br/> Address<input name="address" type="text" value=""><br/> Contact<input name="contact" type="text" value=""><br/> Email<input name="email" type="text" value=""><br/> Internet<input name="how" type="radio" value="internet"><br/> Friend<input name="how" type="radio" value="friend"><br/> Other<input name="how" type="radio" value="other"><br/> <input name="submit" type="submit" value="ENTER"><br/> </form> <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $stuname=$_POST['stuname']; $address=$_POST['address']; $contact=$_POST['contact']; $email=$_POST['email']; $how=$_POST['how']; insert_data($stuname,$address,$contact,$email,$how,$connect); display_data(); echo "<table border=1>"; echo "<tr>"; echo "<td>Sr.No</td>"; echo "<td>Student Name</td>"; echo "<td>Address</td>"; echo "<td>Contact no</td>"; echo "<td>email</td>"; echo "<td>how</td>"; echo "<td>edit</td>"; echo "<td>delete</td>"; echo "</tr>"; echo "</table>"; ?> this file is dbconnect.php <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $connect= mysql_connect("localhost","root","") or die("Connection Error". mysql_error()); //echo "connection established"; if(mysql_select_db("ashish",$connect)) { //echo "<br/>database selected"; } ?> this file is cwfunction.php <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ function insert_data($stuname,$address,$contact,$email,$how,$connect) { global $stuname; global $address; global $contact; global $email; global $how; global $connect; $query="INSERT INTO mydata(student_name,address,contact,email,how) VALUES('$stuname','$address','$contact','$email','$how')"; $result=mysql_query($query,$connect); } function display_data() { echo "i m in display data"; $query="SELECT * FROM mydata"; $result=mysql_query($query); $row = mysql_fetch_array($result); print_r($row); // if($result) // { // $arr = array(); // while($row = mysql_fetch_array($result)) // { // array_push($arr,$row); // } // // // // } //return $arr; } Hello all.. I have here my array results.. does anyone knows how to simplify this array? i would like to get the following value and echo it... Code: [Select] Array ( [GetSMSInboundResponse] => Array ( [Transaction] => Array ( [Code] => 1 [Description] => Transaction OK ) [SMSInbounds] => Array ( [InboundSMS] => Array ( [0] => Array ( [ID] => 3126861 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [Body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote... ) [1] => Array ( [ID] => 3126867 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [Body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote 2... ) ) ) ) ) I would like to echo the result on this part of array Code: [Select] [0] => Array ( [ID] => 3126861 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [Body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote... ) [1] => Array ( [ID] => 3126867 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [Body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote 2... ) but i have problems on how to do it.. please help me guys.. thanks in advance |