Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

AJLX's Achievements


Member (2/5)



  1. That works perfectly- Thanks for your help- I've learnt lots!
  2. Hi Requinix, The file is natively exported as a UTF-16. I re-saved it as a UTF-8 and it all works perfectly. Does PHP have the ability to be able to convert the file for me?
  3. The bottom screenshot clearly doesn't! I must have uploaded the wrong file. I'll leave it there to keep the thread complete. Here is the ACTUAL output, and the the Var_dump afterwards. There's weird characters being exported in the channel column, but as far as I can tell, that's the only key that's effected. I should be able to clean that up easy enough. Any ideas? Many thanks
  4. Hi Lazy Administrator, I'm still struggling with this one! I'm onto about my 10th generation of code which looks like this: That gives me the following output: The Array key "Unit" exists, but for some reason doesn't seem to get found. I tried running print_r(array_keys($new_array) to try and investigate the array keys a bit further, with this result I've played about with adding some spaces to the word Unit to see if that would help, but it doesn't seem to make a difference. It's getting late here, and I'm getting the feeling I've done something that's super simple, but stupid!
  5. Hi Lazy Administrator, Thanks for your help (and patience!) so far. The code you posted doesn't seem to work for me. If I Print_R the $header array, that contains all of the headers, and looks as I expect it should. However, when I Print_R the $line array, the keys are numbered, they don't have the same titles as the header array, so therefore the: comes back with an undefined index error. I thought that I could use array_combine to put the headers back into where I think they should be: Now the array looks how I think it should but still doesn't work. Therefore I clearly don't understand how it should look/work! Thanks!
  6. Hi All, Thanks for the response so far. This is from a file that built about a year ago, I've come to update it. The original code uploaded the file, put it into an array, and then deleted the file. The more I think about it, the more I think that's a pointless step? The CSV sent from a previous page. The aim of the code is to take the data from a .csv file, extract the columns that I want, and store them into a database, for retrieval later. I know the names of the columns that I want to keep, but the maker of the software version keeps updating how they export the data, and adding columns which I can ignore. My current upload code is below. I think it was taken from a tutorial that I found ages ago. Now that I know a little bit more about PHP(!) I'm trying to understand more efficient ways of working! Once again- Thanks!
  7. Hi Guys, I have an array that looks like this: It has come from a CSV file. Basically, I only need to use some of the columns, the rest can be unset/deleted. Is there a way that I can easily make an array that just has for example "header1" and "header5" and the corresponding values "value1" and "value5"? I don't know what order the columns are going to be in, so I need to somehow do it by name. I think I know the concept of what to do, I just lack the php knowledge to actually do it! I think I need to: Step 1: Loop through the array and get the array keys that match up to the headers above Step 2: reload through the array unsetting based on the array keys found in step 1 I've tried looking into array_intersect and array_diff but I can't work out how these would help. Thanks for reading!
  8. Thanks Jacques, The nested loop was because I didn't know that I could do it your way. I'm not sure how I could run it with a cron job, I'm using it to suck the info out of an API, and store it in my own DB, so that I can then add my own data to it. The script only needs to run once, I'll then work out a way where I can make a refresh script which only imports the information that has changed. Regards, AJLX
  9. Hey Guys, I'm just starting to learn Curl so that I connect to an API. At the moment I have this php code: <?php //******************************************************************************// // // //THIS FILE TAKES A CURRENT JOB AND ADDS IT TO A PAL LABEL PROJECT // // // //******************************************************************************// // ******* TURN ON ERROR REPORTING *****// error_reporting(E_ALL); ini_set('display_errors', '1'); //**** SET THE HEADERS UP FOR AUTHENTICATION *****// $headers = array(); $headers[] = "X-SUBDOMAIN:XXXXXXXXXXX"; // Set the sub domain $headers[] = "X-AUTH-TOKEN:XXXXXXXXXX"; // Set the API Code $headers[] = "application/json"; $total = 50; // this is the max number of pages we will search. with 100 items on a page, and 100 items that means we can return 10,000 items $curl = curl_init(); //**** WE GET ALL OF THE ITEMS CURRENTLY IN THE CURRENT PROJECT AND PUT THEIR UNIQUE ID INTO THE ASSETS ARRAY ***// curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_URL, 'https://api.current-rms.com/api/v1/products?page=1&per_page=100'); // allows up to 1 million products curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // Send the request & save response to $resp $resp = curl_exec($curl); // Convert the response to an array $obj = json_decode($resp, true); // The Obj array currently contains every item in the DB and loads of useless info. We need to extract just the ID and the Name! If I print_r the $obj variable it returns this: I have cut the output down a bit, each item in the products array is about 50 lines long, The only information I actually need to recall is the first two lines which is [id] and the [name]. Is there a simple way that I can do this? So far I have tried to do a Foreach loop and create a new array, but this take a very long time (there are about 600 records!) there must be a much simpler way, where I can unset everything that I don't need, or only call the information that I need from the API? Here is the foreach loop that I used: foreach ($obj as $key) { foreach ($key as $id => $value) { if (!empty($value['name'])) { $products[] = array('Name'=>$value['name'], 'ID' => $value['id'] ); } } } **EDIT ** Once I have my array of ID's (which will be around 600 values long) I then need to get a list of serial numbers that are linked to these id's (there could be up to 100 per id) which will leave me with an array that will be huge! So far I have been getting gateway 504 error's, which I'm hoping is just due to the fact that I'm currently pulling out so much more information than I actually need, so I'm trying to make this more efficient and slim lined. I'm fairly new to PHP, and just do it as a hobby, so go easy on me please! Thanks AJLX
  10. Hey guys: I have a database that is full of items. Each item lives in a box, with various accessories. I'm trying to loop through this DB to print out a label for each case that shows the amount of items that are in the case, along with the accessories that belong to it. I currently have a rather convoluted bit of code, that kind of works, but doesn't have the order that I want. My result is currently this: 4 X Generic lighting hanging clamp 4 X Generic lighting hanging clamp 4 X Generic lighting hanging clamp 4 X Generic lighting hanging clamp 4 X Generic lighting hanging clamp 2 X 25kg Safety Bond 2 X 25kg Safety Bond 2 X 25kg Safety Bond 2 X 25kg Safety Bond 2 X 25kg Safety Bond 2 X 16a to Powercon 2 X 16a to Powercon 2 X 16a to Powercon 2 X 16a to Powercon 2 X 16a to Powercon ********** 12 X Generic lighting hanging clamp 6 X 25kg Safety Bond ********** All the information is there, but due to the way that it loops through it's in the wrong order. I'd like it to be grouped so it looks like this so that it is grouped by box: 4 X Generic lighting hanging clamp 2 X 25kg Safety Bond 2 X 16a to Powercon 4 X Generic lighting hanging clamp 2 X 25kg Safety Bond 4 X Generic lighting hanging clamp 2 X 16a to Powercon 4 X Generic lighting hanging clamp 2 X 25kg Safety Bond 2 X 16a to Powercon 4 X Generic lighting hanging clamp 2 X 25kg Safety Bond 2 X 16a to Powercon ********** 12 X Generic lighting hanging clamp 6 X 25kg Safety Bond ********** Here is the code that I'm using. At the moment I'm just concentrating on the if ($item_type == '2') part, but have shown the whole lot so you can see what I'm doing. foreach ($distinct_path as $path) { $sql = "SELECT * FROM current_items WHERE path = '$path'"; $result = $con->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $item_name = $row['item_name']; $item_type = $row['item_type']; $item_qty = $row['qty']; $case_qty = $row['case_qty']; if ($item_type == '1') // THESE ARE MAIN ITEMS { $total_main_qty = $row['qty']; //main item QTY; $main_item_name = $item_name; } // This code will tell us number of full boxes, and number of extra lights left over $amtoffull = $total_main_qty/$case_qty; $amtoffull = floor($amtoffull); // we round down to the nearest whole number $total_left = $total_main_qty - ($case_qty * $amtoffull); if ($item_type == '2') // THESE ARE ACCESSORIES { $asc_qty = $row['qty']; //main item QTY; $asc_qty = $asc_qty/$total_main_qty; // THIS GIVES US THE TOTAL OF ONE Item $asc_qty = $asc_qty * $case_qty; // This is a full case amount //echo $asc_qty ." x ". $item_name ."</p>"; while ($i < $amtoffull) { echo $asc_qty ." X ". $item_name ."</p>"; ++$i; } } $i = 0; } echo "**********"; echo "<p>"; } I think I need to either shift the loops around so they work in a different order, or store everything into an array and then loop through that. Can any one help?
  11. Ah yes! The code I used above with print_r was just to prove that the result was correct. The code I used to actually build the array looked like this: $assets = array(); foreach ($obj as $key) { foreach ($key as $id) { $assets[] = ($id['id']); } } Thanks
  12. Out of interest what would your solution be? This is for my own personal use, you'll be pleased to know I don't do this as a day job. Any opportunity to learn new things is appreciated...
  13. I finally got there! foreach ($obj as $key) { foreach ($key as $id) { print_r($id['id']); } }
  14. Thanks for your reply. I'm still on PHP 5.4, so this hasn't been implimented yet, and upgrading isn't an option.
  15. Hey guys, I have a php array that looks like this: Array ( [opportunity_items] => Array ( [0] => Array ( [id] => 2783 [opportunity_id] => 92 [item_id] => [item_type] => [opportunity_item_type] => 0 [opportunity_item_type_name] => Group [name] => Strobes [transaction_type] => [transaction_type_name] => [accessory_inclusion_type] => [accessory_inclusion_type_name] => [accessory_mode] => The array goes on for ages, but I have only shown the bits I need. I want to create a new array that just contains the [id] key. I can get the first value by doing this: echo $array["opportunity_items"]["0"]["id"]; But I somehow I need to loop through this to get all of the rest of the values. Thanks, Andy
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.