-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
If you are going to resize an image and output it to the browser, you can only do one at a time since you must output a content-type header followed by the data for an (one) image. Why don't you want to save the resized images? If you save them, you will save on the large memory and processing resources needed.
-
mysqli_error requires the connection link as a parameter - echo mysqli_error($connect);
-
a) The query for all students (or a specific subset of students) won't take 600 times the time it takes for one student. Have you tired it without the student_id in the where condition? The query is not being executed once for each student, it is being executed once for all the rows that the query matches. b) "And here is the loop:" Are you aware that you can use aggregate functions in the query, i.e. SUM(), to get the query to return the value you want for each student (provided you use GROUP BY student_id in the query.)
-
Nooooooooo..... You would use one query that gets the rows you want in the order that you want them. You would likely need to use GROUP BY user_id to consolidate the rows for each user. If you post your actual queries and code showing what you are trying to do, someone can probably help.
-
Using partitioning and specifically partition pruning might help - http://dev.mysql.com/doc/refman/5.1/en/partitioning-pruning.html By setting up a partition for the current/active records and one (or more) for the inactive records and using a WHERE clause which would specifically identify that a query would find data only in the partition for the current/active records, your query will only search that partition. However, the entire set of records will still be available in the table.
-
ORDER BY make, model
-
I would recommend that you prototype and test some separate code and data using the suggested method so that you can see how it functions. Data driven designs should end up with general purpose code that will operate on 0, 1, 10, 100, 1000+ pieces of data without changing or touching the code as the amount of data changes. Your variable names should indicate the purpose of the value in the variable (i.e. a compound name, a maximum value, ...) for the current record of data being operated on. You then loop over each record to produce the form and to process the form data.
-
^^^ Does your form have a field named 'searching', with a value of 'yes'? Is your form method set to post? Have you set the error_reporting and display_errors settings to the suggested values (and confirmed that they actually changed to those values after you restarted your web server)?
-
You need to pick a different name for the instance of your class. You are already using $image as the name of the image in $image = $row[2]; When you use $image = new SimpleImage();, you are overwriting the image name, but you are still trying to use $image as though it is the image name. The error occurs because $image now contain an instance of your class.
-
Your database table should be setup like the following (i.e. one row per compound) - id name max LOT_max maxdoz Doz_max min LOT_min mindoz Doz_min 1 P27 n n n n n n n n 2 P28 n n n n n n n n Your totals should be calculated as needed, not stored in the database. Your form should be using array names for the form fields (see this link - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays ), then you can simply use php array functions to access that data inside of a loop without creating a huge number of sequentially named variables or hard coding (copy/paste/over-type) repeated sections of code that only differ in the values/variable names they operate on. See the following link for an example of using array names in the form and how using a php loop can greatly reduce the number of lines of code - http://www.phpfreaks.com/forums/index.php?topic=355179.msg1678517#msg1678517
-
You also have the end of an else {} statement, with some mysql error reporting logic in it, tacked onto the end of that loop construct. I suspect you intended to test if the value that mysql_query returned was a result resource or not.
-
What does a 'view source' in your browser of the blank page show? Edit: You actually have a fatal parse error on line 47, because there is no such thing as a where loop. You meant to use a while loop. You should have php's error_reporting set to E_ALL (or even better a -1) and display_errors set to ON in your master php.ini on your development system so that all the php detected errors will be reported and displayed. You will save a TON of time.
-
Also, you should have php's error_reporting set to E_ALL (or even better a -1) and display_errors set to ON in your master php.ini on your development system so that all the php detected errors will be reported and displayed.
-
You can rewrite that particular part of your <form ...> ... </form> as - <?php $num_regions = 5; // number of repeat regions in the form ?> <form name='order_details' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return validateForm()"> <table border=0 width=800 style='table-layout:fixed'> <col width=10> <col width=65> <col width=50> <col width=45> <col width=35> <col width=20> <col width=20> <col width=30> <col width=30> <col width=30> <col width=35> <tr> <th valign="top"><p class="small"><label>S.No</label></p></th> <th valign="top"><p class="small"><label>Manufacturer</label></p></th> <th valign="top"><p class="small"><label>Brand</label></p></th> <th valign="top"><p class="small"><label>Type</label></p></th> <th valign="top"><p class="small"><label>Exp.Date</label></p></th> <th valign="top"><p class="small"><label>Qty</label></p></th> <th valign="top"><p class="small"><label>Unit</label></p></th> <th valign="top"><p class="small"><label>U.Price</label></p></th> <th valign="top"><p class="small"><label>Package</label></p></th> <th valign="top"><p class="small"><label>P.Price</label></p></th> <th valign="top"><p class="small"><label>S.Price/Unit</label></p></th> </tr> <?php for($x=1;$x <= $num_regions;$x++){ echo <<<EOT <tr> <td valign="top"><p class="small"><label> $x </label></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_manufacturer[$x]" maxlength="40" size=20></input></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_brand[$x]" maxlength="40" size=14></p></td> <td valign="top"><p class="small"><select name="o_type[$x]"> <option>None</option> <option>Capsule</option> <option>Drops</option> <option>Gel</option> <option>Infusion</option> <option>Injection</option> <option>Kit</option> <option>Mouth Wash</option> <option>Ointment</option> <option>Powder</option> <option>Tablet</option> <option>Suspension</option> <option>Syrup</option> <option>Others</option> </select></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_exp_date[$x]" maxlength="10" size=10></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_qty[$x]" maxlength="6" size=4></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_unit[$x]" maxlength="10" size=4></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_unit_price[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_package[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_package_price[$x]" maxlength="10" size=8></p></td> <td valign="top"><p class="small"><INPUT type="text" name="o_selling_price_perUnit[$x]" maxlength="10" size=10></p></td> </tr> EOT; } ?> <tr> <center> <td colspan=5><center><input type="submit" name="confirm_order" value=" Confirm Order " class='myButton'></input></center></td> <td colspan=5><center><input type="reset" name="cancel_order" value=" Cancel Order " class='myButton'></input></center></td> </center> </tr> </table> </form> When the form is submitted, the data will look like - Array ( [o_manufacturer] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_brand] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_type] => Array ( [1] => None [2] => None [3] => None [4] => None [5] => None ) [o_exp_date] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_qty] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_unit] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_unit_price] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_package] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_package_price] => Array ( [1] => [2] => [3] => [4] => [5] => ) [o_selling_price_perUnit] => Array ( [1] => [2] => [3] => [4] => [5] => ) [confirm_order] => Confirm Order ) You can then simply loop over one of the sub-arrays (i.e. $_POST['o_manufacturer']), getting the key and the value, then use that key to access the corresponding values from the other sub-arrays.
-
You need to use arrays for your form field names - http://us2.php.net/manual/en/faq.html.php#faq.html.arrays You would also want to dynamically produce the repeating regions of the form using php code so that you keep it simple so that making any changes to the number of repeating regions or to the actual html would be done in only one place, not four different places. Then, you can simply use php array functions in your form processing code. Edit: I also notice that you have put the php form processing logic in the same file with the form, but you have not logic to distuniguish if the form was submitted before using the data from the form. If your form processing code is actually in the same file with the form, you would need to add logic so that the form procesing code is only execuited after the form has been submitted (otherwise you will be inserting empty values into your database table.) Also, your javascript validation appears (I didn't read it completely) to only validate the first set of data and you always need to validate all external data on the server after it has been submitted.
-
Problem submitting value from dynamic option
PFMaBiSmAd replied to Orasion's topic in PHP Coding Help
type="text" form fields are set, even if they are empty. if(isset($_POST['categoryOther'])){ will always be true any time the form has been submitted. Perhaps you want to test if $_POST['categoryOther'] is empty or if it is equal to an empty string? -
You are likely getting a fatal runtime error (undefined sqlsrv_connect function call.) PLEASE check and show us what the phpinfo() output shows for the error_reporting and display_errors settings. By making the first <? opening tag a short one, your connection logic is not seen as being php code (if you do a 'view source' of the partially working page, you should see the short opening tag, the two lines of raw php code, and the first closing ?> tag. When you use a full <?php tag, those two lines of code are being executed and execution probably halts at that point, which is why you need to have and confirm (through testing if needed) that php's error_reporting is set to E_ALL and display_errors is set to ON. Another thought just occurred. You likely have output_buffering turned ON in your master php.ini and your header() redirects on the page are discarding any php output error messages. If output_buffering is turned on, you should turn it OFF ASAP (stop and restart your server to get any changes made to your master php.ini to take effect and confirm that the setting actually changed by using a phpinfo() statement.)
-
The first array_diff() returns an array with 1 in it. The second array_diff() returns an array with 0,6,and 10 in it. The array_merge produces an array with 1,0,6, and 10 in it, having a count of 4.
-
I just looked at the code on your page closer and you have a number of statements like this <?php= You did have some <?= short tags/print statements in your (working) code and you blindly did a search and replace to change <? into <?php didn't you? Now you either need to go back to your working original source code or you need to go though all your current code and change the <?php= to <?php echo
-
Ummm. That code still has several @ error suppressors in front of php statements. Until you remove all of the @'s in the php code, you won't get accurate reporting of errors that would help you determine what is happening. In the phpinfo() output, what values are shown for the error_reporting and display_errors settings? Don't ever use @'s in your php code to suppress errors, they are not need. On a development system (or when debugging your code), you would have php's display_errors set to ON. On a live site, you would have php's display_errors set to OFF and log_errors set to ON. Going back to some previous information in this thread. Did you or did you not do a 'view source' of a blank page in your browser and see the raw php code? Also, a question I asked that wasn't really answered - are all these php files (the one with posted code, the ones that work, the one with the phpinfo() statement in it) in the same folder or are they in different paths/folders (i.e. do php files at one path, say the document root, work and php files in a folder don't work and show the raw php code in the 'view source' of the page in your browser)? Are you accessing this 'new' web server locally (i.e. where is it located vs where your client computer is located)?
-
Is this code (that you see the raw php code in the 'view source' in your browser) in the same folder where you have tried php code that does work?
-
You are probably using short open tags <? in some of your files. You should ONLY use full opening <?php tags so that your php code will always be seen as being php code, regardless of which server it is being run on.
-
You are making this far far too hard with too much hard-coded logic. If you are just trying to find if there is an avatar file or not and to get the file name if there is, all you would need to do is use the following - <?php $filename = '../../../users/user_avatars/' . $_SESSION['the_user']; $files = glob($filename.".*"); // get an array of all matching path/filename.* files if(empty($files)){ echo 'No avatar file found for the user.'; } else { // the $files array contains the path and filename.ext for the matching file(s) } If your code is not working, you likely have a variable scope problem or your logic is clearing the values and you would need to post your exact code that reproduces the problem to get help with it. FYI - under Windows, php converts / path separator characters into \ before making the low-level calls to the operating system functions. You can use / as path separator characters in all php code regardless of the operating system it is running under.