Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Again, it is up to you. But, I would make the tabs act as submit buttons AND I would have a SAVE button to commit all the data. So, when the user clicks a tab it submits the form for that tab and saves the data for that tab abd displays the form for the selected tab. Only when the user clicks the SAVE button woudl you do the final processing of all the data.
-
My first guess would be your WHERE clause. That's an awful lot of complex mathematics that you are asking the Database server to do just to determine if the record should be in the result set. Try removing that last condition and see if the performance improves. If so, then you know that is the cause. If that is the cause, you could try indexing the fields used in those calculations. I know that indexing improves performance for fields used in lookups and joins, but not sure if it would help when the value is used in match functions or not.
-
Your server likely has "magic quotes" enabled. Which is a bad thing. If you can you should turn that feature off in the web server. If you don't have that ability (e.g. you're on a shared server) you can remove the slashes at run time. Look at this page for more info: http://php.net/manual/en/security.magicquotes.disabling.php There is a sample script in example #2 that you can use. Just call it on any page that receives user input.
-
There are different ways to handle this, each with benefits and drawbacks. 1. You can have one form for all the data but break up the form into different sections where only one section is displayed at a time using JavaScript. So, you get your tabbed display. But, it requires JavaScript which could pose it's own problems. 2. You can build your PHP script for the form so that you pass a tab id to it. When the script runs the first time you would default to tab 1 and the script builds that "tab", when the use clicks another tab use a JavaScript event to submit the form and pass a tab id for the one the user clicked. You can take the submitted data and store it (hidden fields, session data, hidden fields, etc.). So, basically each tab element is a submit button that will store the updated data for that tab. 3. Another solution is to simply make the tabs a "wizard" of sorts. This requires no JavaScript. When the user lands on the first tab there will be a button to submit the form and go to the next tab. As above, the data is submitted and stored somewhere. It's all up to you really to determine how complicated you want to make it. One of the driving factors for me in determining the correct approach would be the validations needed. For example, if data on tab 1 will affect data on tab 2 that would likely influence my decision.
-
An auto-complete feature is a nice feature, but is that really what you "need". You need to crawl before you can walk and walk before you run. You're trying to jump to the 100 meter sprint in the Olympics. I would start with a simple paginated grid with the ability to submit search criteria. THEN add additional features to make the data more user friendly. A dynamic lookup can be very problematic if not done correctly.
-
First, what is this? if ($_SESSION['userName']) {} else { header('location:../index.php'); } Just use this: if (!isset($_SESSION['userName'])) { header('location:../index.php'); } Second, don't use PHP short tags. As to your problem. The only thing that sticks out at me is this if($_POST["pizza$pizza"] == $row['id']) There is a condition to check if the record from that table match a POST value. I would *assume* there would only be one record from that table with that matching id? But, I see you do have a subsequent query to get the same data using the id from the first query. That makes no sense. If you only need the data for particular IDs, then put that in the WHERE clause of the query instead of doing that logic in the PHP code. I'm assuming that these are checkboxes. If so, you should do this differently to make it easier. I would also suggest putting all your PHP logic at the top of the page - easier to maintain. So, in your form, change the fields from what I think is something like this <input type="checkbox" name="pizza12" value="1" /> where 12 is the id of the item being selected Change to this <input type="checkbox" name="pizzas[]" value="12" /> You will now have $_POST['pizzas'] returned as an array with the values of all the selected items Then, I would change your current code to this <?php session_start(); if(!isset($_SESSION['userName'])) { header('location:../index.php'); } //Get the array of selected pizzas (force to be intvals and remove empty values) $selectedPizzasAry = array_map('intval', $_POST['pizzas']); //Remove empty values $selectedPizzasAry = array_filter($selectedPizzasAry); $output = ''; //Var to hold the output //Check that there were valid values if(!count($selectedPizzas)) { $output .= "<tr><td colspan='6'>No pizzas were selected.</td></tr>\n"; } else { mysql_connect("localhost", "root", "")or die("cannot connect"); mysql_select_db("deliverpizza")or die("cannot select DB"); //Create and run query to get selected records $selectedPizzasStr = implode(', ', $selectedPizzasAry); $query = "SELECT `id`, `type`, `size`, `topping`, `cost`, `info` FROM `pizzatopping` WHERE id IN ({$selectedPizzasStr})"; $result = mysql_query($query); //Process the results if(!$result) { $output = "<tr><td colspan='6'>There was a problem getting the records.</td></tr>\n"; //This line for debugging only $output .= "<br>Query:<br>{$query}<br>Error:<br>" . mysql_error(); } elseif(!mysql_num_rows$result()) { $output .= "<tr><td colspan='6'>There was no matching records.</td></tr>\n"; } else { while($row = mysql_fetch_assoc($result)) { $output .= "<tr>\n"; $output .= " <td>{$row['id']}</td>\n"; $output .= " <td>{$row['type']}</td>\n"; $output .= " <td>{$row['size'}</td>\n"; $output .= " <td>{$row['topping']}</td>\n"; $output .= " <td>{$row['cost']}</td>\n"; $output .= " <td>{$row['info']}</td>\n"; $output .= "</tr>\n"; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Deliver-Pizza Order</title> <link href="css/order.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="header"> <img src="images/logo.jpg" alt="logo" /> <a href="log-off.php" id="logg-off" >log off</a> <ul id="nav"> <li><a href="home.php" target="_self">Home</a></li> <span> | </span> <li><a href="Pizza-Topping.php" target="_self">Pizza Topping</a></li> <span> | </span> <li><a href="order.php" target="_self">Order</a></li> <span> | </span> <li><a href="Account.php" target="_self">Account Details</a></li> <span> | </span> </ul> </div> <div id="Featured"><img src="images/banner1.jpg" alt="banner" name="banner"" ID="banner"></div><!--end Featured--> <div class="featuredimage" id="main"> <div id="content" class="tiles"> <h1>Order</h1><hr /> <div id ='staff'> <div style="width:920px; height:autopx; overflow:auto; heightmax:300px"> <table> <tr> <th>pizza number</th> <th>Type</th> <th>Size</th> <th>Topping</th> <th>Cost</th> <th>Information</th> </tr> <?php echo $output; ?> </table> </div> </div> </div> </div> <!--end content--> <div id="footer"><span><p>Created By Ryan Williams</p></span></div><!--end footer--> </div><!--end container--> </body> </html>
-
@onlyican, I think you are implying that the question was about pulling ALL the data down to the client and then using JavaScript to do the pagination. There would be no reason to use AJAX for that since the data could be loaded on first page load. But, yes, if the OP is talking about using pure JavaScript to do the pagination, I agree with you that it would be a foolhardy solution. @op, I assume you were talking abut using AJAX to fetch one page of data at a time as the user selected an option to change the page. There is no intrinsic benefit to doing that. In fact, AJAX just adds another layer of complexity. That's not to say it doesn't have value but, IMO, it is best to first get a process working without AJAX. Once you have it working, then you can add AJAX or other bells and whistles as needed. And, off the top of my head here are some things you may or may want to consider by using AJAX. Cross-browser issues. There are some good JS frameworks that would decrease these problems, but with mobile devices and new browsers it will likely never go away. So, with AJAX you run the risk of some users having problems. As stated above, more complexity. As with a machine, the more moving parts you have the harder it is to maintain and the more likely something will break. A reason TO use AJAX is seamless page transitions. The user doesn't have to refresh the entire web page to see the next 'page' of data. If your process of getting the data takes several seconds this could be useful because no one wants to be looking at a white browser window waiting for a page to load. But, if it's taking a bit to load the page, that's usually a sign that the code is inefficient.
-
Glad you got it worked out. For future reference, I thought I'd let you know that I decided not to respond further because the information you were providing was lacking in clarity. You posted an over-elaborate complete class without only a hint of what the expected outcome should be and didn't provide any information as to what the input would be. In the future you will get better responses if you can narrow down the problem area of code, explain what values are going in, what is being produced currently, and how you want that to be different.
-
I'm glad you got it solved, but that is a lot of unnecessary code. There may have been some minor errors in what I provided, but I would have been willing to help you work it out. On second look, that can't be working correctly. Well, it may be "working" but it would be doing so by accident. Take a look at these three lines where you define three values based upon the DB result $currentSRNum = (int)(substr($row['sr_num'],0,3)); $currentSRYear = (int)(substr($row['sr_num'],2,2)); $currentSRMonth = (int)(substr($row['sr_num'],0,2)); You are defining $currentSRNum as the first three characters of the returned value and $currentSRMonth as the first two characters. That can't be right based upon your requirements above. But, oh well. You app.
-
So, let me paraphrase what I think I understand. You have a form for creating new "items". When that form loads you want to auto-populate the stock number field with a new number in the format "yymmddxxx". I assume that the "yymmdd" stands for year, month, day in two digit format, but you did not state/define what the "xxx" should be. is that supposed to be an auto-incrementing number? If that is correct, then you will need some way to determine the last used number for the given day. That means you will need to store the numbers somewhere - which you also did not elaborate on. So, for the sake of argument I will assume that the xxx is an auto-incrementing number that starts over each day and that the numbers are stored in a database. Off the top of my head, here are the steps I would take when the page loads. 1. Create the datestamp portion for the stock number 2. Get the last used value for the current date from the DB, if it exists 3a. If there is no existing value for the current day create the stock number using 001 3b. If there is an existing value for the current day create the stock number with 1 value higher 4. Populate the field Mock code //Create datestamp $datestamp = date('ymd'); //Query DB for today's highest record $query = "SELECT stockno FROM tablename WHERE stockno LIKE '{$datestamp}%' ORDER BY stockno DESC LIMIT 1"; $result = mysql_query($query) or die (mysqlerror()); if(!mysql_num_rows($result) { $no = 1; } else { $last = mysql_result($result, 0); $no = intval(substr($last, -3)); $no++; } //Create new stock number $newStockNo = $datestamp . str_pad($no, 3, '0', STR_PAD_LEFT); //populate input field echo "Stock Number <input type='text' name='stock_no' value='{$newStockNo}' />";
-
Well, first off the title is about running PHP on IIS and then in your first post you are talking about remote desktop-ing into a machine. I'm not sure what one has to do with the other. I'm really not sure what you mean by remoting into your office server. I know what remote desktop is, but haven't a clue what it has to do with your problem (at least not with waht you have provided). Where are you running the server and where are you running the client? As for running PHP on IIS, yes you can do that and the based upon the errors you are reporting it is installed on the web server you are running on. The problem is that your code is, well, crap. It is full of deprecated and poorly implemented logic. The problems you have in the code will be "overlooked" on some servers based upon their version and settings. Some examples <?session_start();?> Don't use short tags (i.e. <? ?>), use the full PHP tags, <?php ?>. Also, you aren't even putting spaces between the opening and closing tags and the code contained in them. if(isset($_GET[view])) { $view = $_GET[view]; } Unless you have defined a constant called view you should put named indexes in quotes' if(isset($_GET['view'])) { $view = $_GET['view']; } Then in all your if*() conditions you have something like if ($view == 'home'){ But, unless $_GET['view'] was set the variable $view would never be defined, thus you are getting those errors on the if conditions. So, to fix the majority of your errors 1. Use correct PHP open/closing tags 2. Use quotes around the named indexes of the arrays 3. Always set the value of view. Just set it to some logical value if the $_GET value wasn't set $view = (isset($_GET['view'])) ? $_GET['view'] : false; There was also an error on an included page, I'll let you figure that one out.
-
Your issue IS an HTML issue, not a PHP issue. If you know what the HTML markup should be then just use the PHP code to produce that markup. It doesn't happen automagically. To output an image link in HTML <a href="page_to_load.php"><img src="path/to/image.image.jpg"></a> So, to do the same thing in PHP you can hard code the same thing or create variables for parts of the output $href_url = "page_to_load.php"; $image_src = IMAGES_HEADER . "header_02.jpg";; echo "<a href='{$href_url}'><img src='{$image_src}'></a>";
-
How to generate 15 random numbers between (1,10)?
Psycho replied to darkslayer's topic in PHP Coding Help
And SHOW the work you have provided. Explain what you are trying to achieve and how the current results are different. -
Att he end of the for loop $i actually has the value of 6 - not 5. The for() loop condition is to continue as long as $i<6. So when it equals five the for loop will run, then $i is incremented to 6 and the for loop will exit. Therefore, when the while loop starts it first increments $i (to 7). So the first output from the while loop would be "the while loop number 7" If you want to start the while loop output at 6, then increment $i after you do the output.
-
We have no way to determine if the output is right or wrong. We don't know what fields you expect to be included or which ones were actually included. The function is of no value to us without understanding the logic of your DB structure and what the inputs are. For now, you need to focus on the Query that is created - not the results of the query. Just work on ONE part of the process. Once that works, move on to another process. As I showed above, you could work on the fields that are included in the SELECT portion of the query based upon the user selections. That's where I would start. So, just work on processing the user input to get the SELECT portion. Then verify the results by echoing the query. You could test the generated query just to verify the fields are created correctly, but I wouldn't focus on the output.
-
Again, how do you store a 1/2 value with an INT? Makes no sense unless you are doing some "hack" such as "15" really means 1.5, "20" means 2.0, etc. That's a really poor solution. You don't have to worry about accuracy issues if you use a decimal type with a fixed precision of n.1. The n stands for the TOTAL number of digits you want to allow (before and after the decimal), and the 1 stands for the number of digits to allow after the decimal. Do it right and you will avoid many potential problems.
-
Huh? explode() won't do anything to an array - it is used to create arrays. Why don't you show exactly how you are getting the data and how you are using it and what your desired result is? EDIT: In fact, since you are defining those values a numbers and not strings they will automatically have the leading zeros stripped when they are initially assigned. So, your request makes even less sense. Although I just found that 08 and 09 are converted to 0 for some odd reason $a = array(01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11); echo $a[0]; //Output: 1 echo implode(', ', $a); //Output 1, 2, 3, 4, 5, 6, 7, 0, 0, 10, 11
-
No, you cannot. FWIW, you can create stored procedures within the database that are kind of like functions, but that is not what you want here. For example, if you let the user define the fields to be used in the query you would probably give them a list a select fields. So, let's assume the fields are named as an array <select name="field_list[]"> Then to build the SELECT portion of your query you would loop through those input values and create the list. (Note: the following is just a very basic example and does not encompass all validations/sanitizations that should be conducted) //Get list of submitted fields for the select statement //Remove empty values $field_list = array_filter($_POST['field_list']; //Put each field name in single quotes foreach($field_list as &$field_name) { $field_name = "'{$field_name}'"; } //Implode the field list into a string to be used in the query $select_str = implode(', ', $field_list); //Use the dynamically created list of fields in the query $query = "SELECT {$select_str} FROM table_name WHERE 1 = 1"; Now, that is just a basic example regarding the creation of the fields for the select part of the query. You would need to build similar logic for any other parts of the query that will be user defined (e.g. the WHERE clause, ORDER BY, etc.) What you need to do is to dynamically create the query using PHP code. I'm not going to try and deconstruct your code to try and understand it, but here is an example.
-
Well, what is the content of $wtf and where is $thecount defined? in any event you should be using a foreach() loop on the array and not a for() loop. You can easily find what IS happening by adding some code to show debugging messages. Try this $number = 3; foreach($wtf as $word) { $wordCount = strlen($word); echo "Word {$word}, Count: {$wordCount}, " if($number == $wordCount) { echo "Match!<br>\n"; } else { echo "No Match!<br>\n"; } }
-
This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=356168.0
-
A quick google search found this page: http://www.movable-type.co.uk/scripts/latlong.html There are several different formulas and explanations of the logic behind the formulas as well as sample code. the code is in JavaScript, but it should give you enough information to convert to PHP. I'm not going to deconstruct your current formula and try to determine what is wrong and I think the process of finding the corresponding PHP functions for the JavaScript functions should be pretty easy.
-
That code is fine. The problem is the PHP in the file is not getting executed and is instead being returned to the browser without being processed. Are you loading the file in your browser directly? If so, you need to be "requesting" the file via a web server that has PHP installed and enabled. If that is what you are doing, does the file have an appropriate extension (i.e. 'php') that the web server has been configured to process for PHP scripts?
-
Really? I absolutely abhor the use of PHP opening/closing tags on the same line repeated ad nausea. My preferred approach to the above would be to use double-quoted strings so I don't have to enter/exit the quotes to use a variable. Plus, it has the added benefit of being able to easily add some "formatting" to the output such as linebreaks and tabs so the HTML is easily readable. Amazes me how many people output the HTML content all in one line. Absolutely a nightmare to debug an HTML problem. $a = array('1', '2', '3', '4'); if($a) { echo "<ul>\n"; foreach($a as $b) { echo "<li>{$b}</li>\n"; } echo "</ul>\n"; } Or as, Nodral stated, put the content into a variable to output within a template/output file
-
If you want your numbers to be consistently formatted then, yes, number_format() is what I would recommend. That is the whole point of that function to ensure the format of the value is precisely what you want it to be. Although, I'm still trying to wrap my head around how you have tinyint values that have .5 remainders.
-
Your data storage should NOT be used to determine the format of the data in the output. The data storage should simply be the correct type based upon the value to be stored. You previously stated that you were storing an int, but now you state that the values may or may not have 50 cents on them. So, I'm really not understanding what you really want/need. For monetary values you should be using a "numeric" or "decimal" type: http://dev.mysql.com/doc/refman/4.1/en/fixed-point-types.html But, you should then add the necessary PHP code to force the format for whatever purposes you need in the output. Again. number_format() will do this for you. $value = "1.5"; echo number_format($value, 2); //Output: 1.50