PHP - Insert Array Vales Into Sting Of Another Array
I have an array $array_1
Code: [Select] ARRAY( [0] => info 1 [1] => info 2 [2] => info 3 ) and I have another array $array_2 Code: [Select] ARRAY( [0] =>thank you and welcome to what ever [1] =>the info you added * thanks for entering your info ) I want to loop though the first array and place the values into the [1] of the second array. But the tricky thing is I want it to insert were the * is. Code: [Select] foreach ($array_1 as $key => $val) { //not sure about this insert into ($array_2[1],after *, $val); } any help would be awesome. Similar TutorialsI have an audit trail that record users ids and a copy of the sql string for any updates they make to my application. This is very easy for me to follow to find exactly where changes happened but do end users it is a bit of a challenge. Has anyone seen or made a script that can either compare two sql strings to see what fields have different values or a script that takes an SQL string and outputs its field names and values to an array that I can use for comparisons? Example being the look at a update made by user X, the database pulls the sql for that change then looks for the previous change up any user before (update sql should have a value for all fields) then compares to see what user X changed. If not im thinking of case statement to divide sql request between inserts and update then writing a script to split the strings based on where the commas were. Any thoughts? I need a help in the following : I have an admin page from where the admin attaches an gif image.This attached image should be shown to the user as a scrolling image. The code for the scrolling image is done through javascript. So my actual problem is getting the name of the attached gif image to the javascript array which is used for scrolling horizontally. Hi people I am new to php and I need your help.
I am usig libchart and want to make the bars colored based on value:
Original code:
$this->setBarColor(array( new Color(42, 71, 1), )); I want to make something like this: $this->setBarColor(array( if ( ( condition1 )) new Color(42, 171, 1), if ( ( condition2 )) new Color(42, 71, 1), if ( ( condition3 )) new Color(42, 71, 211), )); I do not know php syntax yet, so how can I do this? Thank you, Alex Hi again , I am stuck with simplest problem of array .. i searched all forums and couldn't find similar problem.. Iam collecting array post data "data m_name[][email]" from a form, but I don't know how to get 2 array variables at the same time, here's what I tried : <form action="" method="post" name="myForm"> <div> <input type="text" name="m_name[]" /> <input type="text" name="m_name[][email]" /> </div> <div> <input type="text" name="m_name[]" /> <input type="text" name="m_name[][email]" /> </div> <div> <input type="text" name="m_name[]" /> <input type="text" name="m_name[][email]" /> </div> <input type="submit" name="button" id="button" value="Submit" /> </form> other page where I want to receive above array <?php if($_POST) { print_r($_POST['m_name']); // Output is : Array ( [0] => someone [1] => Array ( [email] => 3 ) [2] => someone two [3] => Array ( [email] => 4 ) [4] => someone three [5] => Array ( [email] => 5 ) ) while (list ($key,$val) = @each ( $_POST['m_name'])) { echo $val.val2 ???"<br/>"; // here I want to get both value $_POST['m_name'] and $_POST['m_name'] ['email'] since I am putting them in db << } } ?> I want to get both values of $_POST['m_name'], I don't know how to do it or is there another way to do it? thankx in advance!! phpfreaks have been very helpful .. HELP!!! PLEASE!!! Here's what's happening: I have a string much like this one: Code: [Select] $str = "84,390961CPK_100,'Pink Coloured Cord',15,'390961CPK_100',1"; I need to insert apostrophes around the first instance of 390961CPK_100 so it reads '390961CPK_100' and not simply 390961CPK_100. To do this I have made the string into an array as follows: Code: [Select] $str_array = str_split($str); Now I need to insert quotes into the array of characters, then convert the whole mess into back into a string. I can't go by hard coded index numbers, because all of the text in this string is variable in length, so I have to go by the first and second positions of the commas. I have no idea how to do this, and it needs to be done yesterday! Mucho Gracias to anyone who can help me with this. I looked through all the array functions in the manual, but didn't see what I needed (might have just missed it) Is there a way to stick a value into the middle of an array, without writing over the current value? I would need it to just push the rest back 1. Hope that explains what Im looking for! Thanks in advance I'm trying to insert array of posts categories into MySQL. I'm getting category IDs from drop down list.. ERR: Notice: Notice: Array to string conversion in C:\laragon\*********\includes\functions.php on line 477
Array Array ( [0] => Array ( [0] => 4 [1] => 5 ) )
PHP try { $sql = "INSERT INTO posts_category_ids (post_id, category_id) VALUES"; $insertQuery = array(); $insertData = array(); foreach ($filter_category as $row) { $insertQuery[] = '(?, ?)'; $insertData[] = $id; $insertData[] = $row; } if (!empty($insertQuery)) { $stmt = $this->conn->prepare($sql); $stmt->execute($insertData); //477 } }catch (Exception $e){ echo $e->getMessage(); } }
I am trying to insert records from an foreach array, it only inserts the first record and I cannot work out how to get it to loop through all of the records. Thank you foreach($_SESSION['post_data_array'] AS $seat) { $rowId = substr($seat, 0, 1); $columnId = substr($seat, 1); echo $rowId . $columnId . ", "; } $sql125 = "INSERT INTO booked_seats(booking_id, row_id, column_id) values ('$book_id', '$rowId', '$columnId')"; $result125 = mysql_query($sql125); if ($result125) { echo "worked"; } else { echo "didnt work"; } Hi - I have an HTML form which is dynamically produced using CodeIgniter / PHP and presents products a customer has ordered. When the customer has finished changing his quantities they must now submit the form. My problem is that my form will contain many of the same named fields for example, 'Product ID', or 'Product Name' or 'quantity'. So now when it gets processed a typical post array like product id could look like this: Code: [Select] Array ( [0] => 28 [1] => 24 [2] => 101 [3] => 23 [4] => 17 ) Of course I get an error: Quote Severity: Notice Message: Array to string conversion Filename: mysql/mysql_driver.php I really need some advice on how I should pre-process the various POST arrays so I can get them into my DB. A very grateful student of PHP ! Thanks If I have an array like this, what makes the most sense for inserting a key value pair after a given key? This is how I came up with to do it, after looking at the manual I'm not sure if there's a function I'm missing, because this seems way too complicated. Code: [Select] <?php function addKV($arr, $keyToFind, $addKey, $addValue){ $keys = array_keys($arr); $spot = array_search($keyToFind, $keys); $chunks = array_chunk($arr, ($spot+1)); array_unshift($chunks[1], array($addKey=>$addValue)); $arr = call_User_Func_Array('array_Merge', $chunks); return $arr; } $myArr = array('id'=>1, 'name'=>'Name', 'created'=>time(), 'modified'=>time()); $myArr = addKV($myArr, 'name', 'foo', 'bar'); ?>$myArr now looks like Code: [Select] array('id'=>1, name=>'Name', 'foo'=>'bar', 'created'=>time(), 'modified'=>time()); Hi, I am creating a new menu (food) in my system. This consists of a menu, menu_items and menu_connection table. I can insert the menu name just fine and return its id just fine. When inserting the menu items, i need to get each of the menu_item_ids to use in the query that inputs the menu_connection. This is what i have so far: if ($_SERVER['REQUEST_METHOD']=="POST") { ///////////////////// //menu name insert // ///////////////////// $mname = mysqli_real_escape_string($conn, $_POST['newMenuName']); $stmt=$conn->prepare(' INSERT IGNORE INTO ssm_menu (menu_name) VALUES (?); '); $stmt->bind_param('s',$mname); $stmt->execute(); $menuInsId = $stmt->insert_id; echo $menuInsId; $stmt->close(); ///////////////////// //menu item insert // ///////////////////// $mitname = $_POST['newMenuItem']; $stmt=$conn->prepare(' INSERT IGNORE INTO ssm_menu_items (menu_item_name) VALUES (?); '); foreach ($_POST['newMenuItem'] as $k => $nmItem) { $mitname = mysqli_real_escape_string($conn, $nmItem); $stmt->bind_param('s',$mitname); $stmt->execute(); $menuItmInsId = $stmt->insert_id; echo $menuItmInsId; } $stmt->close(); /////////////////////////// //menu connection insert // /////////////////////////// $stmt=$conn->prepare(' INSERT IGNORE INTO ssm_menu_connection (menu_id, menu_item_id) VALUES (?,?) '); foreach ($_POST['newMenuItem'] as $k => $nmItem) { $stmt->bind_param('ii',$menuInsId, $menuItmInsId); $stmt->execute(); $connectionInserId = $stmt->insert_id; echo $connectionInserId; } $stmt->close(); } Currently it is inserting each of the items in the connection table with the same id - i understand why but i dont know how to collect up all of the ids to use later Hi Guys
I have a number of arrays that are posted from a form
They are
$home_rider
$order
$away_rider
$awayorder
for each home rider I want to to action the following query
"INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$homerider',$card_id,'h','$homeorder')"
and for each away rider I want to do the following
"INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$awayrider',$card_id,'a','$awayorder')"
I am using the following code
$i=0; for($i){ $homerider=$home_rider[$i]; $homeorder=$order[$i]; $homesql="INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$homerider',$card_id,'h','$homeorder')"; echo $homesql; $i++; } $i=0; for($i){ $awayrider=$away_rider[$i]; $awayorder=$awayorder[$i]; $homesql="INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES ('$awayrider',$card_id,'a','$awayorder')"; echo $awaysql; $i++; }I am getting an error saying Parse error: syntax error, unexpected ')', expecting ';' Where am I going wrong? Hi, I have an 2 arrays ( $match[1] and $match[2] ) with 50+ fields that i need to insert into a database, but im not getting how i could do it. Until now im trying with with the following code: Code: [Select] $sql="INSERT INTO is_trigger_reference (triggerName) VALUES ('$match[2][0]')"; mysql_query($sql) or die(mysql_error()); But when i check into the db table i only got: Code: [Select] triggername ( field name ) Array[0] ( data inserted) I know i can set a var to each array ( 40+ ) but i belive there's something more clean than that Thanks! Hello, I have been at this for awhile now and cant seem to figure it out. I have 2 separate arrays like shown below and I am trying to insert each value into my database using one update query. I have tried a for loop inside each array, but only one column populates. I have tried breaking the values outside their for loop, etc, etc. Does anyone know a way this can be done? Code: [Select] //Cars $cars = array('ford', 'toyota', 'bmw'); //Places $places =arrray('Orlando','California','Texas'); foreach ($cars as $car){ foreach ($places as $place){ $place .=$place; } mysql_query("INSERT INTO vehicles (cars, places) VALUES ('" . $car. "', '" . $place . "'')"); } I am making a website where writers can share stories. One of the fields is other stories. So I used this code to make it a array with the links in each f the items. $other_split = explode(',', $other_form); $other_int = count($other_split); $x = 0; while ($x>$other_int) { $other_link[$x] = "<a href = '$other_split[$x]'> Chapter $x </a>"; } How can I insert the data in that array into one non array variable. Good evening,
I am working on a program that takes images, and casts them into an associated array, I then want to display thumbnails of those images into a 3 column by 4 row table...
[image][image][image]
[image][image][image]
[image][image][image]
[image][image][image]
(For my visual friends)
here is my current, pardon for the mess, but right now, functionality is more important.
<!DOCTYPE html> <html> <head> <title>Zodiac Gallery</title> </head> <body> <h2 style="text-align:center">Zodiac Gallery</h2> <p>Click a thumbnail image to see enlarged view.</p> <?php $ZodiacArray = array ( "Images/rat.jpg" => "Rat", "Images/ox.jpg" => "Ox", "Images/tiger.jpg" => "Tiger", "Images/rabbit.jpg" => "Rabbit", "Images/dragon.jpg" => "Dragon", "Images/snake.jpg" => "Snake", "Images/horse.jpg" => "Horse", "Images/goat.jpg" => "Goat", "Images/monkey.jpg" => "Monkey", "Images/rooster.jpg" => "Rooster", "Images/dog.jpg" => "Dog", "Images/pig.jpg" => "Pig"); foreach ($ZodiacArray as $image => $zodiac) { echo "<table> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> </table>"; ?>Help is welcome, thank you. I have tried many ways of storing an array of data that comes from a multiple selection form into a mysql table, including serialization. I am currently trying to do it by forming a string, and using the string in the insert query, but keep getting errors, or just nothing happening. I am not sure what I am doing wrong. Code: [Select] $categoryString = array(); if ($categoryArray){ foreach ($categoryArray as $category){ $categoryString[] = $category.'<br />';} } $categoryquery= "INSERT INTO categoryname VALUES('$categoryString')"; mysql_query($categoryquery); Thank you for your time as always. Hello, I'm working on a form that once submitted, it inserts the result into my SQL table, but I'm trying to get it so it will update an imploded array. EG: current SQL table is "red,blue,green". Then user submits 'white', the SQL table should then update to: "red,blue,green,white" (notice how its added to the end). This is what I have so far: Code: [Select] $attack_out = $info['attack_out']; $attack_out_split = explode(",", $attack_out); if(isset($_POST["submit_attack"])){ $attack_user = $_GET["attack"]; // user - sent from form //$troops_send = $_POST["troop_send"]; // ammount - sent from form $attack_user_array = array(); $i = 0; $max = (count($attack_out_split) + 1); while($i < $max){ $reverse = ($max - 1) - $i; $attack_user_array[$i] = $attack_out_split[$reverse]; $attack_user_array[$max - 1] = $attack_user; $i++; } $attack_user_glue = implode(",",$attack_user_array); $result = mysql_query("UPDATE users SET attack_out='$attack_user_glue' WHERE username='$username'"); } I can't figure out the algorithm in my while loop. Would appreciate any help, thanks |