Jump to content

Twitch

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by Twitch

  1. Sorry I didn't mean to be vague I was just trying to give you the parts that I thought might be the issue as not to post a ton of code making the post very long. I thought less would make it easier to read. I really appreciate the replies and I definitely don't want to waste your time. I'll give more of a real example. Also I apologize for the typos and errors in earlier code. I was retyping code instead of cutting and pasting. I'm basically doing a simple template. I may not be going about it correctly but this way works with the exception of custom tags that start with the same text. I have used less compact code so you can see my workflow. For example: $custom_tag_array = array('A_ROW','A_COLUMN','A_COLUMN_HEADER'); $content = '[A_ROW] [A_COLUMN] [A_COLUMN|style^color:#00ff00]NESTED COLUMN LEFT<br />It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).[/A_COLUMN] [A_COLUMN]<span style="color:#0000ff;">NESTED COLUMN RIGHT<br />It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</span>[/A_COLUMN] [/A_COLUMN] [A_COLUMN] Outer right half [/A_COLUMN] [/A_ROW]'; foreach($custom_tag_array as $tag){ $matches = array(); $opening_pattern = '~\['.$tag.'(.*?)\]~s'; $closing_pattern = '[/'.$tag.']'; preg_match_all($opening_pattern, $content, $matches); if (!empty($matches[0])){ foreach($matches[0] as $match){ $options_text = preg_replace($opening_pattern, '$1', $match); $options = explode('|',$options_text);//get the parameters - first pipe is for readability but not required foreach($options as $setting){ if (empty($setting)) continue; $setting_exp = explode('^', $setting); if (!isset($setting_exp[1])) continue; ${$setting_exp[0]} = $setting_exp[1];//make variable out of the option }//foreach($options as $setting){ if (!isset($class)){$class = '';} if (isset($style)){$style = 'style="'.$style.'"';}else{$style = '';} switch($tag){ case 'A_ROW': $replacement_string = '<div class="custom-row '.$class.'" '.$style.'>'; $closing_tag = '</div><!--/'.$tag.'-->'; break; case 'A_COLUMN': $replacement_string = '<div class="custom-column '.$class.'" '.$style.'>'; $closing_tag = '</div><!--/'.$tag.'-->'; break; case 'A_COLUMN_HEADER': $replacement_string = '<h1 class="custom-header '.$class.'" '.$style.'>'; $closing_tag = '</h1><!--/'.$tag.'-->'; break; }//switch($component){ $content = str_replace(array($closing_pattern,$match),array($closing_tag,$replacement_string),$content); }//foreach($matches[0] as $match){ }//if (!empty($matches[0])){ }//foreach($custom_tag_array as $tag){ echo $content; The above code works as expected. It generates the expected html <div class="custom-row "> <div class="custom-column " style=""> <div class="custom-column " style="color:#00ff00">NESTED COLUMN LEFT<br>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div><!--/A_COLUMN--> <div class="custom-column " style=""><span style="color:#0000ff;">NESTED COLUMN RIGHT<br>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</span></div><!--/A_COLUMN--> </div><!--/A_COLUMN--> <div class="custom-column " style=""> Outer right half </div><!--/A_COLUMN--> </div> However if I place [A_COLUMN_HEADER]Header Text[/A_COLUMN_HEADER] in the content it renders the following <div class="custom-row "> <div class="custom-column " style=""> <div class="custom-column " style="style=" ""="">Header Text[/A_COLUMN_HEADER] <div class="custom-column " style="color:#00ff00">NESTED COLUMN LEFT<br>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div><!--/A_COLUMN--> <div class="custom-column " style=""><span style="color:#0000ff;">NESTED COLUMN RIGHT<br>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</span></div><!--/A_COLUMN--> </div><!--/A_COLUMN--> <div class="custom-column " style=""> Outer right half </div><!--/A_COLUMN--> </div><!--/A_ROW--> </div> I believe the culprit is in my opening_pattern. It's matching A_COLUMN_HEADER when it is looping through the A_COLUMN. It works if I put A_COLUMN_HEADER first in the loop, but I was hoping for a better solution in the matching so it didn't matter which order they were in. Hopefully this makes it more clear. Also, I have used the method of matching both the opening and closing tags like you posted above, however that seemed to cause issues with nested tags. Course it could have been bad code on my part...haha Thanks again for all the help.
  2. I found the culprit. The code I posted earlier runs in a loop from an array of custom tags. It's the preg_match_all that's incorrectly matching. I should have known that was the likely place, but I've been up since 3 am and it's almost 3 pm my time now so my brain is not functioning properly. So here is what is going wrong: $custom_tag_array = array('A_CUSTOM','A_CUSTOM_TAG'); foreach($custom_tag_array as $tag){ $opening_pattern = '~\[A_'.$tag.'(.*?)\]~';//THIS APPEARS TO BE THE CULPRIT $closing_pattern = '[/A_'.$tag.']'; preg_match_all($opening_pattern, $content, $matches); if (!empty($matches[0])){ foreach($matches[0] as $match){ //THERE IS A FILE HERE THAT PROCESSES THE REPLACEMENT STRING BASED ON THE TAG $content = str_replace($match,$replacement_string,$content); }//foreach($matches[0] as $match){ }//foreach($custom_tag_array as $tag){ If I print_r($matches[0]); when the A_CUSTOM is in the loop it also shows that it matched A_CUSTOM_TAG. I need the A_'.$tag.' of the opening and closing patters to be more greedy. (.*?) part of the opening pattern is to catch the optional parameters. I tried some of the suggesting on a regex site, but I'm guessing I wasn't using them properly. Any suggestions on how to make the match more exact? Thanks in advance!
  3. Thanks for all the replies. mac_gyver I'm using Coda 2 on a Mac to edit files. It must be elsewhere in my code. I'll reply back if I find out what it was. Thanks again!
  4. Thanks for the reply. Yea I had a missing single quote in my example code. That's a very simplistic example. I guess I'll have to look elsewhere in the code for the culprit. Thanks again for the reply.
  5. Hello All, I've been knocking my head against the wall for several hours trying to figure out what's going on with a simple string replace. For the most part it is working beautifully, but if a string contains a similar but not exact match it still replaces the non match. I was under the impression that str_replace always looks for an exact match. I have custom tags that are in strings of text that are structured like: [A_CUSTOM_HEADER] [A_CUSTOM_TITLE] and so on. They always start with "[A_CUSTOM" and end with a " ] ". In between the start and end can be just about anything. So my problem is if I have [A_CUSTOM] and [A_CUSTOM_TAG] in the same text str_replace seems to incorrectly replace all the [A_CUSTOM_TAG] with the [A_CUSTOM] content and the match never happens for the [A_CUSTOM_TAG] content. For example: $content = 'Here is some text and [A_CUSTOM]. Here is more text and [A_CUSTOM_TAG]'. $content = str_replace('[A_CUSTOM]','I have a and custom',$content); $content = str_replace('[A_CUSTOM_TAG]','I have a, custom and tag',$content); So running that code The [A_CUSTOM_TAG] content never gets replaced correctly, it is replaced on the first pass with the [A_CUSTOM] replacement content. I hope this make sense I'm trying to explain it the best I can. I tried using preg_replace() with \b to match the whole word but didn't get anything close to the respected results...haha I'm sure I'm missing something simple...or at least I hope I am. Thanks in advance!
  6. Thanks for the quick reply equinox. I got it working. I was putting /s before the ~ when I just needed to put s after the ~ Thanks again!
  7. Hello All, I have been wrestling with a regex for a couple of hours now and I finally had to give in and ask for help. The weird thing is that it works if there are no new lines in the text, it fails if there is a new line(s) present. The code: $matches = array(); $pattern = '~\[CUSTOM_TAG(.*?)\](.*?)\[/CUSTOM_TAG\]~'; preg_match_all($pattern, $html, $matches); if (!empty($matches[0])){ foreach($matches[0] as $code){ $parameter = preg_replace($pattern, '$1', $code); $content = preg_replace($pattern, '$2', $code);//get the content between the pattern }//foreach($matches[0] as $code){ }else{ echo 'Match failed'; }//if (!empty($matches[0])){ So with that code in mind, if the $html variable (the text to be processed) is: $html = '<h1>Hello, world!</h1><p style="color:#ff0000;">Some red text</p>'; A match is found. If the $html variable is: $html = '<h1>Hello, world!</h1> <p style="color:#ff0000;">Some red text</p>'; Match not found Hopefully I'm just missing something simple in my regex. Thanks in advance! Twitch
  8. Ok I knew I was close I guess I just needed some sleep...haha Here is the query that gets what I want in case someone else needs it: SELECT ( ROUND(SUM(TIMESTAMPDIFF( MINUTE , slip_start, slip_end ) /60*slip_rate),2)) AS TOTAL FROM `slip` WHERE project_id=3
  9. Hello Fellow Freaks, I have written two simple queries to grab some totals. This query successfully gets the subtotal of each row based on the rate and the amount of minutes select slip_rate AS RATE_PER_HOUR,ROUND( ( SUM( TIMESTAMPDIFF( MINUTE , slip.slip_start, slip.slip_end ) ) ) ) AS MINS,ROUND( ( SUM( TIMESTAMPDIFF( MINUTE , slip.slip_start, slip.slip_end ) ) /60 ) * slip_rate, 2 ) AS SUB_TOTAL FROM slip WHERE project_id=3 GROUP BY slip_id The above code returns: RATE_PER_HOUR | MINS | SUB_TOTAL 65.00 | 135 | 146.25 25.00 | 120 | 50.00 65.00 | NULL | NULL This one is almost what I want... select slip_rate AS RATE_PER_HOUR,ROUND( ( SUM( TIMESTAMPDIFF( MINUTE , slip.slip_start, slip.slip_end ) ) ) ) AS MINS,ROUND( ( SUM( TIMESTAMPDIFF( MINUTE , slip.slip_start, slip.slip_end ) ) /60 ) * slip_rate, 2 ) AS TOTAL FROM slip WHERE project_id=3 The above code returns: RATE_PER_HOUR | MINS | TOTAL 65.00 | 255 | 276.25 As you can see the mins are correct however it is calculating all of them at the 65.00 rate. All I wish to do is write a simple query that will return TOTAL 196.25 I'm sure I'm close I just haven't messed much with the SUM and TIMESTAMPDIFF function so any help would be greatly appreciated. Thanks in advance, Twitch
  10. Thanks for the reply, Psycho. I was able to get it with this: SET @runtot := 0; SELECT Adjustments, Month, (@runtot := @runtot + Adjustments) AS RT FROM ( SELECT COUNT(adjustment_id) AS Adjustments, DATE(FROM_UNIXTIME(shifts.outtime)) AS 'Month' FROM adjustments INNER JOIN shifts ON ( shifts.shiftID = adjustments.shiftID ) INNER JOIN employees ON (shifts.idnum = employees.idnum) WHERE YEAR (FROM_UNIXTIME(shifts.outtime)) = '2012' GROUP BY MONTH(FROM_UNIXTIME(shifts.outtime)) ORDER BY MONTH(FROM_UNIXTIME(shifts.outtime)) ASC ) x
  11. hey guys, I am close to accomplishing a running total column but I think I am missing something simple. Any help would be greatly appreciated. SET @runtot := 0; SELECT COUNT(adjustment_id) AS Adjustments, DATE(FROM_UNIXTIME(shifts.outtime)) AS 'Month', (@runtot := @runtot + COUNT(adjustment_id)) AS RT FROM adjustments INNER JOIN shifts ON ( shifts.shiftID = adjustments.shiftID ) INNER JOIN employees ON (shifts.idnum = employees.idnum) WHERE YEAR (FROM_UNIXTIME(shifts.outtime)) = '2012' GROUP BY MONTH(FROM_UNIXTIME(shifts.outtime)) ORDER BY MONTH(FROM_UNIXTIME(shifts.outtime)) ASC The code above outputs: Adjustments | Month | RT 34 | 2012-08-29 | 34 161 | 2012-09-01 | 161 The RT matches the Adjustments and doesn't show the running total. Thanks in advance, Twitch
  12. Thanks again Barand...it almost does what I need but it will come in very handy for future queries as well.
  13. Thanks so much for the response Barand. I will try it out when I get a chance and let you know. -Twitch
  14. Hello Everyone, I'm hoping there is a simple solution to my issue. I have the following UNION query: SELECT reservation_items.productQuantity AS PRODUCT_TOTAL, products.productLabel,products.productImage FROM reservations INNER JOIN reservation_items ON reservations.reservationID = reservation_items.reservationID INNER JOIN venue_products ON (reservation_items.venueProductID = venue_products.venueProductID) INNER JOIN products ON (venue_products.productID = products.productID) WHERE reservations.venueID = 84 AND productIdentity = 1 AND reservation_items.venueProductID > 0 AND reservations.reservationStatus != 4 AND YEARWEEK(reservationDate, 1) = YEARWEEK(CURDATE(), 1) UNION SELECT SUM( productQuantity * specialQuantity ) AS SPECIALS_QUANTITY, products.productLabel,products.productImage FROM reservations INNER JOIN reservation_items ON reservations.reservationID = reservation_items.reservationID INNER JOIN special_items ON reservation_items.specialProductID = special_items.specialProductID INNER JOIN venue_products ON (special_items.venueProductID = venue_products.venueProductID) INNER JOIN products ON (venue_products.productID = products.productID) WHERE reservations.venueID = 84 AND productIdentity = 1 AND reservation_items.specialProductID > 0 AND reservations.reservationStatus != 4 AND YEARWEEK(reservationDate, 1) = YEARWEEK(CURDATE(), 1) GROUP BY products.productID ORDER BY PRODUCT_TOTAL DESC LIMIT 5 The query works fine except if say for instance productID 25 is in the first SELECT result and in the second SELECT result it does not combine the quantity into one result. It will treat them separate. How can I have this query add the sums of like productIDs? I'm guessing I can use an IF statement but don't have must experience with those in a MySQL statement. Hope that makes sense. As always, thanks in advance for the help. -Twitch
  15. Well after more testing I'm convinced my code is correct as well. I was using this code to generate a PDF using mPDF and I'm thinking the issue is lying with the mPDF class because when I get rid of all mPDF code I don't get the invalid argument error. Thanks for the reply, mikesta707. Much appreciated. -Twitch
  16. Thanks for such a rapid reply, mikesta707. The array I try to create from the posted comma separated values uses this code: if (isset($_POST['case_ids'])){ $case_ids = mysql_real_escape_string($_POST['case_ids']); $case_ids = explode(",", $case_ids); print_r($case_ids); when I print_r($case_ids) then I get the aforementioned: Array ( [0] => 10067 [1] => 10076 ) The foreach loop is similar to below (I simplified the $html so the code is more compact. The actual $html that is echo'd is longer) foreach($case_ids as $key => $value){//$key is not necessary but I included as troubleshooting step mysql_select_db($database_db, $db); $query_case = "SELECT case_name FROM cases WHERE case_id = '".$value."'"; $case = mysql_query($query_case, $db) or die(mysql_error()); $row_case = mysql_fetch_assoc($case); $totalRows_case = mysql_num_rows($case); $html = '<a href="somewhere.php">'; $html .= $row_case['case_name']; $html .= '</a><br />'; echo $html; } Thanks again for the help. -Twitch
  17. Hello gurus, I've been pounding my head against the wall on this one. It must be something simple I'm missing. I have a text field that posts ($_POST['case_ids']) a comma separated value such as 10067,10076 When I use explode to break it up it should make it an array. However when I use it in a foreach loop I get an invalid argument error. If I do a check for is_array() it fails the check. If I print the array I get: Array ( [0] => 10067 [1] => 10076 ) So I thought maybe I get the error because the individual array elements don't have commas between them so I wrote this to put commas in between each element except the last: $cases = array(); $numItems = count($case_ids);//get count of array $i = 0;//initialize counter foreach($case_ids as $key => $value){ if($i+1 != $numItems) { $cases[$key] = $value.','; }else{ $cases[$key] = $value; }//end if $i+1 $i++; } However this new array still gets the invalid argument error. Are these not valid arrays? Any help would be greatly appreciated. Thanks in advance, Twitch
  18. my mistake, I needed to use exactly what you wrote...haha Thanks, it's working!
  19. Thanks for the incredibly fast reply. I see what you're saying so I assumed I needed to do it like this: <?php $days = explode(",",$row['specialDaily']);?> <?php $weekdays = array($days[0]);?> However that doesn't seem to work either. Thanks, Twitch
  20. I have checkboxes (one for each day of the week) that I want to mark checked if the value is in an array. The value of $row['specialDaily'] could be something like 1,2,0 or 1 or 2,3,6 etc. <?php $weekdays = array($row['specialDaily']);?> <input name="monday" type="checkbox" id="monday" value="1" class="weekday" <?php if (in_array("1", $weekdays)) { echo "checked='checked'"; }?> /><input name="tuesday" type="checkbox" id="tuesday" value="2" class="weekday" <?php if (in_array("2", $weekdays)) { echo "checked='checked'"; }?> /> If the array only contains one value, the proper checkbox is checked. However, if it contains more than 1 value no checkboxes are checked. I just found the in_array() function and assumed it was exactly what I'm looking for. I assumed that since $row['specialDaily']'s value is like an array I could just plug it in. Unfortunately, (unless I'm missing something simple) I'm thinking it doesn't work the way I hoped. Thanks in advance, Twitch
  21. Hi Fenway, thanks for the reply. I wasn't sure what HAVING was, but since posting this the difference between WHERE and HAVING was explained to me like so: "It's like asking someone to fetch blue balls from a dark room filled with different colored balls and cubes. You can tell them to SELECT balls FROM room WHERE shape='round' HAVING color='blue'. While performing the query (fetching the items), the shape is used to limit the number of retrieved items, but the color is not known until after the query has finished and the balls are brought out into the light, and as such they have to be discarded after everything is retrieved." I haven't had a chance to go back and reexamine this query. I'm just now getting into more complicated queries and using aliases etc. Once again, thanks a bunch for the reply. Hopefully, I'll get to re-write this query tonight. Sincerely, Twitch
  22. Bummer, no replies. I've been trying to find an answer but still nothing. I have found out that WHERE won't work with SUM and I'm not sure if HAVING is what I'm supposed to do. Back to Google... :-\
  23. Should be simple enough if I understand correctly. UPDATE houses SET field_2='YES' WHERE field_1 !='' Or if by empty you mean NULL UPDATE houses SET field_2='YES' WHERE field_1 IS NOT NULL
  24. Maybe do something like this: <?php $four_days = mktime(0, 0, 0, date("m"), date("d")+4, date("y")); echo "4 days from now is ".date("m/d/y", $four_days); ?> Of course in your example you'd use the value to be entered into the database.
  25. Hello Gurus, I've tried all day to get this query right, but no luck so I finally had to break down and ask for help. I'm using MySQL 5.0 I have a reservation system where products can be reserved. The reservation_items table is like so: id | specialProductID | productID | quantity 1 101 0 2 2 0 102 3 The specialProductID is actually a bundle of products with their own quantities tied to a special_items table like so: specialProductID | productID | quantity 101 103 2 101 104 1 My goal is to display the top 3 reserved products based on highest quantity individually. So in the case above my repeat region would show this order: Top products 103 quantity of 4 102 quantity of 3 104 quantity of 2 When the reservation item is not part of a bundle then the quantity in the reservation_items table is the quantity, if it's a special product (a bundle of products) the reservation_items quantity is multiplied by the special product quantity. I have gotten my query close, but not quite what I need. SELECT SUM(productQuantity * specialQuantity) AS Specials_Quantity, SUM(productQuantity) AS Products_Quantity FROM reservations INNER JOIN reservation_items ON (reservations.reservationID = reservation_items.reservationID) INNER JOIN special_items ON (reservation_items.specialProductID = special_items.specialProductID) INNER JOIN products ON (special_items.productID = products.productID) GROUP BY productQuantity ORDER BY Specials_Quantity, Bottles_Quantity I believe I also need to add a WHERE reservation_items.specialProductID<>0 to the Special_Quantity SUM and WHERE reservation_items.specialProductID=0 to the Bottles_Quantity but I don't know the proper syntax. Any help would be greatly appreciated. Thanks in advance, Twitch
×
×
  • 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.