PHP - Add Data To A Multidimentional Array
Hello every body i have a array like this
Array ( [19/5/14] => Array ( [94-DE-80-28-CF-BC] => Array ( [7] => Array ( [qax] => 1 ) ) } }I want to add new array under the [94-DE-80-28-CF-BC] => Array.. I am doing code but what it does it overrides the full array inside that array and create a new one... The code i've used is | array_push( $vis[$date][$macp], array( "$id"=>array( "$country"=>1 ) )); Similar TutorialsI've got a few arrays as follows: Code: [Select] $array1 = ('A', 54, 'a', 2); $array2 = (, 67, 'b',); $array3 = ('R', 54,,); $array4 = (, 36, 'b'); $array5 = (, 36, 'a',); $array6 = ('FX', 119, 's', 4); $array7 = ('R', 3, 'c',); $superarray = array($array1, $array2, $array3, $array4, $array5, $array6, $array7); Now, I've got a piece of code that sorts $superarray by index[1] of the sub-arrays. The code looks like this: Code: [Select] function sortmulti ($array, $index, $order, $natsort=FALSE, $case_sensitive=FALSE) { if(is_array($array) && count($array)>0) { foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; if(!$natsort) { if ($order=='asc') asort($temp); else arsort($temp); } else { if ($case_sensitive===true) natsort($temp); else natcasesort($temp); if($order!='asc') $temp=array_reverse($temp,TRUE); } foreach(array_keys($temp) as $key) if (is_numeric($key)) $sorted[]=$array[$key]; else $sorted[$key]=$array[$key]; return $sorted; } return $sorted; } $sortedarray = sortmulti($superarray, 1, ASC, $natsort=FALSE, $case_sensitive=FALSE) The output is this: R3c 36b 36a A54a2 R54 67b FX119s4 This is great because it goes 3 -> 36 -> 36 -> 54 -> 54 -> 67 -> 119. However, the problem, if you look, is this part: 36b 36a Its sorted everything according to index[1] of the sub-arrays, but now I would like to sort by index[2], then index[3] as well. I'd like the output to look like this: R3c 36a 36b A54a2 R54 67b FX119s4 Any ideas? Because this is way over my head ... this is an array returned after parsing YAMl file using spyc api. i want to write a code to to extract value related to key topic name and put in a separate 1d array say $topicnames Array ( [1] => Array ( [topicname] => singapore travels [rev] => 250 => Array ( [25] => Array ( ) [topicname] => airlines [rev] => 24 ) [1] => Array ( [35] => Array ( ) [topicname] => shubham [rev] => 65 ) ) [2] => Array ( [topicname] => singapore entertainment [rev] => 210 => Array ( [45] => Array ( ) [topicname] => night safari[rev] => 54 ) i tried using simple for loop but not working.. pl help me out. How do I echo the array below in a for each loop? I'm trying to output this data in a table. Array ( [u] => Array ( [0] => Array ( [row_id] => 1 [0] => Jn [1] => Bo [2] => do [3] => jilcom [4] => hocom ) [1] => Array ( [row_id] => 3 [0] => Jk [1] => Kk [2] => wd [3] => jk [4] => ) [2] => Array ( [row_id] => 5 [0] => Jn [1] => Bo [2] => on [3] => jm [4] => hm ) ) [blog] => Array ( [0] => Array ( [row_id] => 3 [0] => dk [1] => [2] => [3] => [4] => ) [1] => Array ( [row_id] => 9 [0] => 2rs [1] => dee [2] => [3] => [4] => ) ) ) 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. Good evening all, I am trying to expand my experience with PHP by doing a small project for a personal website. I am working from scratch using notepad and so far have been having great sucess. My experience with C# is helping greatly but sadly ive hit a snag and can't seem to free myself. I have an array that is populated with items, and the prices for those items if you are buying/selling them. What I will have is a form with a drop list that is populated by this array list (already working) and a text entry that you can enter a numerical quantity value, then another drop list that will have buy / sell as an option. What the page will do is take the values from the form and calculate the "total" from the supplied values. Sadly some reason I cant set a $Variable to the value of the array values. I can echo them and get the correct value, but can't set the Variable to the arrays value! Code: [Select] <?php $ResBuySell = array( "Iron ingot" => array("Buy" => 6, "Sell" => 7), "Shadow iron ingot" => array("Buy" => 14, "Sell" => 16), "Dull copper ingot" => array("Buy" => 14, "Sell" => 16), "Copper ingot" => array("Buy" => 6, "Sell" => 7), "Bronze ingot" => array("Buy" => 6, "Sell" => 7), "Gold ingot" => array("Buy" => 6, "Sell" => 7), "Agapite ingot" => array("Buy" => 6, "Sell" => 7), "Verite ingot" => array("Buy" => 6, "Sell" => 7), "Valorite ingot" => array("Buy" => 6, "Sell" => 7), "Feathers" => array("Buy" => 6, "Sell" => 7), "Arrows" => array("Buy" => 6, "Sell" => 7), "Bolts" => array("Buy" => 6, "Sell" => 7), "Boards" => array("Buy" => 4, "Sell" => 6), "Spined leather" => array("Buy" => 16, "Sell" => 18), "Horned leather" => array("Buy" => 6, "Sell" => 7), "Barbed leather" => array("Buy" => 6, "Sell" => 7), "Cloth" => array("Buy" => 6, "Sell" => 7), "Ribs" => array("Buy" => 6, "Sell" => 7), "Fish steaks" => array("Buy" => 6, "Sell" => 7), "Orange petals" => array("Buy" => 6, "Sell" => 7), "Red leaves" => array("Buy" => 6, "Sell" => 7), "Green thorns" => array("Buy" => 6, "Sell" => 7) ); function GetPrice($ResType = "Iron ingot", $TranType = "Buy") { return $ResBuySell[$ResType][$ResType]; } function GetQuantity() { return 5; } function GetTotal() { $ResPrice = GetPrice(); $ResQuanity = GetQuantity(); $ResTotal = $ResPrice * $ResQuanity; return $ResTotal; } echo GetTotal(); ?> Quote 0 The problem resides he Code: [Select] function GetPrice($ResType = "Iron ingot", $TranType = "Buy") { return $ResBuySell[$ResType][$ResType]; } Some reason when I echo this: Code: [Select] $ResType = "Iron ingot"; $TranType = "Buy"; echo $ResBuySell[$ResType][$ResType]; it will return; Quote 6 The proper value, but when I put it into a function and try to retrieve this info via the function it returns zero. I am a beginner with php and just trying to learn by trial and error, but after failing at this for 5 days I figured it was time to call in help from the big guns! Thanks in advance to anyone who can offer my any assistance with this problem! 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. I have the current data show up when I do a var_dump. Code: [Select] Code $result = $wrap->get_lists(); echo "Result of lists:<br />"; if($result->was_successful()) { echo "Got lists\n<br /><pre>"; var_dump($result->response); //print_r($result->response); } else { echo 'Failed with code '.$result->http_status_code."\n<br /><pre>"; var_dump($result->response); } echo '</pre>'; Data Output array(303) { [0]=> object(stdClass)#5 (2) { ["ListID"]=> string(32) "df2d1497b0f4bdc3b8b77863f6721025" ["Name"]=> string(14) "DATA1" } [1]=> object(stdClass)#6 (2) { ["ListID"]=> string(32) "f44d9acf655e914b944d7174bdd521ff" ["Name"]=> string(14) "DATA2" } [2]=> object(stdClass)#7 (2) { ["ListID"]=> string(32) "c84f4ba6b86bc508e6922f4ca44ab41c" ["Name"]=> string(14) "DATA3" } [3]=> object(stdClass)#8 (2) { ["ListID"]=> string(32) "b7dc652cd5060194362f19667ddf47e9" ["Name"]=> string(14) "DATA4" } } What I need to achieve is get the data in "ListID" out so I can run "ListID" through another function of mine, to delete records. Any ideas, how I would get "ListID" values out of the array? 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 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; } What I need is to: - take the information from array 1 - remove it from array 2 - then ADD it OR take from array 3 (this of course depends on array 1) I also have to keep in mind that array 1 could be empty thus needing to empty array 2 and IF the information is in array 3 then remove it array 3 is the main array that I will update the database row which will in turn display the correct check boxes checked or not Thank you for reading, I hope you can help me. Code: [Select] Array //#1 this is the submitted information ( [0] => 103100000 [1] => 103200000 [2] => 103400000 [3] => 103500000 [4] => 103700000 ) Array //#2 all possible choices ( [0] => 103100000 [1] => 103200000 [2] => 103300000 [3] => 103400000 [4] => 103500000 [5] => 103600000 [6] => 103700000 ) Array //#3 currently stored in database / marks the check boxes "checked" ( [0] => 103100000 [1] => 103200000 [2] => 103300000 [3] => 103400000 [4] => 103500000 [5] => 103600000 [6] => 103700000 ) Hi everyone, Hope someone can help. Does anyone know why this is nor displaying any data? Code: [Select] $qry = mysql_query("select * from product"); $data = array(); while($row = mysql_fetch_array($qry)){ $productName[] =$row['productName']; // Item name } for($i=0;$i<mysql_num_rows($row);$i++) { $data = $productName[$i]; } return $data; Thanks in advance Edd 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. Hello All, First, I'm new to php and I have spent a lot of time searching forums and google for the answer to my question with no luck, so if it's a topic already covered, PLEASE reply with a link or point me in the right direction. OK, I have a form that let's users upload multiple images. The upload portion works fine. What I can't figure out how to do is put the image name of each file that gets uploaded all into the same table record. I also need each file name to be put into it's own column in the table. For example, file1, file2 and file3 will get dumped into the same record and into it's respective column (uploaded_image1, uploaded_image2, uploaded_image3). I've included the working upload code and the code that inserts some of the information into the database (just not the image names). Code: [Select] echo "<textarea name=challenge rows=15 cols=60> </textarea><br/><br/>" echo "<textarea name=insight rows=15 cols=60> </textarea><br/><br/>" for($i=1; $i<=$max_no_img; $i++){ echo "Image $i <input type=file name='image[]' ><br/>"; } echo "<input type=submit value=Submit>"; Code: [Select] // Connect to DB $host = 'xxx'; $user = 'xxx'; $pass = 'xxx'; $db = 'xxx'; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); // Post Variables $challenge = $_POST['challenge']; $insight = $_POST['insight']; $filename=serialize($_POST['filename']); // Upload Images while(list($key,$value) = each($_FILES[image][name])) { if(!empty($value)) { $filename = $value; $add = "upimage/$filename"; copy($_FILES[image][tmp_name][$key], $add); chmod("$add",0777); } } // Insert into database $query = "INSERT INTO table ( challenge, insight, uploaded_image1, uploaded_image2, uploaded_image3,)". "values ( '$challenge', '$insight', '$filename' '$filename2' '$filename3')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); I know just enough about php that the reason the above wont work, is because $filename2 and $filename3 haven't been given a value. Unfortunately, I have no idea how to separate that information in the array. If anyone can point me in the right direction I'd be forever grateful! Thanks, Gary |