-
Posts
5,448 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
shuffle should not produce the same result each time. with a small set of data, you may see the same result multiple times, but it should not be the same result every time. did you try it more than once and what's your current code?
-
the URL you are building and using in the AJAX request would need to have the subcat=x parameter, in addition to the page=y parameter.
- 1 reply
-
- php
- pagination
-
(and 2 more)
Tagged with:
-
your value=' ... ' has got a leading space in it (after the first " and before the ' )
-
i have a recommendation for using a switch/case statement to map one value to another, especially since you already have an array that is mapping one value to another. don't use a switch/case statement to map one value to another, just expand your existing array. this will significantly reduce the amount of code and will point out things like missing values (your posted code doesn't handle the 'flood' value for $typeKey.) your array - $stormTypesAry['tornado'] = array('name' => 'Tornado', 'color' => 'rgba(128, 128, 128, 0.4)'); $stormTypesAry['funnelcloud'] = array('name' => 'Funnel Cloud', 'color' => 'rgba(255, 222, 173, 0.4)'); $stormTypesAry['wallcloud'] = array('name' => 'Wall Cloud', 'color' => 'rgba(255, 20, 147, 0.4)'); $stormTypesAry['rotation'] = array('name' => 'Rotation', 'color' => 'rgba(255, 228, 181, 0.4)'); $stormTypesAry['hail'] = array('name' => 'Hail', 'color' => 'rgba(255, 255, 0, 0.4)'); $stormTypesAry['wind'] = array('name' => 'Wind', 'color' => 'rgba(255, 0, 0, 0.4)'); $stormTypesAry['flood'] = array('name' => 'Flood', 'color' => 'you don\'t have an entry for this'); $stormTypesAry['flashflood'] = array('name' => 'Flash Flood', 'color' => 'rgba(255, 165, 0, 0.4)'); getting both values at once, without writing line after line of hard coded logic for each value - // get the stormType and reportColor using the $typeKey $stormType = $stormTypesAry[$typeKey]['name']; $reportColor = $stormTypesAry[$typeKey]['color']; // this line takes the place of all the switch/case logic also, by having less code, it will be easier to see the errors in your logic.
-
how are you producing the value in $_POST['horse']? it might have a non-printing character as part of it that echoing it doesn't show.
-
break the file up into smaller pieces and send one at a time or don't try to send it as an email attachment.
-
you are making this harder that it is. a function should do one thing really well. a function named get_value() should just do that one thing. a function should also return the value so that you can use the function in any context. if you use the function in your form, you can echo the returned value. if you need to put the value into a query, you can call the function at the point where you are putting values into a query.
-
if you have an arbitrary list of data you are traversing, you must find the next/previous based on the current id that was submitted, either by querying the database where you originally got the list from or by storing the list in a session variable.
-
the error mentions an amount of memory larger than the file because the output from base64_encode is about 2/3 larger than the original.
-
your get_value() function should do one thing, what its name implies. it should get the value from the correct $_SESSION variable. all the values should either be in session variables or they don't exists at all at the point where you are building the form and if they do exist they should have been stored in the session variables at one point, where you detected that the form was submitted, in your form processing code. you should have specific and distinct code that process the form data and specific and distinct code that builds the form.
-
you are not echo'ing the mysqli_error. change your code to this - echo mysqli_error($link);
-
since the $_POST array is apparently set, it's highly unlikely that the $_FILES array will be empty unless your form is invalid or uploads are not enabled on the server. have you successfully uploaded ANY file on this server? what does the output from a phpinfo() statement show for the file_uploads setting? does your form page have other forms on it, possibly breaking the <form> tag you did show? what is the complete 'view source' of the form page?
-
practices are only good if they make sense in the context where you are using them. blindly applying practices in all situations, can lead to bad results.
-
Inventory Management (Storing Items In Boxes)
mac_gyver replied to Monkuar's topic in PHP Coding Help
that's not an answer to - what significance is there to what box any item is located in? that's a statement of what you are doing. why not just display the items in any person's inventory, in the boxes, in alphabetical order or in the order they were acquired in, starting at the top-left box? you are having difficulty with storing the location, just think how much code it will take to allow someone to change the location and prevent overwriting a location already in use? -
How can I write CSS with PHP? - I tried and i have lost styles
mac_gyver replied to jarv's topic in PHP Coding Help
i was reading your thread on one of the other programming help forums where you started out the thread by stating that the .htaccess file breaks all your styles. that tutorial contains a comment that EVERY .css file in the folder where the .htaccess file is at must have the header() statement in it. only put your dynamically produced .css files in the folder with the .htaccess file. put regular .css files somewhere else. -
How can I write CSS with PHP? - I tried and i have lost styles
mac_gyver replied to jarv's topic in PHP Coding Help
one example would be so that each user could have his own settings. -
How can I write CSS with PHP? - I tried and i have lost styles
mac_gyver replied to jarv's topic in PHP Coding Help
not if the values are dynamic, such as custom styling stored in a database and are being retrieved using php code. -
How can I write CSS with PHP? - I tried and i have lost styles
mac_gyver replied to jarv's topic in PHP Coding Help
just telling us that something you are doing is not working, doesn't help us to help you. you haven't even posted your code that is linking/including the .css file, so we have no idea what any of your code is doing. when you browse directly to the .css file, is the output in the browser what you expect? -
based on your other recent thread about including a file containing your connection, you are apparently now calling a 'connect_db' function inside of each of your database related functions to open a connection and based on post #8 in this thread, closing that connection after you use it each time. that's most definitely NOT how to manage a database connection in your application. creating a database connection takes a significant amount of time, so of course your code is noticeably slow. the correct method is to create one database connection in your application code and pass it into each function that uses it. you would normally pass this in as a call time parameter, in the same way that the procedural mysqli_ functions accept the mysqli connection as the first call-time parameter in any function that needs it. there are other methods to pass a database connection object into functions, but they are not general purpose.
-
Inventory Management (Storing Items In Boxes)
mac_gyver replied to Monkuar's topic in PHP Coding Help
what significance is there to what box any item is located in? isn't it enough that you have an item in your inventory? -
is your query that gets the total number of matching rows that goes into producing the number of pages also using the same JOIN?
-
if you have a form with more than about 5 fields in it, you would want to dynamically produce it rather than typing-out/copy-pasting code 50 times. you would define the fields somewhere (array, database table) and use php code to produce the form by looping over the definition.
-
CSV Class? Need help updating a csv file.
mac_gyver replied to ballhogjoni's topic in PHP Coding Help
the basic logic would be - <?php $infile = 'in.csv'; // a file for testing only $csvfile = 'out.csv'; // another file for testing only $tempfile = tempnam(".", "tmp"); // produce a temporary file name, in the current directory // modify the values to match your data structure define('IN_SKU',1); // define the offset of the incoming sku column define('IN_QTY',2); // define the offset of the incoming quantity column define('OUT_SKU',1); // define the offset of the outgoing sku column define('OUT_QTY',2); // define the offset of the outgoing quantity column // read incoming sku/qty if(!$handle = fopen($infile, "r")){ die('could not open incoming file'); } $in_data = array(); $header = true; while(($data = fgetcsv($handle)) !== FALSE){ if($header){ $header = false; continue; } $in_data[$data[IN_SKU]] = $data[IN_QTY]; } fclose($handle); // process data, updating the quantity with any incoming quantity if(!$input = fopen($csvfile,'r')){ die('could not open existing csv file'); } if(!$output = fopen($tempfile,'w')){ die('could not open temporary output file'); } $header = true; while(($data = fgetcsv($input)) !== FALSE){ if(!$header && isset($in_data[$data[OUT_SKU]])){ $data[OUT_QTY] = $in_data[$data[OUT_SKU]]; // modify qty if exists in the in_data } fputcsv($output,$data); // write the line to the output $header = false; } fclose($input); fclose($output); unlink($csvfile); rename($tempfile,$csvfile); echo 'done'; -
CSV Class? Need help updating a csv file.
mac_gyver replied to ballhogjoni's topic in PHP Coding Help
here is how i would do this - 1) open and read all the "in" data into an array with sky as the index/key and the quantity is the array value. close the file as you no longer need the file handle. 2) open the existing "out" file for reading and open a temporary file for writing. 3) in a loop, use fgetcsv to read each line from the existing "out" file into an array, one line at a time. using the sku element of this array, get the quantity from the array made in step #1 and store it to the correct quantity element of the current line's array. write the array to the temporary output file made in step #2. 4) when done looping through all the lines in the existing "out" file, close all open files and if there have been no errors, delete the original "out" file and rename the temporary file to the original "out" file name. -
you can save all the data using one statement - $_SESSION['post'] = $_POST; you would reference any specific value using - $_SESSION['post']['windows']