Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. Could you not just name the fields as arrays? There there is no need to change the name for additional field added.
  2. Well, I think you really want to be using onfocus/onblur, but I went ahead and wrote this using onmouseover and onmouseout since that is what you stated: <html> <head> <script type="text/javascript"> function highlightLabel(fieldObj, labelColor) { var labelObj = document.getElementById(fieldObj.id+'_label'); labelObj.style.color = labelColor; } </script> </head> <body> <label for="username" id="username_label">Username:</label> <input type="text" id="username" name="username" onmouseover="highlightLabel(this, '#ff0000');" onmouseout="highlightLabel(this, '#000000');" /> <br /> <label for="password" id="password_label">Password:</label> <input type="password" id="password" name="password" onmouseover="highlightLabel(this, '#ff0000');" onmouseout="highlightLabel(this, '#000000');" /> <br /> </body> </html>
  3. You need to generate unique links for each day by adding a variable to the url. I'd suggest using a tmestamp. Example: <a href="schedule.php?date=56438547">5</a> Then on the page schedule.php you can reference the value using $_GET['date']
  4. The problem is that on this line $arr[$i]=$row[2]; You are defining the value of $arr[$i] as a string. But,then on this line $arr[$i][$j]=$row[3]; you are trying to define an array value for $arr[$i]. You can't have $arr[$i] be a string and an array.
  5. That question is not what you meant to ask. Well, a 2kb file will take longer than a 1kb file, but you won't notice the difference. As to when you will notice a difference and, more importantly, when will that performance degredation be to a level that is unacceptable by you is impossible for anyone to determine via a forum. How bug the file will be before you start to have performance issues will depend on several factors: the efficiency of the code to extract the line, where the line of code is in the file, the specifications of the server(s) that the site is running on (CPU, memory, hard-drive speed/capacity), etc. Plus, if you are on a shared host, it will be even more difficult to determine the limits as you won't know what activity is going on for the other sites. The only way to detemine the limits is to run load/performance tests. Ideally, you would want exclusive access to the server. You would then run an application to simulate x number of users on the site performing various activities, where x is the max number of concurrent users you feel you need to support. Then you would increase the allowable size of the file at specific intervals and take recordings until performance degraded to a level that is unacceptable.
  6. The specific problem is variable scope. A variable defined inside a function only has that value inside the function. There are ways around this with globals, but that is typically a bab solution. In this situation you are returning true or false. Just change that logic to return false or the $type value. Although I see problems with that function aside from that. At the beginning of the validation function you test to ensure the length is exactly 10 characters. I would first ask why you would use to tests to check for less than or greater than instead of just a single check to see if it is not 10, but there are two other problems with that logic. 1) The value needs to match one of the values in the arrays, but none of the values to match or 10 characters, so I would presume those tests will always fail. Plus, why do a length check at all since you are testing too see if the valuse match a defines list of values? Use this for the validation (notice change in function name) function getExactType($exact) { $colors = array( '.30' => array('red','orange','yellow'), '.50' => array('pink','purple'), '.60' => array('blue','grey','white') ); //Check against each array foreach ($colors as $type => $typeColors) { if (in_array($exact, $typeColors)) { //There was a match, return the type return $type; } } //There were no matches return false; } Also, I see a logic problem with this IF statement $_SESSION['exact'] = $_POST['exact']; if( isset($_POST['exact']) && (!validateExact($_POST['exact']))) { echo ('<tr><td><td>The Colour is Invalid</td></tr><tr><tr><td>Colour<input id="exact" class="exact" name="exact" size="10"/><input type="submit" name="send" value="ApplyExact" /></td></tr>'); } else { echo ('<tr><td>Your Colour is '.$_SESSION['exact'].' and is valued at '.$type.'</td></tr>'); } You first set a session value based on the POST value THEN you check if the POST value is set. Plus, you are assuming if the IF conditin fails that validation passed. But, if the POST value isn't set that IF statement fails, but the code assumes validation passed. I would correct that like this: if(isset($_POST['exact'])) { $color = $_POST['exact']; $_SESSION['exact'] = $color $type = getExactType($color); if($type===false) { echo ('<tr><td><td>The Colour is Invalid</td></tr><tr><tr><td>Colour<input id="exact" class="exact" name="exact" size="10"/><input type="submit" name="send" value="ApplyExact" /></td></tr>'); } else { echo "<tr><td>Your Colour is {$color} and is valued at {$type}</td></tr>\n"; } }
  7. This makes no sense to me: $orders[] = ( "$status||$id||$shop||$name||$orderdate" ); I thought you were dealing with a multi-dimensional array. Instead you are taking the values and creating a sting with all the values concatenated. You should create a multidimensional array to keep the data organized and you can easily sort using usort(). usort() is a better option for sorting multidimensional arrays. array_multisort() would require you to create/maintaine separate arrays for each sort field (see Example #3 in the manual). With usort() you just need to create a small function to sort a multidimensional array. Try this: <?php $orders = array(); // init foreach($database_array as $x){ $db = "F:\location\\$x.mdb"; $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.'); $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$db"); $sql = "SELECT * FROM MyTable ORDER By Status asc, ID desc"; $rs = $conn->Execute($sql); while(!$rs->Eof){ //Create a multi-dimensional array $orders[] = ( 'status' => $status, 'id' => $id, 'shop' => $shop, 'name' => $name, 'orderdate' =>$orderdate ); $rs->MoveNext(); } $rs->Close(); } //Create custom function for sorting array function mySort($a, $b) { //Sort by status, ascending if($a['status']!=$b['status']) { return ($a['status']<$b['status']) ? 1 : -1; } //Sort by ID descending return ($a['status']>$b['status']) ? 1 : -1; } //Sort array using usort() and the custom function usort($orders, 'mySort'); print_r($orders); ?>
  8. I'm with roopurt18 on this. Let's see how you are getting the data. However, if there is no way to sort the databefore putting it into an array, then usort() will be a better solution than array_multisort(). array_multisort() will require you to reformat the multidimensional array into many arrays before running it. With usort, you can create a small function to resort the multidimensional array however you want. If you were to provide the structure of your array I could provide some sample code. Use print_r() as already suggested above. Your examples do not show structure: are the values numerically indexed or what?
  9. Interesting, would that work for a multidimensional array? How is array_replace() going to help you? That function is meant to "replace" values in one array with the values from another array. You have a single array that you want to output into an HTML table. All you need to do is perform a foreach() on the array and output the results accordingly. If you want to reorder a multi-dimensional array then use usort() as I stated. If you want more specific help then do a print_r() on your array and copy the results to a txt file and attach to this thread. Then provide what columns you want displayed and how they should be sorted.
  10. You cannot determine the ID of a checkbox in the POST data - only the Values. What are the values of the checkboxes? It would be very helpful if you showed the form that creates the checkboxes on the form. As I stated previously, you should be calculating the cost more explicitly instead of just counting the checkboxes.
  11. I originally wrote it that way, but then decided against it. The way I coded it the page which contains the "management" functions is completely self contained. This way, on any pages that need to read/write the profile data, the developer does not have to reference back to the variable created on the page with the management functions. Ideally, this would be a class. I try to avoid gloabl variables whenever possible, but I feel they do have their place.
  12. Yeah, that could be done, but it wouldn't be as simple as adding a browse button. You have different options on handling the images. The solutions require differing capabilities of the user. The simplest solution would be for the user to manually upload pre-sized images to the server and to manually enter the path in the edit page. Next easiest would be to incorporate upload functionality on the edit page. BUt, the user would need to be responsible for uploading pre-sized images or at least images with a consistent scale so you can appropriately display them programatically. The third option would be to include scripting that will automatically scale/crop the uploaded images. I have no idea what the ROI is for this project - which would determine how much time and effort should be invested. Again, none of this is exceptionally difficult. Just do one thing at a time and add individualt features as you complete others.
  13. Sounds reasonable. Although I would not store the actual database name (or the user's password) in the session data. Instead, I would save an identifier for the correct database for the user. Then on each page load do a lookup in the master database for the correct user database to use. Then switch to that database to get all the specific page data.
  14. Like I said, do a Google search for "date format". Google is the all knowing entity.
  15. Did you test out those "formats"? The last two aren't formats that I have ever seen used. You would get something like: 16Feb/Tue/2010 or February-Tue16-2010 I *think* your instructor is wanting you to find eight formats that would be legitimately used. Think about how dates are used by people (in different countries) and by machines. Or, be lazy, and do a simple google seach for "date format".
  16. Here's a quick and dirty solution. <?php $data = array ('s', 't', 'r', '1', '2', '3'); foreach($data as $char1) { foreach($data as $char2) { if ($char2 != $char1) { foreach($data as $char3) { if ($char3!=$char1 && $char3!=$char2) { echo "{$char1}{$char2}{$char3}<br />\n"; } } } } } ?>
  17. It looks to me that "most" of the checkboxes represent items that each cost £200. That would explain why you are counting up all the checked items and multiplying by 200. Are you even using the value of the checkboxes? If no, then use the value for the prices of the checkboxes and then sum up all the values to get the total price. If you are using the values of the checkboxes for some other purpose, then I have to assume you have a way of knowing what the cost of each item is that you can tie back to the actual value (e.g. title?). You would want to determine the price individually by looking up each checked value.
  18. Yeah, you could use XML, but I'd just use a CSV file. I was bored on a conference call, so I wrote some rough code. manageProfiles.php <?php $dataFile = "profiles.txt"; function getProfiles() { global $dataFile; $profiles = array(); if(file_exists($dataFile)) { $dataArray = file($dataFile); foreach($dataArray as $key=>$profileRecord) { $profiles[$key] = explode("\t", $profileRecord); } } return $profiles; } function saveProfiles($profilesArray) { global $dataFile; $fh = fopen($dataFile, 'w') or die("can't open file"); foreach($profilesArray as $profile) { $textRecord = implode("\t", $profile) . "\n"; fwrite($fh, $textRecord); } fclose($fh); return; } ?> pageEdit.php <?php include("manageProfiles.php"); function createFieldSet($profileData=false) { if(!$profileData) { $name = ""; $title = ""; $desc = ""; $image = ""; } else { list($name, $title, $desc, $image) = $profileData; } $fieldSet = "Name: <input type=\"text\" name=\"name[]\" value=\"{$name}\" /><br />\n"; $fieldSet .= "Title: <input type=\"text\" name=\"title[]\" value=\"{$title}\" /><br />\n"; $fieldSet .= "Description: <textarea name=\"desc[]\">{$desc}</textarea><br />\n"; $fieldSet .= "Image: <input type=\"text\" name=\"image[]\" value=\"{$image}\" /><br /><br />\n"; return $fieldSet; } //Data was posted, save changes if (isset($_POST['name']) && is_array($_POST['name'])) { $profileCount = count($_POST['name']); //Parse the data $profileData = array(); for($idx=0; $idx<$profileCount; $idx++) { $name = trim($_POST['name'][$idx]); $title = trim($_POST['title'][$idx]); $desc = trim($_POST['desc'][$idx]); $image = trim($_POST['image'][$idx]); if(!empty($name) || !empty($title) || !empty($desc) || !empty($image)) { $profileData[$idx] = array($name, $title, $desc, $image); } } //Save the changes saveProfiles($profileData); } else { //Get the current data from file $profileData = getProfiles(); } //Create the form fields $formFields = ''; foreach($profileData as $profile) { $formFields .= createFieldSet($profile); } //Create empty fieldSet to add new profile $formFields .= createFieldSet(); ?> <html> <head></head> <body> <form action="" method="POST"> <?php echo $formFields; ?> <button type="submit">Submit Changes</button> </form> </body> </html> pageDisplay.php <?php include("manageProfiles.php"); $profileData = getProfiles(); function displayProfile($profileAry) { list($name, $title, $desc, $image) = $profileAry; $htmlOutput = "<div><img src=\"{$name}\">\n"; $htmlOutput .= "<span><b>{$name}</b> {$title}<br /><br />\n"; $htmlOutput .= "{$desc}<br />\n"; $htmlOutput .= "</div><br /><br />\n"; return $htmlOutput; } ?> <html> <head> <style> </style> </head> <body> <?php $profileData = getProfiles(); foreach($profileData as $profile) { echo displayProfile($profile); } ?> </body> </html>
  19. What? It doesn't need a custom framework. The OP only wants to allow one page to be edited. @liamloveslearning: Making a page, such as the one you linked to, editable is fairly simple as long as the format will always be consistent. In this case I would assume only the profiles for each person would be editable. Each profile consists of four pieces of information: Name, Title, Description, and image. As long as the output of each of those four peces of information will be consistent (i.e. name is always bold, no ability to italicize/bold individual words in the decription) it is fairly straitforward. Personally, for a project such as this, I would use a flat file to store the data and build PHP scripts to edit the file. For the edting, I would create a form page with input fields for all the current profiles and an empty set of fields at the bottom to add a new profile. When the page is saved, the form is displayed again with all the profiles (including the new one) and again, another empty set of fields to add a new profile. I suppose you could also create a function to move profiles up/down on the page. But I doubt that that function would be used much - if at all. Without knowing your level of expertise in HTML/PHP I'm not sure how much of an undertaking this would be for you. For someone proficient, I think this could be done in a couple of hours.
  20. $string = "first,second third , fourth"; echo preg_replace('/[ |,]+/', ',', ucwords(preg_replace('/,/', ' ', $string))); //Output: First,Second,Third,Fourth
  21. It all depends on how "extensive" the editing features need to be for this page. Does he need to be able to edit font and graphics? If the layout is such that there is only a block of text for each person it can be implemented very easily and would not even need a database. Can you provide a link to the current page?
  22. No, disable fields don't get passed because they are disabled. That's kind of the point of disabling them.
  23. You are using some custom functions to do your database activities: ret11() and gloss(). So, there is no way for us to know what the problem really is. I doubt this has anything to do with your database structure. The only thing I can *guess* from the code you have provided is that it looks like you are only querying for the "team" field, but you are trying to use results for "title" and "barracks". In fact, the variable $team in the query makes no sense. It is being concatenated to the field name "team" and you have no fields in the database with team and additional characters.
  24. $string = "first second third"; echo preg_replace('/[ ]+/', ',', ucwords($string)); //Output: First,Second,Third
  25. You can create a custom function to order the array however you want using usort(). So, let's say you want to order the array by items at the index 2 in ascending order, and if those items are equal, then do a sub-sort on the items at index 4 in descending order: function customSort($a, $b) { if ($a[2] == $b[2]) { if ($a[4] == $b[4]) { return 0; } return ($a[4] < $b[4]) ? 1 : -1; } return ($a[2] > $b[2]) ? 1 : -1; } usort($myArray, 'customSort');
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.