Search This Blog

Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Saturday, April 25, 2020

How to Store an Array in LocalStorage - [SOLVED]

localStorage only supports strings. Use JSON.stringify() and JSON.parse().

place array inside onDeviceReady and asign the json array to localStorage

On Page parse values stored in localStorage array into another json array for implimentation


Friday, March 17, 2017

Adding $_POST array to existing $_SESSION array - PHP Resolved

This one was tricky for me.
Scenario
1. Already Have a Set of $_SESSION array

$_SESSION["val1"] => 101
$_SESSION["val2"] => 102
$_SESSION["val3"] => 103
$_SESSION["val4"] => 104


2. on FORM post creates set of $_POST array
This set of $_POST needs to be appended to existing $_SESSION sets

$_POST["val1"] => 201
$_POST["val2"] => 202
$_POST["val3"] => 203
$_POST["val4"] => 204

Simple

$_SESSION += $_POST

IT WORKS LIKE CHARMING!!!

Monday, October 22, 2012

PHP : Array to MySQL Table

I knew there has to be some way to simplify whole big process of INSERTing FORM DATA into SQL Table in less time.

Here is How?

1. Collect all form data into an array
    $flds = $_POST;
2. Check Every form data has been collected in ARRAY
print_r($flds);
If things are fine...
3. There is one more things that is to remove "submit" button field
Count Total # of Arrays
$carray = count($flds);
4. Remove "Submit" Array:
array_splice($flds,$carray);
5. If you want to add few fields with default values -- the put them in form HIDDEN FIELDS or Try this to add MANUALLY:
$flds["new_field"] = "new_field_value";
5. Write a Function to extract values from array and insert into MySQL Table
 function mysql_insert_array($table, $data) { 
            foreach ($data as $field=>$value) { 
            $fields[] = '`' . $field . '`';  
            $values[] = "'" . mysql_real_escape_string($value) . "'"; } 
         
            $field_list = join(',', $fields); 
            $value_list = join(', ', $values); 
            
            $query = mysql_query("INSERT INTO `" . $table . "` (" . $field_list . ") VALUES (" . $value_list . ")") or die('Error in Inserting from ARRAY : ' . mysql_error()); 
   return $query; 
   }
6. FINAL NAIL to Good Old Frame for "Wall of Fame" :
     mysql_insert_array("tablename",$flds);
Note: This function can be used without hesitation anywhere, where there is no 2nd table or cross table data storage. Copy code BINDAAS-ly...

Wow!!!! That's Called Music...

It is shameful, even after 8 years into PHP. Never used it. Although the concept was there at cornor of my mind for very longtime (about 5 years) --> That $_POST is an ARRAY ITSELF.

Finally, I worked my way out today for my client Yellow Cab Airport Taxi

Hope you like it...


Saturday, October 20, 2012

PHP Checkbox values to ARRAY and to UL LI list

I've been trying lately to store selected checkbox values to an Array and show them in UL and LI lists.

Here is how???

Sedan
Stretch
SUV
Coach Bus
Classic Stretch
Hummer
Party Limo
Classic Stretch
Passenger Van
SUV Stretch
Airport Stretch

if(isset($_POST["csubmit"])){ print_r($_POST['fleet']); $arr = $_POST['fleet']; echo ''; }

PHP Assign Checkbox Values to Array and to a Standard Variable

Oh Boy! I've banged my head, kicked mouse - cursed unfriendliness of these coding syntax and finally found a way.

What about it???

--- I Have 10 Checkboxes
--- Where only selected Checkbox values need to stored into an ARRAY
Once Checkbox values stored into an Array
--- Assign those values to a Standard PHP Variable

Here is HOW for your references:


Sedan
Stretch
SUV
Coach Bus
Classic Stretch
Hummer
Party Limo
Classic Stretch
Passenger Van
SUV Stretch
Airport Stretch

Wow! That's Simple isn't it??? Yeh, You Bet... ----------------------------------------------------- Bay Area Taxi

content-wide advt