Jump to content

Twitch

Members
  • Posts

    80
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling
  • Location
    Texas

Twitch's Achievements

Member

Member (2/5)

0

Reputation

  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
×
×
  • 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.