Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. I also see some other HTML poblems that will result from your code: <td style="text-align:center;"> <?php if ($linkboxscore) { ?> <a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=boxscore&id=$past->id");?>"><?php echo $past->finalv;?><br /><?php echo $past->finalh;?></a> <?php } else { ?> <?php echo $past->finalv;?><br /><?php echo $past->finalh;?> </td> Look what would happen if that IF statement results in TRUE - there would be no closing </TD> tag because you only put the closing tag within the ELSE statement. I' walking through the code now and will post a rewrite momentarily. But, the reason for these errors is as I alluded to previously - with all the IF/ELSE conditions and opening/closing PHP tags it is near impossible to follow the flow to spot these problems
  2. As I stated, the code is not correct for the if/else branches. The opening of that row is within the ELSE condition above. So, if the IF condition is true the date/time will be included in the previous row.
  3. You must be using DreamWeaver or some other CRAP editor. All of those opening/closing PHP tags are a complete waste and make reviewing code 10 times harder than it should be. After taking out all of that drap I think the problem is that you have a closing curly brace "}" right before you try to echo the gamedate and gametime. That brace is used to close an else condition code block - Which is just odd. That means the game date/time is supposed to be displayed no matter if that IF/ELSE condition is true or false. But, if the true condition occurs the game date/time would not be displayed in a table cell. There are just so many embedded if/else statements and all the embedded PHP/HTML code it is near impossible to follow the logic. I would highly suggest you do all the "logic" in the start of the page to define the output, then just use echos in the HTML to put the output in the proper places. Plus, you should consider using proper indenting to make the flow of the code apparent. EDIT: One last thing: Comments! Use them, they are your friend.
  4. http://www.9math.com/book/sum-first-n-natural-numbers function sumOfNaturalNumbers($maxNum) { return ($maxNum * ($maxNum + 1)) / 2; } $answer = sumOfNaturalNumbers(540);
  5. Yes, of course. You would have to elaborate on "...post the values into different rows of DB" for us to provide any worthwhile advice. But, let's say, for example, that you want a page where you can "deactivate" records. So you would generate a page with a single check box for each record next to a tile for each record or some way for the user to identify which record is which. Now, you can decide to only include currently active records or include all record and check/uncheck each record according to it's current active status. For simplicity I will assume this will only include currently active records with the options to deactivate them. I have left of some necessary code - such as connecting to the db, validation/data cleansing, etc. Page to create form <?php //Run query to get list of currently active records $query = "SELECT * FROM table WHERE active = 1"; $result = mysql_query($query); //Create HTML form code to display checkboxes for each active record $formFields = ''; while($row = mysql_fetch_assoc($result)) { $formFields .= "<input type=\"{$row['id']}\" name=\"recID[]\" />{$row['name']}<br />\n"; } ?> <html> <body> <form action="deactivate.php"> Select the records to deactivate:<br /> <?php echo $formFields; ?> <button type="submit">Deactive Selected</button< </form> </body> </html> Page to process the form //Create id list from submitted values for query $idList = implode(', ', $_POST['ids']); //Create and run query to update records $query = "UPDATE table SET active = 0 WHERE id IN ({$idList})"; $result = mysql_query($query);
  6. OK, so the question isn't It is how you would apply the rates. There is still a lot of information not available. For example, is the normal rate flat (i.e. it is the same for every day) or does it vary (e.g. weekends are normally more). Also, can there by more than one "special date block"? All of that will determine how this should be coded. I will assume that if there are multiple "special date blocks" that they do not overlap. Here is a sample script that works (AGAIN: If there are "special date blocks" that overlap, they will all be applied. But since I did not provide any logic on how multiple rate differentials should be applied if there is an overlap, the results might not be what you intend.) This was also done against my test database - so you may need to make some modifications for this to work for you. This only returns the total rate for the reservation period. If you need a breakout, you can modify the function accordingly. function getRate($startDate, $endDate, $normalRate) { //Modify dates to timestamps $startDateTS = strtotime($startDate); $endDateTS = strtotime($endDate); //Get total days for reservation period $totalDays = intval(($endDateTS - $startDateTS) / 86400) + 1; //Get rate for total days at normal rate $rateTotal = $totalDays * $normalRate; //Run query to get number of days to apply for each //special date block rates within reservation period $query = "SELECT rate DATEDIFF(LEAST(rate_end_date, FROM_UNIXTIME({$endDateTS})), GREATEST(rate_start_date, FROM_UNIXTIME({$startDateTS}))) as rate_days FROM `date_blocks` WHERE rate_end_date >= FROM_UNIXTIME({$startDateTS}) AND rate_start_date <= FROM_UNIXTIME({$endDateTS})"; $result = mysql_query($query); //Adjust rate total for number of days in each date block while($rateBlock = mysql_fetch_assoc($result)) { $rateTotal = $rateTotal + ($normalRate * $rateBlock['rate_days'] * $rateBlock['rate']); } //Return the total cost for the reservation period return $rateTotal; } //Reservation dates $start_date = '01/12/2011'; $end_date = '07/12/2011'; //Get rate total $rateTotal = getRate($start_date, $end_date, 20);
  7. You say you have four text boxes and four checkboxes. Do the checkboxes correspond to the textboxes? If so, why do you need the checkboxes? Just use the fact that a value has been entered into a search field. Anyway, the solution to your problem is fairly simple. Use the input to "build up" the query. Then run the query after you have checked all the user input. Example: $whereClauses = array(); if(isset($_POST['checkbox1'])) { $whereClauses[] = "field1 LIKE '%{$_POST['textbox1']}%'"; } if(isset($_POST['checkbox2'])) { $whereClauses[] = "field2 LIKE '%{$_POST['textbox2']}%'"; } if(isset($_POST['checkbox3'])) { $whereClauses[] = "field3 LIKE '%{$_POST['textbox3']}%'"; } if(isset($_POST['checkbox4'])) { $whereClauses[] = "field4 LIKE '%{$_POST['textbox4']}%'"; } $searchQuery = "SELECT * FROM tableName WHERE " . implode(' AND ', $whereClauses);
  8. See my sig - I'm not always going to take the time to test the code I provide. In some instances it would require me to set up a database and other data that would be prohibitive.
  9. Didn't you already do that here? 03/12/2011-06/12/2011 prices +15% If you are asking how you would implement that in your application, there is no way for us to give you an answer as we don't have a clue of how your application is currently configured. If you are using a database, then you could simply have a table to define date ranges with up/down charges. I would use (at a minimum) three fields: start_date, end_date, rate_change. How you would use that in calculations would again depend on how your application is currently built.
  10. I cannot make sense out of your request above. This is not a "chat" room, please use punctuation. From what I *think* I understand you simply don't want the ELSE condition to run if there is no image. Then just remove the else condition. Also, your script is very inefficient due to the queries being run in a loop. You should create one query to insert all the records and run it at the end. Example if (isset($data['product_image'])) { $insertValues = array(); foreach ($data['product_image'] as $image) { $image = str_replace (' ', '', "{$image}.jpg"); $filename = '/home/purchase/public_html/fancydresscostumesonline.co.uk/image/'. $image; if (file_exists($filename)) { $id = (int) $product_id; $img = $this->db->escape($image); $insertValues[] = "('$id', '$img')"; } } $query = "INSERT INTO " . DB_PREFIX . "product_image (product_id, image) VALUES " . implode(', ', $insertValues); $this->db->query($query); }
  11. Sure, first do not run a database query then dump the data into an array just so you can process it later. It is createing a two step process that should only be one. Just process the database results once. There is no need to put them into an array. However, the example code below does use a temp array. That is because - accordingly to your specifications - you need to style the output differently based upon whether there is one record or multiple for and event ID. The easiest way to do that is not to generate any output for a particular event ID until you have gathered all the data for that ID. What you are asking is fairly simple, here is some example code: <?php //Function to create HTML output for all records of an event function createEventHTML($eventArray) { $htmlOutput = "<tr><th style=\"background:#ccc;\">New Event</th></tr>\n"; //Determine style based on whether there is one or multiple records $style = (count($eventArray)>1) ? '' : 'border:1px solid black;'; foreach($eventArray as $event) { $htmlOutput .= "<tr><td style=\"{$style}\">{$event['event_id']}</td></tr>\n": } return $htmlOutput; } //Run query to get the data $query = "SELECT * FROM table_name ORDER BY event_id"; $result = mysql_query($query) or die(mysql_error()); //Create variables for the processing loop $eventTableOutput = ''; //String to hold html output $current_id = false; //Var to check for id change $eventAry = array(); //Temp array to event records //Process the results into html output while($row = mysql_fetch_assoc($result)) { //Check if the record has different id from last if($row['event_id']!==$current_id) { //Create html output for previous event ID records if(count($eventAry)>0)) { $eventTableOutput .= createEventHTML($eventAry); } //Set current ID and set temp array $current_id = $row['event_id']; $eventAry = array(); } //Add record to temp array $eventAry[] = $row; } //Add the last event records to the output $eventTableOutput .= createEventHTML($eventAry); ?> <table> <?php echo $eventTableOutput; ?> </table>
  12. OK, from your screenshot my understanding is that if there is only one entry for a specific ID you want that item to have a boder. However, if there are multiple entries for the same ID then there will be no border. My advice is to NOT create individual tables for the individual IDs. It only makes the HTML more complex and the PHP code for creating it harder to create/maintain. Instead use a single table for the entire content and use style properties to modify the entries of single IDs. You could also make this process much, much easier by reconfiguring your array so it is not multidimensional. But, a more important question is how is this array generated? If this is generated from a DB query - then you are going about this all wrong. Is there other data for each record that you are wanting to display or is the ID really the only thing you want displayed?
  13. You still didn't provide an explanation of what you are trying to achieve. But, I'll provide some code on what I suspect you are wanting. $previous_id = false; $output = ''; foreach($result as $row) { if ($row['event_id'] !== $previous_id) { $output .= "<tr><td style=\"background:#ccc;\">New Event</td></tr>\n"; $previous_id = $row['event_id']; } $output .= "<tr><td>{$row['event_id']}</td></tr>\n"; }
  14. You don't show how you are getting the list of values from the database or if there should be a "pre-selected" value. Here is some sample code: //Run query to get all words from database $query = "SELECT word FROM table ORDER BY word"; $result = mysql_query($query) or die(mysql_error()); //Create options $wordOptions = ''; while($row = mysql_fetch_assoc($result)) { //Preselect value if it matches 'LANGUAGE_SEARCH_RATESTITLE' $selected = ($row['word']==$output['LANGUAGE_SEARCH_RATESTITLE']) ? ' selected="selected"' : ''; $wordOptions .= "<option value=\"{$row['word']}\"{$selected}>{$row['word']}</option>\n"; } $output['RATESTITLE'] = "<select class=\"inputbox\" size=\"24px\" name=\"ratestitle\">{$wordOptions}</select>";
  15. //Look for ANY character that is not lower case alpha character $regex = "/[^a-z]/"; if (!preg_match($regex, $DepartureDate)) { //All characters are lower case alpha caracters mail($to, $subject, $message, $headers); header("Location: {$url_success}"); } exit();
  16. What do you mean it doesn't work? You need to state what you expect to happen and what is, or is not, happening. Normally I would also state you need to state what the input is that you are testing against. But, in this case, I'm pretty sure your problem is on this line echo $url_success = "confirmation.php"; What are you trying to do on this line? Do you want to echo something or do you want to set a value?
  17. Yeah, I made a change in the array structure and forgot to change that IF condition for setting the default value. As for the TinyMCE issue, I really have no clue. I don't user TinyMCE or WordPress. The line breaks should not be an issue since it will eventually be rendered in HTML the line breaks won't be interpreted (unless you are displaying the code withing PRE tags or something). The real problem would seem to be the missing tags which are there to style the content. Since they are missing in your WordPress example I would guess whatever functions/processes you are using from WordPress are removing those tags. I suspect the code in question does that to prevent CSS injection.
  18. You mean, if they go to the link with from=Justin they are presented with a page to enter a value THEN when the user submits the page the processing page does not have access to the previous "%from" value, correct? On the page steal.php where you are creating a form for the user to enter an amount, use the $from value to populate a hidden field in the form. Then the page that processes the page will have the value passed in the POST data. Thanks! But I could've swore Thorpe said their was another way. He tends to smash the information in your brain. D: Yes, there are many way to accomplish what you are asking. If Thorpe suggested something different I will assume he had a good reason for doing so. You may have provided him with slightly different information that led him to provide a solution that would be better in the context that he understood it.
  19. I can't say it is right or wrong because I haven't seen all the code. But, as I stated it is IMPOSSIBLE for a PHP script to send output tot he browser THEN to do a header redirect. It's right there in the manual for the header() function. Not to mention we see many posts on these forums by users who don't pay attention to that requirement askign why they are getting a header error about content already being sent. If your processing page has any loops - especially ones that run queries - that is a place to start looking.
  20. Yeah, that is a pretty poor implementation. I would simply create an array of all the links youwant to create then use a for loop to iterate over each one and set the class appropriate based upon the currently selected page. I really don't understand why you would want to put a switch statement inside an array declaration. Makes your code much harder to read/debug. The following code should help. All you should need to do is add your options to the array <?php //Create array of all menu options using $header_title as key with label/href values $menuOptions = array( 'index' => array('label' => 'Products', 'href' => 'index.php'), 'add_product' => array('label' => 'Add new Product', 'href' => 'add_product.php') ); //Set the current page to default, if not in array if(!in_array($header_title, $menuOptions)) { $header_title = 'index'; } //Create HTML for the menu options $menuOptions = ''; foreach($menuOptions as $pageIdx => $option) { $class = ($pageIdx==$header_title) ? 'first-item current' : ''; $menuOptions .= "<li class=\"{$class}\">"; $menuOptions .= "<a tabindex=\"1\" class=\"{$class}\" href=\"{$option['href']}\">{$option['label']}</a>"; $menuOptions .= "</li>\n"; } ?> <div class="submenu"> <div class="submenu-head">Products</div> <ul> <?php echo $menuOptions; ?> </ul> </div>
  21. You mean, if they go to the link with from=Justin they are presented with a page to enter a value THEN when the user submits the page the processing page does not have access to the previous "%from" value, correct? On the page steal.php where you are creating a form for the user to enter an amount, use the $from value to populate a hidden field in the form. Then the page that processes the page will have the value passed in the POST data.
  22. What he said. And it would be impossible for page B to have any ouput and still have a header redirect at the bottom. Most likely the code on page B has some inefficient code and you are looking at a "white-page" while the code is processing.
  23. Because that is not how you destroy a cookie. unset() is used to unset variables within the PHP system. The cookie exists on the user's computer. Why don't you take a look at the setcookie() manual - there is plenty of information there on how to destroy a cookie.
  24. Change your query as follows and this should get you an additional field returned in your db results called 'till_time' $query = "SELECT *, DATE_ADD(start, INTERVAL TIME_TO_SEC(duration) SECOND) AS till_time FROM booking WHERE date='$date' AND store='$store' ORDER BY time"; $result = mysql_query($query) or die ('Could not select ' . mysql_error());
  25. That is probably his preference (it is mine as well). You can use just about any character to deliniate your regex expression. But, the problem with your original pattern was the period which as a wildcard will match any character. That is why it needed to be escaped.
×
×
  • 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.