PHP - How To Store Each Line Of Xml Into A Php Array
Similar TutorialsHello, 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 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. Hello all, I have an error handler that I need to append messages to (First name not right, Last name not right, etc) I'm using a session array to handle all error messages titled GORB. How come this code won't work? $_SESSION['GORB']['message'][] = "First name wrong"; $_SESSION['GORB']['message'][] = "Last name wrong"; How can I get it to work? I already have the handler output written and functioning fine, I just need to get it to loop over an array of errors instead of just one. i'm trying to get all the results from a query search into an array and them have another query search the results from that array againts a different table to get the right results. Here is my code: Code: [Select] $name = $_GET['name']; //lets say $name = 'california' $get_state = mysql_query("SELECT * FROM locations WHERE state LIKE '$name'") or die(mysql_error()); $num_states = mysql_num_rows($get_state); $location_array = array(); $i = 0; while($state = mysql_fetch_assoc($get_state)){ $location_array[$i][] = $state['id']; $i++; } $get_buildings = mysql_query("SELECT * FROM points WHERE location_id='".implode(",", $location_array)."' ORDER BY name ASC") or die(mysql_error()); However i can't get any results. I tried outputing the array by imploding it and all i got was "array, array, array, array," I hope someone here can help me out. I want to store... - questionID - questionNo - questionText ...in one array? How do I do that?! Debbie hello, um i got a form that stored an array of variables upon users clicks. it submits to another page fine as an array and i can print them using if(!empty($_POST['langSpoken'])) { echo "\n<p><strong>You selected the following LangSpoken:</strong></p>\n<ul>"; foreach($langSpoken as $lang) { // exclude any items with chars we don't want, just in case someone is playing if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $lang)) continue; // print the lang echo "\n\t<li>" . htmlspecialchars($lang) . "</li>"; } echo "\n</ul>"; } else { echo "\n<p>No items selected</p>"; } it prints a list a of array like english spanish but i need to store each one in one variable so i can store in a database is there a way? thanks Hi, I'm trying to store the first+lastname from my mysql user datababase into arrays like this: // Fill up array with names $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; Hello, I'm trying to store the match I get in $result to a variable so that I can easily compare its other values against other values. Here is my code.. //loop through new orders array foreach ( $orders as $order ) { //compare job number and line item against database information for a match if ( array_search ( $order[ 'job_number' ], array_column ( $result, 'job_number' ) ) !== false && array_search ( $order[ 'line_item' ], array_column ( $result, 'line_item' ) ) !== false ) { $db_match = key($result); echo '<br><br>'.$db_match.'<br><br>'; echo 'Job: ' . $order['job_number'] . '/Line Item: ' . $order['line_item'] . ' was found<br>'; //new order which doesn't exist in database } else { echo 'Job: ' . $order['job_number'] . '/Line Item: ' . $order['line_item'] . ' was not found<br>'; } } When I do $db_match = key($result); I get 0 each time and when I do: $db_match = array_search ( $order[ 'job_number' ], array_column ( $result, 'job_number' ) ) !== false && array_search ( $order[ 'line_item' ], array_column ( $result, 'line_item' ) ) !== false; I get 1 each time...which I assume is the number of matches which meet that criteria instead of the array key I found a match on. Edited May 8, 2020 by mongoose00318hello dear php-experts,
well i want to do some data-saving in the next few days. i have some data amount to store in a mysql-db.
well i am pretty sure this is a easy question for php-freaks
the question is: from plain-text to mysql-db: how to store a triple / array? how to store this data into a mysql-db have a dataset of 10 000 lines: {'data_1': 'data_2', 'data_3': 'data_4', 'data_5': 'data_6', 'data_7': 'data_8'} how to store this dataset into the mysql db ? love to hear from you greetings The Script:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="text" name="hashtags" /> <input type="submit" name="submit" /> </form> <?php include("connect.php"); ?> <?php if(isset($_POST['submit'])){ $hashtags = explode(", ", $_POST['hashtags']); for($i= 0; $i < count($hashtags); $i++){ $tqs = "SELECT `id` FROM `hashtags_two` WHERE `hashtags` = '" . $hashtags[$i] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } $fetch_array = array(); while($row = mysqli_fetch_array($tqr)){ $fetch_array[] = $row['id']; } }Hey, sorry for these fundamental array questions lately, I am not going to ask much more when it comes to this. The hashtags come from the submit form (separated by commas) and get stored inside an array with the "explode()" function. The script should select the ID numbers of the hashtags from the table. With the script above only the last row gets inserted into $fetch_array inside the while loop. When the $fetch_array variable is printed on screen then only one ID number can be seen inside the array: Array ( [0] => 24 )How can I have the other ID numbers too? Hi there I have a MySQL database table that has multiple records which look like (1, Which of these are your favorite color(s)?, Red||Blue||Orange||Green, question-type1 ) I have written some PHP code in extracting that data into a HTML form. (The above data looks like a question with multiple options (radio buttons/checkboxes) below it). Below is what I'm trying to achieve: When the action is Submit: store the question number, user responses of the options , time stamp and user name into a new database table. I came to know that passing arrays will do the job, but I got stuck in the middle. Please see the attached documents that has the code. TIA [attachment deleted by admin] Hi, I want to store files to variable array using glob() like $files[0] = xyz.txt $files[1] = pqr.txt . . . $files[n] = nfile.txt I know how to list files from directory using glob() Code: [Select] <?php foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; } ?> How can I do that ? I am pulling 5 addresses and I am wanting to store these 5 addresses in columns in a separate table. On the query string I put LIMIT 5. How can I store the results of each of the 5 loops into columns in a separate table? The columns are A1(for name), A2(for address), A3 (for city), A4 (for state), A5 (for zip), A6 (for phone), A7 (for miles), .... then I also have B1-B7, C1-C7, D1-D7, and E1-E7. I am basically wanting to store up to 5 addresses in an array and then update them into a mysql table. Code: [Select] foreach ($zips as $key => $value) { $result = mysql_query("SELECT State FROM extreme WHERE Zip = '$key' AND Type='store' AND `InStore` <> 'NO' LIMIT 5", $db); $num_rows = mysql_num_rows($result); while($myrow = mysql_fetch_array ($result)) { $Dealer=$myrow['Dealer']; $Address=$myrow['Address']; $City=$myrow['City']; $State=$myrow['State']; $Zip=$myrow['Zip']; $Phone=$myrow['Phone']; $Miles = $value; } } Hi I have a results page from a MySQL query and I have implemented pagination to present data in chunks of 25 per page in a table view (each row => 1 entry). My problem is that next to each data row, I have a selection checkbox, and if the user clicks on it, he can download the selected entries. This thing worked OK before I employed paginated view, when I presented all data in one page. Now, if I select e.g. 2 entries in page 1, then I jump to page 12 and select another 2 entries, if I click on the "Retrieve" button, I get only the last 2 entries (from the last page visited). How can I solve this problem? With JS? Can I use PHP only? The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? Hello there, I have this snippet of code Code: [Select] echo "<td><a href='inc/browse.php?act=view&id=$id'>$title</a></td><td>$author</td>"; } } //close up the table echo "</tr></table>"; This is the code that actually displays the links that go to the listing. The problem is, they all show on one line across the screen. How can it be configured to where the next listing is displayed below the previous one. I tried putting: Code: [Select] echo "<br />" But didn't do it. Any ideas? I am trying to break down an array to make it easier to read. An array that looks like Array (
=> 0 [1] => 0 [2] => 0 [3] => 0012844 1 [4] => 37 [5] => 1 etc...) I want to display it like:
Code: [Select] [0] => 0 [1] => 0 [2] => 0 etc... how can this be accomplished. I have any array with name, gender , age I want to write into a csv which already contains many records line by line, I would like to write the array elements into the csv as a line line from the bottom without overwritten the whole csv. How to do so? Thanks Hello, I am new to php, and what I need to know and learn is a part of an assignment I normally wouldn't ask for help on the net for an assignment but my teacher is not very helpful and other students are struggling too! I have searched the net inside and out and have tried many things. My problem is that I am trying to remove a line from an array by clicking a delete button. The outpur I need is: a line of text that comes from my text file after it is exploded into an array | With a delete button here next line of text that comes from my text file after it is exploded into an array | With a delete button here etc I have managed to write this much myself - Code: [Select] <?php $file = fopen('fav/fav.txt', 'r'); $file = file_get_contents('fav/fav.txt'); $file_array = explode("\n",$file); array_pop($file_array); foreach($file_array as $line) { echo "<form method='post' action=''>".$line. "<input type='submit' name='post' value='delete'><br>"; $fh = fopen("fav/fav.txt",'w'); foreach ($file_array as $line) { fwrite($fh,$line."\n"); } fclose($fh); } ?> The array_pop deletes from the bottom instead of the line the button is next too, I realise I will need to use and if statement but this is the closest I have gotten. Thanks in advance!!! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347628.0 |