-
Posts
5,454 -
Joined
-
Days Won
175
Community Answers
-
mac_gyver's post in incremental number for each table row was marked as the answer
actually, naming form fields (variables, db column names, or anything else) with an incremental number is a bad design that takes more code to produce the markup and process the data.
you should use an array name for the form fields. - name="School[]", name="Student[]", and name="Class[]".
this will submit the data as a php array for those field names, that you can simply loop over and access the values from each set of form fields within the group.
-
mac_gyver's post in insert a query after getting a query was marked as the answer
i recommend that you tell or show us what symptom or error you are getting that leads you to believe that something doesn't work. we are not sitting there with you and don't know what it is you are seeing in front of you.
why are you using both the msyql and mysqli extensions in one script? do you even have a connection using the mysql extension? there would be php error's if you don't. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects?
your code should ALWAYS detect and handle errors with database statements, so that it doesn't try to run logic that's dependent on database statements working when they haven't and test to make sure that a query matched a row of data before using the data.
why are you using a multi_query() statement for a single query? this opens the door for sql injection to run ANY type of query, especially since you are not doing anything to protect against sql injection. even if you currently trust the data source, someone at some point can get nefarious data onto the site you are getting your data from. you must ALWAYS protect against sql injection.
btw - the php mysql extension has been removed from php for almost a year. you should not be using it at all at this point in time.
-
mac_gyver's post in PHP Error - mysqli_result, boolean given was marked as the answer
return, the point where the sql syntax error is occurring at is a reserved mysql (database server) keyword. are you sure the original query wasn't as follows, with back-ticks around the table name -
"SELECT * FROM `return` WHERE nMemberID='$nMemberID' AND nInfoID='$nInfoID' ORDER BY nReturnID DESC"; next, just converting the mysql_ statements to mysqli equivalents is not enough. you must also safely supply data values to the sql query statement. if $nMemberID or $nInfoID are coming from external data or they could contain any sql special characters, they must either be properly escaped (see the mysqli real escape string function/method) or you need to use a prepared query with place-holders in the sql statement for the data values and then bind the actual data to the place-holders. a prepared query is actually the best choice since it is impossible for injected sql in the data to be treated as sql syntax, whereas using the escape string function must have the proper character encoding set for the database connection to match what the database tables are set up for.
-
mac_gyver's post in Skipping first line of db was marked as the answer
look at your code, between where you are executing the sql query and where you are looping over the data from that query.
-
mac_gyver's post in jQuery Sortable Portlet Save position to database was marked as the answer
so, i went through your code to figure out what it is doing, in order (pun intended) to figure out how to make this work.
starting with your html markup -
1) the id='...' attribute you have for the column div's, should start with a letter, to make them valid. i choose to use id='COL_n', where n = 1, 2, ..., 6
2) the portlet div's needs an id attribute so that the serialize/toArray functions have something to use as data. i choose to use id='ID_n', where n is the job id auto-increment column value from your database table (if you don't have a job id, you need one.)
3) to allow the php code to dynamically produce the html, for the different status values 1-6, you need a way of mapping the status value to the display label - 'New' through 'To Be Invoiced'. i choose to use an array, and since you (probably) want to output each status section, regardless of if there is any data for it, you would loop over this array to produce the sections on the page, then loop over any data for each section.
the html, from the <div style="clear:both;"></div> to the end of the page should look more like the following (note: data values that you output to the browser should be passed through htmlentities(). this is not in the example code and is left up to you as a programming exercise) -
<?php // define status value to label mapping $status_map = array(); $status_map[1] = 'New'; $status_map[2] = 'Artwork Rec'; $status_map[3] = 'Approved & Ordered'; $status_map[4] = 'In Production'; $status_map[5] = 'Delivered'; $status_map[6] = 'To Be Invoiced'; // query for all the data you want, in the order that you want it $query = "SELECT * FROM jobs ORDER BY status ASC, job_title DESC"; $result = mysqli_query($con,$query); $data = array(); while($row = mysqli_fetch_assoc($result)) { $data[$row['status']][] = $row; // index/pivot the data using the status value - 1..6 } // note: i used some made-up data in the $data array at this point. the above query code should work, but is untested. // loop over the data and produce the output foreach($status_map as $key=>$label) { echo "<div class='column' id='COL_$key'>\n"; echo "<h3>$label</h3>\n"; if(isset($data[$key])) // is there any data from the database for this key/status { foreach($data[$key] as $row) { echo "<div class='portlet' id='ID_{$row['id']}'>\n"; echo "<div class='portlet-header'>{$row['job_title']}</div>\n"; echo "<div class='portlet-content'><a href='pdfs/{$row['pdf_link']}' target='_blank'>View PDF</a></div>\n"; echo "</div>\n"; } } echo "</div>\n"; } ?> </body> </html> next, the jquery you have that is using an id selector - "#portlet" should be removed since this exercise is operating on a class basis, not an id. also, you would not use the update : method, since this triggers for every column that gets updated. if you move something from one column to another, it triggers two times. you need to use the stop : method. see the following javascript/jquery that i came up with -
<script> $(document).ready(function(){ $( ".column" ).sortable({ connectWith: ".column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all", stop: function() { var dat = []; var i = 0; $(".column").each(function() { dat[i++] = [this.id,$(this).sortable("toArray")]; // this.id is the column id, the 2nd element are the job id's in that column }); $.ajax({ method: "POST", url: "save_order.php", data: { data: dat } }); } }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).on( "click", function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); </script> this will submit an array of data to the .php file, in $_POST['data']. see the following example code that extracts the column number and job id (if any), and logs the information to log.txt -
<?php // for some reason, the portlet toArray 'adds' an empty element to the start of each array if(isset($_POST['data'])) { foreach($_POST['data'] as $arr) { //$arr[0] is the column id - COL_1, COL_2 (these are the status number 1-6 = New - To Be Invoiced) //$arr[1] is an array of the ids that are in the column - ID_1, ID_5 // get the status (column) number list($not_used,$status) = explode('_',$arr[0]); // get the id's in each status/column $arr[1] = array_filter($arr[1]); // remove empty elements if(empty($arr[1])) { // an empty status/column $str = "Status: $status, empty"; file_put_contents('log.txt',print_r($str,true)."\n",FILE_APPEND); } else { // non-empty status/column foreach($arr[1] as $element) { // get the id number list($not_used,$id) = explode('_',$element); $str = "Status: $status, Id: $id"; file_put_contents('log.txt',print_r($str,true)."\n",FILE_APPEND); } } } } -
mac_gyver's post in Hi, how to have jquery check if one of several select menus have quantity select allow submit... was marked as the answer
assuming that you want to look at all the select/option menus and they all have class='qty', you would loop over each of the elements with that class -
$(document).ready( function() { $('input[type="image"]').click( function() { var total = 0; $( ".qty" ).each(function() { total += Number($( this ).val()); }); if(total == 0) { alert("You have not selected a product quantity!"); return false; } }); }); -
mac_gyver's post in mysql query not working with drop down boxes was marked as the answer
promised example code -
// define, or get from an sql query, the choices for the select/option menus $author_data = array(); $author_data[] ="ken davies"; $author_data[] = "arthur smith"; $author_data[] ="gill rafferty"; $author_data[] ="molly brown"; $author_data[] ="gilbert riley"; // define and populate the data for the other select/option menus. left up to you as a programming exercise. $genre_data = array(); $year_data = range(2002,2008); $publisher_data = array(); // define a list/array of expected inputs for the dynamic WHERE clause $choices = array(); $choices[] = 'author'; $choices[] = 'genre'; $choices[] = 'year'; $choices[] = 'publisher'; // produce the dynamic WHERE clause $and_terms = array(); // holds each term for the WHERE clause // loop over the defining array of choices foreach($choices as $choice) { if(isset($_GET[$choice])) { // the choice is set, add it to the terms to use $and_terms[] = "`$choice` = '$_GET[$choice]'"; // you need to either - validate that the input value is exactly one of the possible choices, properly escape the value using the database escape string function, or use a prepared query to supply the value to the sql statement. left up to you as a programming exercise. } } // db connection - convert to PDO and use exceptions to handle errors. left up to you as a programming exercise. $con = mysql_connect("localhost","root",""); If (!$con){ die("Can not Connect with database" . mysql_error()); } mysql_select_db("authors",$con); $where_clause = !empty($and_terms) ? 'WHERE ' . implode(' AND ', $and_terms) : ''; // build the sql query statement $sql = "SELECT * FROM books $where_clause"; // execute the query and retrieve the data into an array $result_data = array(); $myData = mysql_query($sql,$con); while($row = mysql_fetch_assoc($myData)) { $result_data[] = $row; } // start the html document/template ?> <html> <head> <title>My Page</title> </head> <body> <br> <form> <select name="author" size="2"> <?php foreach($author_data as $value) { $sel = isset($_GET['author']) && $_GET['author'] == $value ? ' selected': ''; echo "<option value='$value'$sel>$value</option>\n"; // you need to apply htmlentities() to any data being output. left up to you as a programming exercise. } ?> </select> <input type = "submit" value = "go"> <select name="genre" size="4"> <?php // use code similar to the above to produce each set of select/option choices. left up to you as a programming exercise. ?> <option value="adventure">adventure</option> <option value="biography">biography</option> <option value="crime">crime</option><br /> <option value="romance">romance</option> <option value="thriller">thriller</option> </select> <input type = "submit" value = "go"> <select name="year" size="4"> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> </select> <input type = "submit" value = "go"> <select name="publisher" size="4"> <option value="blue parrot">blue parrot</option> <option value="yonkers">yonkers</option> <option value="zoot">zoot</option> </select> <input type = "submit" value = "go"> </form> <?php // you need to use css to style your table border. left up to you as a programming exercise. echo"<table border='3'> <tr> <th>id</th> <th>author</th> <th>title</th> <th>publisher</th> <th>year</th> <th>genre</th> <th>sold</th> </tr>"; foreach($result_data as $row) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; // you need to apply htmlentities() to any data being output. left up to you as a programming exercise. echo "<td>" . $row['author'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['publisher'] . "</td>"; echo "<td>" . $row['year'] . "</td>"; echo "<td>" . $row['genre'] . "</td>"; echo "<td>" . $row['sold'] . "</td>"; echo "<tr />"; } echo "</table>"; ?> </body> </html> -
mac_gyver's post in Why Warning "Cannot modify header information" Is NOT Fired ? was marked as the answer
For the case you have just posted, php's output buffering is turned on in the php.ini or possibly .htaccess file (if php is running as a server module) on your server. You can determine this by looking at the output from a phpinfo() statement.
-
mac_gyver's post in My code is broken *somewhere* was marked as the answer
textarea's don't have value='...' attributes. you output the existing content in between the <textarea>content goes here</textarea> tags.
-
mac_gyver's post in Foreach loop doesn't bring all the records from the database was marked as the answer
setting php's error_reporting to E_ALL and display_errors to ON (which should already both be set this way in the php.ini on your development system), should help with finding the cause of the problem.
does the 'view source' of the page show all the repeated sections of content? maybe there's a broken html comment or tag that's preventing the output from being rendered by the browser.
also, does the content, that's after the end of the loop, get displayed?
-
mac_gyver's post in looping results from query and limit amount per row was marked as the answer
you will also want to JOIN the image table, whatever its name is, with the products table, so that you can run just ONE query. and did you really name the database column catagory, rather than category?
your code should look like this -
$items_per_row = 5; // number of items per output row $query = "SELECT p.id, p.catagory as category, p.name, p.make, i.name as imgName FROM products p JOIN $table3 i ON p.id = i.insert_id ORDER BY p.catagory, p.make, p.name"; // execute query using PDO, $pdo contains an instance/connection to the msyql database server $stmt = $pdo->query($query); // pre-process the data and index it by category, creating an array of arrays with the main index being the category $data = array(); foreach($stmt as $row) { $data[$row['category']][] = $row; } // produce the output from the data foreach($data as $category => $arr) { // Create a table with an id name of the category echo "<table width='100%' id='$category'>\n"; // Write the first row of the table - Category Title echo "<tr><td><span class='catTitle'>$category</span></td></tr>\n"; // output the rows of data $chunks = array_chunk($arr, $items_per_row); foreach($chunks as $chunk) { echo "<tr>"; // start a new row foreach($chunk as $row) { // Write new <td> in table with the data of the title echo '<td width="20%" class="cellPadd"><a href="product.php?id=' . $row['id'] . '"><div class="latest"><div class="latestTop">'; echo "<img class='latestImg' src='images/listings/" . $row['imgName'] . "' border='0' width='100%' />"; echo '</div><div class="latestBottom">'; echo $row["make"]; echo $row["name"]; echo "</div></div></a></td>\n"; } // complete a partial row $count = count($chunk); if($count < $items_per_row) { echo str_repeat("<td> </td>\n", $items_per_row - $count); } echo "</tr>\n"; // end the row } echo "</table>"; // end the table } -
mac_gyver's post in how to make this pagination work with search results? was marked as the answer
i don't really think i can help you 'get' what it is you need to do to be able to write code that does something useful. you are randomly changing code, because you haven't taken the time to learn what the statements in the code actually mean and do, then dumping the code on a forum for someone to tell you what to do to fix it. you won't learn anything by getting some to fix your code for you.
some problems in the posted code - you are no longer preparing the query, yet you are trying to bind parameters to it. you are using a wrong PDO defined constant in the bindParm() statement, you are using global $per_page; that does absolutely nothing in the context of this code.
the only thing you are currently doing different, from at the start of this thread, is changing the sql query statement, specifically just the WHERE ... term. the only code you need to change are the lines that are building the WHERE term. the rest of the code needs to remain the same. and even you were doing this for a completely different sql query statement, the only things you would change in the code are the two queries, the SELECT COUNT(*) ... query , that gets the total number of matching rows and the SELECT list of columns ... query, that retrieves the matching data.
this is the code, from reply #10, that is building the WHERE term -
// define the possible search fields - this is used to produce a data driven/dynamic design, where you don't write out block after block of code that only differs in the value it operates on $search_fields = array('title','name','description'); $and_terms = array(); // WHERE terms to be AND'ed $params = array(); // bound input parameters for a prepared query foreach($search_fields as $field) { if(isset($_GET[$field]) && $_GET[$field] != 'ALL') // only if the field is set and it's not 'ALL' { // add the search field to the WHERE terms $and_terms[] = "$field = :$field"; $params[] = array(":$field",$_GET[$field],PDO::PARAM_STR); } } $where_term = ''; if(!empty($and_terms)) { $where_term = "WHERE " . implode(' AND ', $and_terms); } all you have to do is change this section of code so that it produces WHERE memberID = :memberID as the where term and then add the correct entry to the $params array for the $_SESSION['memberID'] value. in its simplest, bespoke form, this is what you would have left -
$params = array(); // bound input parameters for a prepared query $where_term = "WHERE memberID = :memberID"; $params[] = array(":memberID",$_SESSION['memberID'],PDO::PARAM_INT); the rest of the code, starting with - $query = "SELECT COUNT(*) FROM table $where_term"; doesn't change, unless you want it to do something differently, such as output the data differently or you want the pagination links to be different.
-
mac_gyver's post in Updateing Software Apache/PHP/Mysql was marked as the answer
the php.net documentation has migration sections in the appendix that lists the major changes that have been made to the language. if your code is dependent on any of the Backward Incompatible Changes, from the starting php version you were using to the final php version you have now, you will need to rewrite that portion of your code.
we cannot specifically help you since we don't know what exact method, among all the possibilities available in programming, your code is using. you would need to post enough of your code that reproduces each problem to get specific help.
-
mac_gyver's post in Array Question (Issue)... was marked as the answer
you are probably storing some white-space in with the data, which you should be storing not as a comma separated list, but as a separate row in the table for each check box that's checked.
what exactly does the $row['hw_lev'] look like using var_dump($row['hw_lev']);
-
mac_gyver's post in .= causing errors was marked as the answer
that will fix the immediate issue of the simple html dom class not running, when it's not where the error is at. any php error, no matter how benign, prior to using the load() method, will cause this problem.
you should be defining/assigning the first line to the variable before using a concatenate operator on it anyway. every error in your code, even if the reporting/display/logging is turned off, is still being detected and handled by php. the reporting/display/logging is just the last step in the php error handling.
-
mac_gyver's post in getting error : Catchable fatal error was marked as the answer
when you build the query string part of links, you should use a function like http_build_query(). this will let you take any existing $_GET parameters, add/remove/modify any of them, then produce the part of the link after the ? -
$get = $_GET; // get a copy of any existing get parameters. you only need to do this once // in your pagination link code, for each link you produce $get['currentpage'] =1; // set the current page to whatever value you want $qs = http_build_query($get, '', '&'); // produce the query string part of the link echo "<span class='rest'> <a href='?$qs><<</a> </span>"; // output the link. note: i removed the use of $_SERVER['HTTP_SELF'] since it is open to cross site scripting and it's not necessary in modern browsers -
mac_gyver's post in PHPMailer error on line 3042 class.phpmailer.php was marked as the answer
phpmailer should (according to the documentation) work for any php 5+ version (5.4+ if you are using oauth.)
however, assuming you are using the latest version of php mailer, that particular section of code IS using php syntax that was introduced in php 5.3 and will throw a parse/syntax error for lower versions. the php version check logic they put in that particular code doesn't have any affect because the code never runs when there is a syntax error.
you can edit the section of code for the clearQueuedAddresses method so that it only contains the first set of conditional logic.
you could also put the section of code that's in the else{} conditional statement, that's using the php5.3+ syntax, into an external file and require it in place of the in-line code. the require statement will only be executed if the else{} condition is true and this won't throw a parse/syntax error since the code in the required file is only evaluated when the require statement is executed.
you can also (at your own risk) download and use older versions of php mailer - https://github.com/PHPMailer/PHPMailer/releases
-
mac_gyver's post in How do I automate this script to create individual CSV files? was marked as the answer
the following implements your logic, saving the output from each input .htm file to a corresponding .csv file -
<?php ini_set('display_errors',1); error_reporting(E_ALL); $stats_wanted = array('playedPositionsShort', 'name', 'playerId', 'age', 'rating', 'shotOnTarget', 'shotsTotal', 'penaltyScored', 'penaltyMissed', 'passLongBallAccurate', 'passLongBallTotal', 'passTotal', 'passCrossAccurate', 'passCrossTotal', 'passThroughBallTotal', 'passThroughBallAccurate', 'keyPassTotal', 'dribbleWon', 'dribbleTotal', 'tackleWon', 'tackleLost', 'tackleWonTotal', 'tackleTotalAttempted', 'challengeLost', 'interceptionLost', 'penaltyTaken', 'interceptionAll', 'clearanceTotal', 'offsideGiven', 'offsideProvoked', 'foulGiven', 'foulCommitted', 'dispossessed', 'duelAerialWon', 'duelAerialLost', 'duelAerialTotal', 'touches', 'totalPasses', 'offsideWonPerGame', 'offsideGivenPerGame', 'passSuccessInMatch' ); $keys = array_flip($stats_wanted); // change stats wanted into keys $source_path = 'directory/'; $dest_path = ''; // enter the path, with trailing /, where you want the destination files to be written foreach (glob("$source_path*.*") as $filename) { echo "Processing: $filename<br>"; $info = pathinfo($filename); // get the ['filename'] $content = json_decode(file_get_contents($filename),true); // read file contents as an array $output = fopen("$dest_path{$info['filename']}.csv",'w'); // create output file fputcsv($output, $stats_wanted); // write header line to file // loop over players in the data foreach($content['playerTableStats'] as $arr){ $arr = array_intersect_key($arr,$keys); // keep only the stats wanted elements fputcsv($output, $arr); // write the data to the file } fclose($output); // close the current file } this makes the same assumption that your code does, that the order of the $stats_wanted elements matches the order that the data elements will exist as. if not, you can throw in a sort operation before writing the data to the file.
-
mac_gyver's post in login redirect blank page? was marked as the answer
what debugging have you done to narrow down the problem? have you dumped (see: var_dump()) the role value so that you know what if anything it is?
are you sure that login success code is even running for the users with those roles?
if all your code is doing is mapping a set of values to other values, you shouldn't write out conditional logic (if/elseif/switch/case) for each possible choice. this will require that you edit the program logic just to add, remove, or change any of the possible choices. it also makes for cluttered code, which i just noticed is the cause of your problem. you have a missing {, which has made all your conditional logic off a bit. properly indenting your code, based on where matching { and } are at would help you make sure all the { and } are where you intend.
you should instead write general purpose, data driven code, that defines data (arrays) that tells simple code what to do. see the following example -
// define categories of roles (in a configuration file) $management = array('Admin', 'Manager', 'Front_Desk'); $staff = array('Writer'); // at the point of decided what to do for the category a role belongs to if(in_array($role,$management)){ header("location: reservation.php"); exit; } elseif (in_array($role,$staff)){ header("location: articles.php"); exit; } else { // none of the defined roles, handle that condition here... } next, logging someone in, involves identifying who they are, not what permissions/roles they have, which is a different concern/different process. all your login code should do, when the username/password has been confirmed, is to store the user_id in a session variable. after your post method form processing code successfully runs (with no errors), it should do a header() redirect to the exact same url that the form submitted to. this will cause a get request for the page, which stops the browser from trying to resubmit the form data.
when each page gets requested, it should take the user_id from the session variable and query for the current user permissions/role. this will insure that any change made to a user's permissions/roles take affect on the very next page request. any page should take the user permissions/role and use them to determine what will be processed on the page and what will be displayed.
-
mac_gyver's post in Special text sort of array? was marked as the answer
the examples in the documentation, SELECTing the value returned by the FIELD() statement are only to demonstrate what value is returned for each example. imagine calculating that value for each row of data in the result set and ordering the data by that value -
ORDER BY FIELD(cstype,'main character in', 'secondary cast in', 'appears in', 'cameo appearance in') -
mac_gyver's post in Additional AND criteria was marked as the answer
because of the meta key/value pairs, that you want to match two different sets of, you need to join with the woocommerce_order_itemmeta twice, once for each set of values. the following (untested) should work -
SELECT oi.order_item_id, oi.order_id, pm.post_id, pm.meta_value, u.ID, u.user_nicename, oim_t1.meta_key, oim_t1.meta_value, oim_t2.meta_key, oim_t2.meta_value FROM $wpdb->postmeta pm INNER JOIN $wpdb->users u ON pm.meta_value = u.ID INNER JOIN $wpdb->woocommerce_order_items oi ON pm.post_id = oi.order_id INNER JOIN $wpdb->woocommerce_order_itemmeta oim_t1 ON oi.order_item_id = oim_t1.order_item_id AND oim_t1.meta_key = '_wcs_migrated_subscription_status' AND oim_t1.meta_value = 'active' INNER JOIN $wpdb->woocommerce_order_itemmeta oim_t2 ON oi.order_item_id = oim_t2.order_item_id AND oim_t2.meta_key = '_product_id' AND oim_t2.meta_value = '20' WHERE pm.meta_key = '_customer_user' -
mac_gyver's post in Get Data from URL Variables was marked as the answer
yes, the } you have on line 114 does close the function definition.
the error is due to the Heredoc closing tags (two places) being indented. they must be the only thing on a line and cannot have any characters before them on the line and can only have a ; and a newline after them on the line.
the color highlighting in your programming editor should have stopped changing at the first EOF; to alert you to this problem (all the code after that point is considered to be part of the string.)
-
mac_gyver's post in Inconsistent Sessions was marked as the answer
this is a sign that the host-name/sub-domain part of the url (the www. vs no www.) is inconstant and is changing due to the redirects and your session cookie setting for the domain isn't set to match all variations of your domain name. the php.net documentation tells you how to set it so that it does, but your code should also be consistent in the variation of your domain name that is being used.
you also need a exit; statement after the header() redirect to prevent your code on the protected page from running while the browser is requesting the target url in the redirect. this could also be the cause of unusual session operation, if the rest of your code on the page is clearing or modifying the session variables.
lacking a real permission system, you need to use in_array() to test if a value is or is not one of several possible choices. your code would end up looking like -
// define the user types that are admins - $admin_types = array("Admin","Owner","Moderator"); // test if the current user is not an admin type if(!in_array($_SESSION['SalesCRMA'],$admin_types) { header('Location: http://www.mysite.com/logout.php'); exit; } -
mac_gyver's post in Combine Arrays-Not Merger was marked as the answer
array keys/indexes must be unique, so your anticipated result is not possible.
not knowing why are you doing this, what you are ultimately using the data for, which would produce the best result, i would recommend making an array with the start value as the main array key and the (start)/title/description data as sub-arrays under any start value. it would look like -
$data['201601221400'][0] = array('start' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.' ); $data['201601221400'][1] = array('start' => '201601221400', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.' ); $data['201601221400'][2] = array('start' => '201601221400', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.' );
you would produce this by looping through the data, using the 'start' value as the main array key and appending an array consisting of the start, title and desc -
$data = array(); foreach($items as $arr){ $data[$arr['start']][] = $arr; } echo '<pre>'; print_r($data); -
mac_gyver's post in Split Array of Variable Length was marked as the answer
you would use a html array name for the rec form field, where the array key is the SKU number - name='rec[1769057]'
this will result in an array in $_POST['rec'] that you can use php's array functions on, such as a foreach(){} loop to loop over.the elements when providing data to your sql query.