Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. You could try using rollup, which would look something like this:

    SELECT 
    plant_id, SUM(reading) 
    FROM `table_diesel_site`
    WHERE ((week BETWEEN '$first_week' AND '$last_week') AND year='$year')
    GROUP BY plant_id, week with rollup

     

    you may need to reverse plant_id and week in the group by

  2. try adding the word "explain" before your select statements. It will tell you which keys (if any) it is/isn't using.

     

    example:

    mysql> explain select * from members where member_id = 108649;
    +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+
    | id | select_type | table   | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+
    |  1 | SIMPLE      | members | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
    +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+
    

     

    you want to look at the column "key" if it is "NULL" you are not using a key, and you should then add one. Paste the query your running, and we can help you choose indexes to use.

     

    Thanks

  3. Say I have a chunk of code that looks like this (contains imagesx):

     

    <span style="color: #0000BB">$width </span><span style="color: #007700">= </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$img</span><span style="color: #007700">);  <br />

     

    within the code I would like to make all the php functions link to php.net

     

    I thought that the following code would work, but it does not, well because there is no spaces around the above word

    	public function phpLinks($string){
    	$words = explode(" ", $string);
    	$str = array();
    	foreach($words as $word){
    		if(function_exists($word)){
    			$str[] = preg_replace("/$word/i", '<a href="//php.net/'.strtolower($word).'">'.$word.'</a>', $word);
    		}else{
    			$str[] = $word;
    		}
    	}
    	return implode(" ", $str);
    }

     

    I now can not think of a good way to do this, so I am asking does anyone have any suggestions?

  4. I have been looking at the Cassandra Database, and I am trying to figure out how it works, I still don't understand it.

     

    I assume that you wouldn't store your members in the database because you need to search it knowing exactly what key your looking for (but maybe I am wrong).

     

    What types of items/things would you store in a Cassandra database?

    How would a Cassandra database best be used?

  5. I have a bash script that runs as a cron, and one of the commands in the script requires sudo to work. My question is how do I pass a password to sudo?

     

    Here is the bash cron script:

     

    #!/bin/bash
    PHP_FPM_FOUND=`top -n 1 -b | grep -o php-fpm | wc -l`
    
    if [ "$PHP_FPM_FOUND" = "0" ]
    then
        sudo /etc/init.d/php-fpm start
        echo "Started php-fpm"
    else
        echo "Didn't Start php-fpm"
    fi

  6. Creating an index on that query should greatly speed things up.

     

    create index ip_type_photo on pp_ipcache (ipaddr, type, photo);
    -- or maybe even just this:
    create index photo on pp_ipcache (photo);
    

     

    I don't know how many records that table has, and the more there is the longer it will take to create an index, and phpMyAdmin would then be the last place you would wan't to create the index. A Command prompt or shell would be best.

  7. I can not remember how to do this, so any help would be great!

     

    I am getting an alpha value from a pixel between 1 and 127, I need to convert it to a number between 1 and 0.

     

    0 = 127

    1 = 0

     

    If you can help me remember the math to do this, it is very much appreciated!

  8. I own http://phpsnips.com, and we are in the process of rebuilding it, and we want to add a new feature that will allow members to see a demonstration of some of the snippets we have, so they can see the result of the php in action before the use it and then find out it didn't do what they were expecting.

     

    Do you have any suggestions for us on what we should do to keep it secure?

     

    Some of the big things I was thinking of were:

    A. No database examples

    B. No examples with eval

    C. Don't allow examples of all code

  9. I am making custom drop down menu's, and when the div is expanded, everything moves all weird. So the best I could come up with so it doesn't happen is to absolutely position them.

     

    Here is an example of two within a table. The one on the right is the year/month/day, but the month and day are hidden behind the year drop down.

    post-42401-13482403464998_thumb.png

  10. so, it looks like all I had to do on my server was create an nginx dir in my root and add the domain dir. I then just create files in it and I was able to do this for the rewrites:

     

    rewrite ^/snip/([0-9]+)$ /snippet.php?id=$1;
    rewrite ^/snip-([0-9]+)$ /snippet.php?id=$1;
    rewrite ^/snip/images$ /images;

  11. I think I want to convert my server from Apache to Nginx, but one problem I think I may face is mod rewrite rules.

     

    my current .htaccess file looks like this:

    RewriteEngine on
    RewriteRule ^snip/([0-9]+)$ snippet.php?id=$1
    RewriteRule ^snip-([0-9]+)$ snippet.php?id=$1
    RewriteRule ^snip/images$ /images

     

    Is there anything I need to do when converting? do similar rewrite rules work with Nginx?

     

    Any other thoughts on converting or on Nginx?

  12. image mouseovers should be done via css IMO

     

    basically you make one image with two images laid on top of it.

    so say one image is 20x20 the second one would also be 20x20, and your full image would be 40x20 (or 20x40 depending on if you want it vertical/horizontal doesn't really matter).

     

    your HTML would look like this:

    <a href="" id="hoverImage" /></a>
    

     

    and your CSS would look like this:

    /*create a css window with an image as a background */
    a#hoverImage{
    display: block;
    float: left;
    height: 20px;
    width: 20px;
    background-image: url("/path/to/large/image.png");
    background-repeat: no-repeat;
    }
    
    /* 40x20 image this will shift the background image to the left when someone mouse's over it */
    a#hoverImage:hover{
    background-position: -20px 0;
    }
    

  13. I have this jquery that isn't working. It is a search box. When someone searches for something a list of suggestions shows. When they press down it is supposed to go to the first result, down again another result, and so on. The problem I am having is when someone presses down the first time it selectPos is 1, it doesn't go to the first suggest-item, it goes to the first div. press down again selectPos is now 2 and it doesn't go to the second suggest-item but the second div. This continues up till 5 and starts over (which it should do).

     

    so, why is it going to the nth div and not the nth suggest-item?

     

    The jquery:

    $("div#suggest div.suggest-item:nth-child("+(selectPos)+")").addClass("suggest-hover");

     

    The HTML:

    <div id="suggest" style="display: none; ">
    <div class="suggest-header">
    	<div class="suggest-strike"></div>
    	<div class="suggest-head">SNIPPETS</div>
    </div>
    <div class="suggest-nomatch">No Matches Found</div>
    <div class="suggest-header">
    	<div class="suggest-strike"></div>
    	<div class="suggest-head">PEOPLE</div>
    </div>
    <div class="suggest-item" id="people_886">imPathpaif</div>
    <div class="suggest-item" id="people_1367">perybrirur</div>
    <div class="suggest-item" id="people_4093">Meectireen</div>
    <div class="suggest-item" id="people_111522">TotEsopsyZ</div>
    <div class="suggest-item" id="people_111560">fluffZoorn</div>
    </div>

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