Jump to content

MoFish

Members
  • Posts

    227
  • Joined

  • Last visited

Posts posted by MoFish

  1. Jacques1 & requinex - Sorry about this.

     

    I'm still not getting the results I require. The following is still not returning the correct data - even without the -.

     

    I have attempted so many queries myself and none appear to be correct.

    SELECT * FROM TABLE WHERE DATE(`DDATE`) = DATE_ADD(UTC_DATE(), INTERVAL 3 DAY)
    
  2. Hi Requinex,

     

    Yes, I looked at your query - however noticed you had put a limit on the end of the query - which made me think we were talking about differing things. I could potentially expect more than one result as per my example results above. I have tried multiple times to do the 'middle bit' but am struggling a little. I thought my query above was close.

  3. Hi Requinix, Thanks for your reply.

     

    I may have not communicated correctly what I am trying to achieve - as there could often be more than one result.

     

    Let's say I have the following data in my TABLE and today's date is the 09/02/2017

    ID, DDATE
    
    1, 09/02/2017 (date/time)
    2, 15/02/2017 (date/time)
    3, 20/02/2017 (date/time)
    4, 07/02/2017 (date/time)
    5, 09/02/2017 (date/time)
    6, 06/02/2017 (date/time)
    

    I would expect this to return the following results:

    ID, DDATE
    
    1, 09/02/2017 (today)
    4, 07/02/2017 (tomorrow - inside 3 day range)
    5, 09/02/2017 (today)
    6, 06/02/2017 (3rd day ago - inside 3 day range)
    

    I thought the SQL query would have been something like the following - however this does not work nor is it fully valid.
     

    // SELECT * FROM TABLE WHERE DATE IS BETWEEN TODAYS DATE AND TODAYS DATE + 3 DAYS

    SELECT * FROM TABLE WHERE (`DDATE` BETWEEN UTC_DATE() AND UTC_DATE() + 3 DAY INTERVAL);
    

    Regards,

     

    MoFish

  4. Hi,

     

    Another date query which I'm struggling with. Would anyone be able to help me at all?

     

    I have the following table.

    ID, DDATE
    
    1, 09/02/2017 (date/time)
    2, 15/02/2017 (date/time)
    3, 20/02/2017 (date/time)
    

    I'm trying to only select the values from the DB where the CURRENTDATE is equal to the DDATE value + 3 days afterwards.

     

    For example: Once the CURRENDATE is 09/02/2017 it should return row 1 until the CURRENTDATE hits the 12/02/2017 as that's + 3 days.

     

    It should not return row 2 or 3 until the actual date (15/02/2017) or (20/02/2017) is the CURRENTDATE

     

    I tried this myself a few times and failed - the results are not correct. I used UTC_DATE() in my queries as my server is based in America and i'm in UK.

     

    Any help much appreciated.

     

    Thanks,

     

    MoFish

    SELECT * FROM `TABLE` WHERE `DDATE` = UTC_DATE() AND `DDATE` BETWEEN (DATE((`DDATE`) + INTERVAL 3 DAY) AND UTC_DATE())
    
    SELECT * FROM `TABLE` WHERE (`DDATE`) BETWEEN UTC_DATE() AND (`DDATE`) + INTERVAL 3 DAY
    
    SELECT * FROM TABLE WHERE UTC_DATE() = DATE(`DDATE`) + 3 DAY INTERVAL
    
  5. Thanks for replying Barand.

     

    I have amended your query to suit my needs - the BETWEEN was the key i was missing i think.

     

    The following appears to work as expected for the time being - however i'm guessing when UK hits Brittish Summer Time then things may not work quite aswell. Until then, i'll leave it as it currently is. Thanks again, your a star.

    SELECT * from table WHERE UTC_DATE() BETWEEN DATE(`schedule_start`) AND DATE(`schedule_end`) AND UTC_TIME() BETWEEN `schedule_start` AND `schedule_end`
    

    MoFish

  6. Hi Barand, sorry to bother you again.

     

    I have amended things slightly to use a date/time field instead of a seperate date and time column as it was a bit of an overhead to maintain.

     

    My SQL query has been updated as below - however it doesnt appear to work correctly.

     

    To clarify on what i am trying to do:

     

    I only want to capture results between schedule_start and schedule_end on both the current date and time. i tried UTC_TIMESTAMP also without success.

     

    UTC_TIME was used as you mentioned before to help with the SQL TIME i had.

     

    The query does seem a little long winded.

     

    Regards,

     

    MoFish

    select * from `table` 
    WHERE 
    UTC_DATE() >= `schedule_start` 
    AND 
    UTC_DATE() <= `schedule_end` 
    AND 
    EXTRACT(HOUR_MINUTE FROM UTC_TIME()) >= EXTRACT(HOUR_MINUTE FROM schedule_start) 
    AND 
    EXTRACT(HOUR_MINUTE FROM UTC_TIME()) <= EXTRACT(HOUR_MINUTE FROM schedule_end)
    
  7. Thanks Barand, turns out my server was using an American timezone - darn! :suicide:

     

    I used a set time_zone to Europe/London and all worked! Not sure if this is the best way to update it however.

    SET time_zone = 'Europe/London'; select * from `table` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND EXTRACT(HOUR_MINUTE FROM CURTIME()) = EXTRACT(HOUR_MINUTE FROM schedule_time)
    

    Thanks very much!

     

    MoFish

  8. Thanks for replying Barand.
     
    I tried the following SQL which has no errors - however does not return the result i would have expected.
     

    select * from `table` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND EXTRACT(HOUR_MINUTE FROM CURTIME()) = EXTRACT(HOUR_MINUTE FROM schedule_time)
    

    I set a row in my DB with the following values and waited until 17:06 before performing my query - however nothing was returned. If i remove the time bit you supplied - the correct date results are returned.

    schedule_date_start (date)        schedule_date_end (date)        schedule_time (time)
    2017-01-11 	                  2017-01-18 	                  17:06:00
    

    Is there something i am missing?

     

    Thanks,

     

    MoFish

  9. Hi All,

     

    I have the following DB structure.

     

    schedule_date_start | schedule_date_end | schedule_date_time

    2017-01-11                 |  2017-01-11              | 15:00:00

     

    I am going trying to pefrom a query every minute to find out what items are found between the:

     

    schedule_date_start and schedule_date_end and match the schedule_date_time.

     

    I attempted to do this by writing the following SQL statement. I am finding that i never get any results. This is probably because my script executing is not running at exactly 15:00:00 and quite possibly 15:00:45. Is there an easy way to perform a query which would not take into consideration of the seconds? I tried messing around with the minutes() however didn't have much luck.

    select * from `domains` where CURDATE() >= `schedule_date_start` AND CURDATE() <= `schedule_date_end` AND CURTIME() = `schedule_time`
    

    Thanks,

     

    MoFish :shrug:

  10. Hi Jacques,

     

    Thanks for that - worked perfect.

     

    I was using PHP before, however found that it exceeded my memory_limits on my server everytime it was zipping.

     

    The exec method seemed to be the only way it would zip without falling over.

     

    Cheers,

     

    MoFish

  11. Hi,

     

    I am running a zip command via exec which zips my website up. This works well, however I am a little unsure on the best way to check if this was successfull or not. Should I simply check if the file exists or is there a better way to do this?

    if(isset($_POST['action'])) {
        switch ($_POST['action']) {
            case "zip":
                $script = "cd /websites/N2eGK46OjC/; zip -r -o /call/remote_skeleton.zip *";
                $var = exec($script, $output, $return_var);
                return $return_var; // this returns 0 by default
                break;
        }
    }
    

    Ideally i'm wanting to run this from another file and return the response, however do not know how to best return success or error.

        <script>
    		$(document).ready(function(){
    			$("#btnGo").click(function() {
    				$.ajax({url: 'action.php',
    					data: {action : 'zip'},
    					type: 'post',                  
    					async: 'true',
    					dataType: 'json',
    					beforeSend: function() {
    						$("#loading").show(); // This will show ajax spinner
    					},
    					complete: function() {
    						$("#loading").hide(); // This will hide ajax spinner
    					},
    					success: function (result) {
    						// not sure how to capture here??
    					},
    					error: function (request,error) {
    						// not sure how to capture here??            
    						alert('error');
    					}
    				});                  
    			});  
    		}); 		
    	</script>
    

    Any helps much appriciated.

     

    Cheers,

     

    MoFish

  12. Hi,

     

    I have a WYSIWG editor (called summernote) on my page. I also have a button #add-another which will clone the editor and add multiple.

     

    The issue im having is that im unclear on how best to re-initialise the editors on a button click, as the page does not reload. Can anyone advise?

     

    Should i somehow destroy the editors, then reinitialise? little confused.

     

    I have the following so far, but not sure if im going down the right path, as its not working correctly.

     

    Regards,

     

    MoFish

    <script>
    $(document).ready(function() {
    	function initialize() {
    		$('.wysiwyg').summernote({
    			height:150,
    			minHeight: null,
    			maxHeight: null
    		});
    	}
    
    	initialize();
    
    	$("#add-another").click(function(e) {
    		e.preventDefault();
    		$("#meta-clone").clone().appendTo("#meta-container");
    		initialize();
    	});
    });
    </script>
    
  13. Hi,

     

    I'm using Twitter Bootstrap for a recent project, however require a slightly bigger large container size than default one provided. I therfore adjusted the '@container-large-desktop' in the variable.less file to be (1250px) which corrected the container width to match the design :tease-03: . However, the breakpoints are now a little off, in that when you scale the browser window down in size, it doesnt break as nicely as it did before. I'm not 100% sure which values need updating to correct the breakpoints due to this size change.

     

    Would anyone be able to advise?

     

    Thanks, MoFish

     

    Below is the default breakpoints section of the file which i've tried updating but had no success - so reverted back to default.

    //== Media queries breakpoints
    //
    //## Define the breakpoints at which your layout will change, adapting to different screen sizes.
    
    // Extra small screen / phone
    //** Deprecated `@screen-xs` as of v3.0.1
    @screen-xs:                  480px;
    //** Deprecated `@screen-xs-min` as of v3.2.0
    @screen-xs-min:              @screen-xs;
    //** Deprecated `@screen-phone` as of v3.0.1
    @screen-phone:               @screen-xs-min;
    
    // Small screen / tablet
    //** Deprecated `@screen-sm` as of v3.0.1
    @screen-sm:                  768px;
    @screen-sm-min:              @screen-sm;
    //** Deprecated `@screen-tablet` as of v3.0.1
    @screen-tablet:              @screen-sm-min;
    
    // Medium screen / desktop
    //** Deprecated `@screen-md` as of v3.0.1
    @screen-md:                  992px;
    @screen-md-min:              @screen-md;
    //** Deprecated `@screen-desktop` as of v3.0.1
    @screen-desktop:             @screen-md-min;
    
    // Large screen / wide desktop
    //** Deprecated `@screen-lg` as of v3.0.1
    @screen-lg:                  1200px;
    @screen-lg-min:              @screen-lg;
    //** Deprecated `@screen-lg-desktop` as of v3.0.1
    @screen-lg-desktop:          @screen-lg-min;
    
    // So media queries don't overlap when required, provide a maximum
    @screen-xs-max:              (@screen-sm-min - 1);
    @screen-sm-max:              (@screen-md-min - 1);
    @screen-md-max:              (@screen-lg-min - 1);
    

    Below is the container sizes. I updated the '@container-large-desktop' value.

    //== Container sizes
    //
    //## Define the maximum width of `.container` for different screen sizes.
    
    // Small screen / tablet
    @container-tablet:             (720px + @grid-gutter-width);
    //** For `@screen-sm-min` and up.
    @container-sm:                 @container-tablet;
    
    // Medium screen / desktop
    @container-desktop:            (940px + @grid-gutter-width);
    //** For `@screen-md-min` and up.
    @container-md:                 @container-desktop;
    
    // Large screen / wide desktop
    @container-large-desktop:      (1250px + @grid-gutter-width);
    //** For `@screen-lg-min` and up.
    @container-lg:                 @container-large-desktop;
    
  14. Hi,

     

    Sorry, I don't mean to make things confusing. I had an overall picture of how I wanted my project to work, and feel it could work if i could break it down and figure out the small components. For the moment i'm focusing on building a form from the contents of the file (image.php). I have played around with things since the orignal post and have got a little further, however am again running into problems. My code now finds the <mofish> tags in the file amoungst other HTML which I then read using the DOMDocument. In my final $string, when I echo it, it writes back the fields as I would expect, however when I do a return on the $string it only returns one field. As Jacques said, maybe i'm going down the wrong road completely - but feel i'm close in getting the form fields displaying which is all I need for the time being.

     

    @requinix - the code is mine - and I can edit it anyway fit get the form fields to display.

    	public function generate_form($filename='image.php')
    	{
    		$html = file_get_contents("./placeholder_templates/".$filename, true);
    		preg_match_all('/<mofish[^>]+>/i',$html, $results); 
    		
    		foreach($results['0'] as $result){
    			//echo htmlentities($result) . "<br/>";
    			
    			$doc = new DOMDocument();
    			@$doc->loadHTML($result);
    			$tags = $doc->getElementsByTagName("mofish");
    			$string = "";
    			
    			foreach ($tags as $tag) {
    
    				switch ($tag->getAttribute('type')){
    					case "text":
    						$string .= "<div class='form-group'>
    										<label for=''>".$tag->getAttribute('label')."</label>
    										<input class='form-control' type='text' name='' value='' />
    									</div>";
    						break;
    					case "image":
    						$string .= "<div class='form-group'>
    										<label for=''>".$tag->getAttribute('label')."</label>
    										<input class='form-control' type='file' name='' value='' />
    									</div>";
    						break;
    					default:
    						echo "could not find";
    				}
    				//echo $string;
    			}
    			
    			//echo  $string;
    			return $string;
    		}
    		
    	}
    
  15. Hi Jacques1,

     

    The reason for the <mofish> placeholders being in amoungst HTML, is that I thought my administration panel could generate form as explained above, and from the front end of the website the <mofish> tags could be fully replaced with the database values inserted in the form. For example the following:

    <img src="<mofish id="image" type="image" label="Please select an image" required="true" title="true" />"  alt="<mofish id="text" type="text" label="Image alternative text" required="true" title="true" />" />
    

    Administration:

     

    This would look at the following string, and generate form fields as explained above - ignoring the syntax around the <mofish> tags and generate a form based on the attribute values.

     

    Front End

     

    This would look at the above string and replace the <mofish> tags with the database values assigned from the administration form above, giving an output of something like:

    <img src="image1.jpg"  alt="Welcome to my page" />
    

    That was the idea in my head, but I understand its a little strange!

  16. Hi Jacques1,

    What i am trying to do is read a HTML file (image.php) which could in theory contain multiple <mofish> tags.

    I want to loop around each tag and find out the 'type' attribute associaited with each tag.

    Once I have found the type - I can then build up a simple form using the attributes. Please see the below as an example:

    <img src="<mofish id="image" type="image" label="Please select an image" required="true" title="true" />"  alt="<mofish id="text" type="text" label="Image alternative text" required="true" title="true" />" />
    

    This would generate a form like the following: (i'm ignoring required and title for now).

    <label>Please select an image</label>
    <input type="file" name="" />
    
    <label>Image alternative text</label>
    <input type="text" name="" />
    

    The example I put together didnt work, but you might get the general idea from the below:

    $html = file_get_contents("placeholder_templates/image.php", true);
    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $tags = $doc->getElementsByTagName("mofish");
    
    // find out which tag it is
    foreach ($tags as $tag) {	
    	switch ($tag->getAttribute('type')){
    		case "text":
    			// display text
    			echo "<div class='row'>";
    				echo "<label for=''>".$tag->getAttribute('label')."</label>";
    				echo "<input type='text' name='' value='' />";
    			echo "</div> <br/>";		
    			
    			break;
    		case "image":
    			// display file upload
    			echo "<div class='row'>";
    				echo "<label for=''>".$tag->getAttribute('label')."</label>";
    				echo "<input type='file' name='' value='' />";
    			echo "</div> <br/>";
    			break;
    		default:
    			echo "could not find";
    	}
    }	
    
    

    MoFish

  17. Hi,

    I have the following code inside my image.php file which I can read okay:

    <mofish id="image" type="image" label="Please select an image" required="true" title="true" />
    

    However if i put my tag amoungst other HTML it doesnt seem to find it. Can anybody shed any light on this? I've tried changing the quotes around etc with no success.

    <img src="<mofish id="image" type="image" label="Please select an image" required="true" title="true" />" />
    

    Ideally i need to be able to read the mofish tag regardless of what is around it.

    Regards,

    MoFish
     

    $html = file_get_contents("placeholder_templates/image.php", true);
    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $tags = $doc->getElementsByTagName("mofish");
    
    foreach ($tags as $tag) {    
        
        echo "<pre>";
        print_r ($tag);
        echo "</pre>";
    }
    
  18. Hi,

     

    I have a folder called "skeleton" which sits in the root of my website. Inside the folder is a selection of folders and files e.g.

    -- skeleton
        -- areas
            -- uk.html
        -- pages
            -- contact.html
            -- index.html
        -- images
            -- panda.jpg
        -- javascript
            -- jquery.js
    

    Using code ignitors built in zip library I have managed to successfully get zip a folder with all the child files/folders, however it is also including the root "skeleton" folder inside the zip file which i'm trying to exclude. Does anyone know if there is a way to exclude the root directory you are zipping? I have had a read of the documentation at https://ellislab.com/codeigniter/user-guide/libraries/zip.html and cannot find the answer or am simply overlooking it.

     

    My code is as follows:

    $this->zip->read_dir("./skeleton", false);
    $this->zip->archive($this->skeleton_path."remote_skeleton.zip");
    

    Any help much appreciated.

     

    Thanks,

     

    MoFish

     

  19. Hi Phyco,

     

    Sometimes it just takes someone to state the obvious! I double checked the html files and it seems like the placeholder text did not save into them correctly.

     

    The functon i wrote therfore works perfectly, after a few hours scratching my head!

     

    Thank you

     

    MoFish

  20. Hi,

     

    I have created the following function but it is not working as I had hoped.

     

    I have an array of files, inside these files are placeholder values.

     

    I'm wanting to loop around the files and find all instances of the placeholders.

        public function findPlaceholders(){
    	$filenames = array("index.html", "areas.html", "testing.html");
            $placeholders = array("{TITLETAG_PLACEHOLDER}","{METADESC_PLACEHOLDER}","{METAKEYWORDS_PLACEHOLDER}","{H1_PLACEHOLDER}","{AREALINKS_PLACEHOLDER}");
             
             foreach($filenames as $filename){
             	// echo $filename . "<br/>";
             	$source = file_get_contents($this->skeleton_dir.$filename);
             	foreach ($placeholders as $placeholder){
    		        if(strpos($source, $placeholder)){
    		        	//echo $placeholder . "<br/>";
    		        	echo $placeholder . " found inside the file named ". $filename . "<br/>";
    		        }
             	}
             }
        }
    

    The function works to an extent, in that it loops around the files and writes out a single instance of the placeholder value when found, however some files have multiple placeholders which it is not displaying. Where have I gone wrong? I was hoping that it would write out all instances of the placeholders inside the files. Clearly i've got a little lost.

     

    Output

     

     

    {AREALINKS_PLACEHOLDER} found inside the file named areas.html
    {H1_PLACEHOLDER} found inside the file named testing.html

     

    Thanks,

     

    MoFish

  21. Hi,

     

    I have an array of files, and i want to check they ALL exist.

     

    I have put together the following, but it doesnt check they all exist correctly -  it simply returns true, false for each individual file so is a bit of a lottery depending on the order of whats going to happen. Is there an easy way im overlooking to do this? should I be setting a variable and then checking that out-with the loop?

     

    Thanks,

     

    MoFish

    $filenames = array("index.html", "areas.html", "test.html", "example.xls");
    foreach ($filenames as $file){
        if(!file_exists($this->skeleton_dir.$file)){
            return false;
        }else{
            return true;
        }
    }
    
×
×
  • 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.