PHP - Multi Dimension $_session Arrays?
Hi, i am having trouble retriving data from a 2D array in my php code an was wondering if i should be using a session array instead to keep track of the contents of the array between refreshes of the page.
I am currently working with an array in the form of : $hosts[][] // $hosts[$x][0] - the hostname // $hosts[$x][1] - the ip address // $hosts[$x][2] - the operating system However, i seem to loose the ability to read data from this array when the user creates a refresh event (ie clicks a button/hyperlink). Should i be storing the data in a $_SESSION array, if so what is the correct syntax to use, i have only ever stored single values in $_SESSION variables. Thanks for reading. Similar Tutorialsi want to edit a product and allocate industries to a product refer following link to view http://meriwebsite.net/envytech/admin/industryallocate.php?pageNum=1SELECT%20a.products_id,%20a.products_image,%20b.language_id,%20b.products_description,%20b.products_name%20%20%20FROM%20products%20a%20,%20products_description%20b%20WHERE%20a.products_id%20=%20b.products_id%20and%20language_id=1%20and%201%20order%20by%20%20b.products_id,%20%20b.products_description I can update prouct name and serial number but cannot get values for industries the do while loop for industry display is given below (displaying industry id before check box here) $iquery="SELECT * from industry "; mysql_select_db($database_DBconnect, $DBconnect); $iResult = mysql_query($iquery, $DBconnect) or die(mysql_error()); $irows = mysql_fetch_assoc($iResult); $itotalrows=mysql_num_rows($iResult); $j=-1; do { $j++; ?> <br /><?php echo "id=". $irows['id'];?><input name="ind[$i][$j]" type="checkbox" class="vardana12" id="ind[$i][$j]" value="<?php echo $irows['id'];?>" /> <?php echo $irows['name'];?> <?php } while ( $irows = mysql_fetch_assoc($iResult) ); ?> I am trying to display values using following code if ( (isset($_POST['sub'] )) or (isset($srno['sub'] ))) { echo "<br> count=".count($_POST['srno']); for($i=0; $i< count($_POST['srno']); $i++){ echo "on 'save' clicked <br>"; echo "<br> products ".$_POST['products_id'][$i]; echo "<br>srno ". $_POST['srno'][$i]; echo "<br>industry ".print_r($_POST['ind'][$i]); echo "<br>product name ". $_POST['products_name'][$i]; Updateindustry($_POST['products_id'][$i], $_POST['srno'][$i],$_POST['industry'][$i],$_POST['products_name'][$i]); } $update=1; $alert= "udation done"; } I am not getting correct values for $_POST['industry'][$i] please help I'm trying to add a value to my multi dimension array. I want to add a 'quantity' value to the inner array.
This is what I have now:
Array ( [0] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green)) [1] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green)) )I'm trying to make it like this: Array ( [0] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5)) [1] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 [quantity] => 5) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF [quantity] => 5) [2] => stdClass Object ( [name] => Mud Ring[option_sku] => [value] => Rise Single Gang [quantity] => 5) [3] => stdClass Object ( [name] => MC Cable[option_sku] => [value] =>black,white,green [quantity] => 5)) )I'm trying something like this but it isn't working. <?php //This is the array I want to add to. $product_options = $registry->toObject(); //This is the value of what I want to add to the array. With the key being 'quantity'. $number = $item->orderitem_quantity; ?> <?php foreach($product_options as $key => $quan) ?> <?php $product_options[$key]['quantity'] = $number; ?> <?php endforeach; ?> Edited by Zane, 19 June 2014 - 02:43 PM. Hi I have a multi-dimension session array as per the below: $_SESSION['myarray'][][] If for example there are several elements stored in the array: $_SESSION['myarray'][0][0] = "aaa"; $_SESSION['myarray'][0][1] = "111"; $_SESSION['myarray'][1][0] = "bbb"; $_SESSION['myarray'][1][1] = "222"; $_SESSION['myarray'][2][0] = "ccc"; $_SESSION['myarray'][2][1] = "333"; $_SESSION['myarray'][2][0] = "ddd"; $_SESSION['myarray'][2][1] = "444"; How can i remove one of the above and shunt the other elements up? I have tried using the unset command but this seems to essentailly nullify the desired values where as what i would like to do is remove them completly from the array and then shorten the total number of records stored in the array. Thanks for taking the time to read this. I am having a bit of trouble with the following (just for theoretical purposes of course!). Just wondered how you do the following code: $products = array(); // makes a empty array called $products $i = 1; $icol = 1; while($row = mysql_fetch_array($result)) { $products[$i]['product1'] = $row[$icol][0]; $i = $i++; } All its meant to do is: Quote SELECT * FROM products Which the table contains just 3 columns: productid | product | price 1 | product1 | 25.55 That is it, very simple, but wanted to make a multi dimension array that will be 3 columns wide, then however many rows (hence the while loop and array fetch etc). Any help is appreciated, just coming from a VBA background when it comes to the arrays in VB lol. Thanks for any help in advance, Jeremy. I already know how to empty individual $_SESSION[""] array elements, but I was wondering how you could empty ALL $_SESSION array elements without having to write out unset ($_SESSION[""]); for each one? Is it just unset ($_SESSION);? Sorry if this seems like a stupid question, but I'm just trying to make sure, because I have a lot of $_SESSION variables and am trying to simplify the task of emptying them all. Hey all, I'm well aware of associative arrays (key/value pairs) and how you can index them in an array like this: $character = array (name=>"John", occupation=>"Programmer", age=>22, "Learned language "=>"PHP" ); Then it makes sense to iterate through the key/value pairs of the array using foreach: foreach ( $character as $key=>$val ){ print "$key = $val<br>"; } However, I was watching a video tutorial where he created a $_SESSION array and then created an array associative array: $_SESSION['cart'] = array(); [/PHP] Then he added a function add_to_cart: function add_to_cart($id){ if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]++; return true; } else { $_SESSION['cart'][$id] = 1; return true; } return false; } Now that $id variable holds an id converted to integer from the dataabse. So if first item is clicked, id holds a value of integer 1. When I see this: $_SESSION['cart'][$id] I see an array that holds two indexes, each index containing an associative array: [[array() => ''], [1 => '']]. So at index 0 of $_SESSION is [array() => '']. But then he uses the foreach iterator like this: function total_items($cart){ $items = 0; if(is_array($cart)){ foreach($cart as $id => $qty){ $items += $qty; d } } return $items; } Now I'm very confused. As you can see in that foreach method, it says that $id (and its corresponding value) is an associative array of $cart array, not $_SESSION array. I don't see how that happened. I thought $cart and id$ were distinct indexes of $_SESSION. I don't see how $id is a key of the $cart array. Thanks for any explanation to clear my confusion. Basically what I want to do is create an array of inheritance. so here is the levels Owner->Admin->moderator->User->guest owner has all the abilities of admin, moderator, user and guest.. So I want to be able to sort through them and end with an array like this Code: [Select] $array['Owner'] = array('Admin', 'Moderator', 'User', 'Guest'); Currently my code works sort of. Basically Admin is only set to inherit Moderator. Moderator only inherits User. So this code works but only to 2 levels. I don't want to add a billion foeachs within each other for each level(currently 4) but I might add more roils so then I would have to add more foreachs. There must be a magic way to do this. Any feedback is appreciated! Code: [Select] <?PHP $sql = 'SELECT * FROM '.self::$Config['PERMISSIONS']['Database'].'.permissions_inheritance'; $result = DB::Query($sql); while($row = DB::fetch($result)){ if($row['type'] == '0'){ $group_i[$row['child']][] = $row['parent']; }elseif($row['type'] == '1'){ $user_i[$row['child']][] = $row['parent']; } } //echo count($group_i); print_r($group_i); $groups = array(); foreach($group_i as $Key=>$Value){ foreach($Value as $K=>$V){ $new_array[$Key][] = $V; if(isset($group_i[$V]) && is_array($group_i[$V])){ foreach($group_i[$V] as $Q=>$A){ if(is_array($A)){ foreach($A as $C=>$X){ $new_array[$Key][] = $X; } }else{ $new_array[$Key][] = $A; } } } } } Let me know if you have any questions! I hope you enjoy the challenge lolol This has been so much FUN for me that I couldn't wait to share! I have a page on a Wordpress site using some special functions in the Theme I am running that displays custom fields in a List after a Form has been filled out for a Particular Post Category. On this page the User can see the results of the Form they just filled out and review them before finally submitting them. I have one function which gathers all of the Custom fields associated with that particular post they have made from the "holding table"--an interim saving instead of keeping them all in a session value exclusively. The form they have just filled out produces one string or value per field EXCEPT in the case of multi-value checkboxes. If on this review page any values are gathered whose $field_type is equal to 'checkbox' then it is guaranteed that those values are stored in an array. Right now the problem is that the existing function that gathers and displays all these custom fields simply shows "Array" everytime it handles the values of one of these checkboxes. In those cases where a row's $field_type = 'checkbox' then in every case there will be an associative array stored in brackets [] that I want when detected to be put into visible list of however many values are found. In the sql statement when it gathers the field $field_type values it will find either "text", "dropdown", "textarea", or "checkbox" in the same id row along with the $field_label, $field_name, $field_values for each record. I want to build more conditions and actions here to handle a situation where it runs into an associative array inside the first array of all of the custom fields. I include the whole function I want to modify further down: It starts out -- echo cp_formbuilder_review($results); and I guess I want something along the lines of-- if($results) {foreach ($results as $result) if (is_array($result) { loop through and put individual array elements in an unordered list with the $field_label associated with each checkbox array} else { continue the loop for all other types of custom fields which are not $field_type=checkbox because all of these custom fields will have values in just one string or one value} For testing purposes, so you know what the values look like underlying this page if I use this statement on the page echo '<br/><br/>("$postvals")-- $postvals PRINT<br/>'; print_r; I will get back this for $_POST echo '$_POST PRINT<br/>just the post and nothing more'; print_r($_POST); ( [post_title] => Stunning rental [cp_checkbox_days] => Array ( => Thursday [1] => Friday ) [cp_checkbox_amenities] => Array ( => Gardener [1] => Watchman ) [cp_checkbox_hello] => Array ( => Smoking Allowed: Outdoor areas only ) [cp_price] => 98888 [cp_street] => 888 Flange [cp_city] => Reynaldo [cp_state] => Virginia [cp_country] => Antartica [cp_zipcode] => 1080 [tags_input] => stunner [post_content] => Wow is all we can say about this one. Right now the visual display shows this for Arrays <ul> <li><label><strong>Category:</strong></label> <div id="review">Affordable Rentals</div> <div class="clr"></div> </li> <li> <label><strong>Title:</strong></label> <div id="review">Stunning stunner</div> <div class="clr"></div> </li> <li> <label><strong>help checkbox:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Staff Provided:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Suitability:</strong></label> <div id="review">Array</div> <div class="clr"></div> </li> <li> <label><strong>Price:</strong></label> <div id="review">98888</div> <div class="clr"></div> </li> <li> <label><strong>Street:</strong></label> <div id="review">888 Flange</div> <div class="clr"></div> </li> </ul> So, wherever a value shows up like this [cp_checkbox_days] => Array ( => Thursday [1] => Friday ) I need for this array to be iterated and broken up into <li>Thursday</li> <li>Friday</li> HERE IS THE CODE MORSEL that is UNDERPERFORMING! I am hoping a genius like DavidAM can soup this thing up! function cp_show_review($postvals) { global $wpdb; // if there's no form id it must mean the default form is being used so let's go grab those fields if(!($postvals['fid'])) { // use this if there's no custom form being used and give us the default form $sql = $wpdb->prepare("SELECT field_label, field_name, field_type, field_values, field_req " . "FROM ". $wpdb->prefix . "cp_ad_fields " . "WHERE field_core = '1' " . "ORDER BY field_id asc"); } else { // now we should have the formid so show the form layout based on the category selected $sql = $wpdb->prepare("SELECT f.field_label,f.field_name,f.field_type,f.field_values,f.field_perm,m.meta_id,m.field_pos,m.field_req,m.form_id " . "FROM ". $wpdb->prefix . "cp_ad_fields f " . "INNER JOIN ". $wpdb->prefix . "cp_ad_meta m " . "ON f.field_id = m.field_id " . "WHERE m.form_id = '". $postvals['fid'] ."'" . "ORDER BY m.field_pos asc"); } $results = $wpdb->get_results($sql); if($results) { // loop through the custom form fields and display them echo cp_formbuilder_review($results); //from here is where I have to switch to detecting the Arrays associated with checkboxes and explode them and loop them separately into something pretty with its own field_label //and when it has looped through all the Arrays and made them visible it continues looping through the rest of the single value strings and fields } else { echo sprintf(__('ERROR: The form template for form ID %s does not exist or the session variable is empty.', 'cp'), $postvals['fid'] . "\n\n"); } ?> Looks pretty darn easy doesn't it?? Hello,
I've been struggling to get array_multisort to work...
If I have this array output...
I'd like to sort on the product sub-array.
The array is called orders and that number 15 is the specific order id.
Array ( [15] => Array ( [clientId] => 1 [clientName] => Bob [o_date] => 2014-01-02 [o_number] => 1 july-append [o_notes] => order on 1 july-append [i_date] => 2014-01-17 [i_number] => 18072014-append [i_notes] => invoiced on 18 july 14 -append [products] => Array ( [0] => Array ( [id] => 37 [prod_id] => 1 [product] => door [qty] => 2 [cost] => 12.121 ) [1] => Array ( [id] => 38 [prod_id] => 2 [product] => window [qty] => 3 [cost] => 22.5 ) [2] => Array ( [id] => 36 [prod_id] => 3 [product] => chair [qty] => 1 [cost] => 300 ) ) ) )So, I've tried a number of variations of this... array_multisort($orders[$theOrder]['products'], SORT_DESC, SORT_NUMERIC, $orders[$theOrder]['products'], SORT_ASC, SORT_STRING); array_multisort($orders[$theOrder]['products']['id'], SORT_DESC, SORT_NUMERIC);etc. etc. - but I seem to get no-where. Can some-one kindly point out my error, please? Thank you. Hi guys, I've done a bit of research into sorting a multi-dimensional array that contains the menu information (to be parsed and displayed). Everything that I've read has confused me more than I was when I started. I want it to be sorted by parent (ASC) then by it's sort number (ASC). Code: [Select] Array ( [0] => Array ( [0] => 2 [id] => 2 [1] => About Us [label] => About Us [2] => ?r=about [link] => ?r=about [3] => [relation] => [4] => 0 [parent] => 0 [5] => 10 [sort] => 10 [6] => 0 [active] => 0 ) [1] => Array ( [0] => 3 [id] => 3 [1] => Fleet [label] => Fleet [2] => ?r=about/fleet [link] => ?r=about/fleet [3] => [relation] => [4] => 2 [parent] => 2 [5] => 0 [sort] => 0 [6] => 0 [active] => 0 ) [2] => Array ( [0] => 4 [id] => 4 [1] => Test [label] => Test [2] => ?r=test [link] => ?r=test [3] => [relation] => [4] => 0 [parent] => 0 [5] => 5 [sort] => 5 [6] => 1 [active] => 1 )) Thank you in advance for any help Hello fellow coders! My brain is about to explode! Does anyone have some time to help me with a small problem? I have two multi-dimensional arrays similar to the below: Code: [Select] mysql_table_schedule [0] [firstname] = Roger [id] = xxx [1] [firstname] = Pamela [id] = xxy mysql_table_roster [0] [firstname] = Roger [id] = xxx [1] [firstname] = Pamela [id] = xxy [2] [firstname] = Orsen [id] = xyy I can build both arrays above after grabbing the data from the MySQL database by using a quick for function Code: [Select] for($i = 0; $array[$i] = mysql_fetch_assoc($mysql_roster); $i++) ;but after I have both arrays how do I keep only the records in mysql_table_roster that are in the schedule. Out of each daily schedule only a few people work. I'd like to keep all of the associated information from the roster like first name, last name, phone number, etcetera. If yesterday only Roger and Pamela worked how do I compare by [firstname] and trim the mysql_table_roster to inlclude only the arrays related to Roger and Pamela? I've looked into array_intersect, but have no clue how to specify a comparison by a specific array key within multi-dimensional arrays. Hello!
First of all, I'm new here. I've been working with PHP for a few months and am really enjoying its capabilities
A little background on the project I'm doing at the mo, I'm creating a small dashboard for grabbing Twitter stats via the API. The result will eventually output in a pretty table showing the daily followers, follower gains (or losses) etc. Here's an example of the table I eventually want to end up with.
So far I have two arrays of data:
$accounts_data is a list of all account names and their associated ID's
$followers_data is a list of all follower counts, for a specific time of day, with an associated account ID (which matches the ID found in $accounts_data, thus pairing the follower count to a specific account)
I'm now trying to combine these two arrays into something more sensible that can then be used to output the table as shown in the link above.
$accounts_data:
array(4) { [0]=> array(2) { ["id"]=> string(4) "1279" ["name"]=> string(13) "AccountName1" } [1]=> array(2) { ["id"]=> string(4) "1280" ["name"]=> string(10) "AccountName2" } [2]=> array(2) { ["id"]=> string(4) "1281" ["name"]=> string(12) "AccountName3" } [3]=> array(2) { ["id"]=> string(4) "1283" ["name"]=> string(11) "AccountName4" } }$followers_data (truncated this data) array(12) { [0]=> array(3) { ["account_id"]=> string(4) "1279" ["date_time"]=> string(19) "2014-11-14 09:00:03" ["followers"]=> string(4) "1567" } [1]=> array(3) { ["account_id"]=> string(4) "1280" ["date_time"]=> string(19) "2014-11-14 09:00:29" ["followers"]=> string(4) "7688" } [4]=> array(3) { ["account_id"]=> string(4) "1279" ["date_time"]=> string(19) "2014-11-14 16:30:35" ["followers"]=> string(4) "1566" } } Hello, here is the PHP situation I'm in. I'll type it out in pseudo-ish code first. <?php $multi_array = array( array("cats", "dogs", "sheep", "walruses"), array("jazz", "larva", "pencils", "derp"), array("to", "much") ); $string = array("the", "cats", "ate", "too", "many", "pencils"); $count = count($string); for($i = 0; $i < $count; ++$i) { if($string[$i] IN ARRAY $multi_array) { THEN replace $string[$i] with a random word in the sub array of the multi-array for example, if $string[$i] is cat, then it would replace it with any of the words in the sub array of multi-array, so it could be "cats", "dogs", "sheep", or "walruses" } } ?> I have no idea how to do this and tried thinking of ways for an hour and a half.
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Hi, how to identify whether the array is single or two dimensional array? example structure of text database- mytextfile.txt 10-11201|2010/09/01|Sam|Thurston 10-11307|2010/09/04|Tony|Piper 10-11405|2010/09/11|Sarah|Smith <?php $file2 = 'mytextfile.txt'; $openedfile =fopen($file2, "r") or die("ERROR- could not open file for editing."); // flock($openedfile, LOCK_EX) or die("Error!- Could not obtain exclusive lock on the file to edit."); $hold[$record_count] = explode("|", trim(fgets($openedfile))); while(!feof($openedfile)) { $record_count++; $hold[$record_count] = explode("|", trim(fgets($openedfile))); } ?> What I need to do is loop through this and one by one- take any arrays that contain a date that is between $dateX and $dateY (which comes via a form input) and place it in a new array $matched. I am stumped. 1-Is there a way to do it inside the above while loop that I am not seeing? 2- Do I need to open the file in another manner? 2- Would it be best to now loop through $hold[$record_count] I am trying to keep the process short so as not to use up too much memory. Point me in the right direction for this one please. I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
Below is my image upload and resize script. The issue I am running into is when an image is wider than 800px (i'm not even sure how much wider, i just know that an image that is 800px wide will upload, but larger ones won't). Anyway, is there a "dimension limit" on images when using "imagecopyresized"? Thank you for your time? Code: [Select] $uploaddir3 = "/my/server/path/coname/images/"; $thumbDirectory3 = "/my/server/path/test"; $thumbWidth3 = "640"; $target_encoding3 = "ISO-8859-1"; echo '<pre>'; if(count($_FILES) > 0) { $arrfile3 = pos($_FILES); $uploadfile3 = $uploaddir3 . iconv("UTF-8", $target_encoding3,basename(strtoupper($arrfile3['name']))); if (move_uploaded_file($arrfile3['tmp_name'], $uploadfile3)) echo "File is valid, and was successfully uploaded.\n"; $imageName3 = basename(strtoupper($arrfile3['name'])); function createThumbnail3($uploaddir3, $imageName3, $thumbDirectory3, $thumbWidth3) { $srcImg3 = imagecreatefromjpeg("$uploaddir3/$imageName3"); $origWidth3 = imagesx($srcImg3); $origHeight3 = imagesy($srcImg3); $ratio3 = $thumbWidth3 / $origWidth3; $thumbHeight3 = $origHeight3 * $ratio3; $thumbImg3 = imagecreatetruecolor($thumbWidth3, $thumbHeight3); imagecopyresized($thumbImg3, $srcImg3, 0, 0, 0, 0, $thumbWidth3, $thumbHeight3, $origWidth3, $origHeight3); imagejpeg($thumbImg3, "$thumbDirectory3/$imageName3"); } createThumbnail3("/my/server/path", "$imageName3", "/my/server/path/coname/images/test", $thumbWidth3); } else { } |