Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. Back in 2007 / 2008 I wrote a voting script which stores votes. The problem I have is I save the votes badly. I have 2 columns:

     

    - voteTotal (sum of all the votes)

    - votes (number of people who voted)

     

    Here are two values of on item:

    1394

    431

     

    I want to break these up into single Items. I know I cannot go back into time and get the values, but I would like to calculate what could have been used. So for the above example, I would insert 431 rows into a table, each with a value of 1-5 (int's) all rows adding up to 1394.

     

    Any ideas of what I could do for this?

  2. there are two ways to do this.

     

    1. MySQL

    insert into my_table (...) values (...);
    set @i1 = (select last_insert_id());
    select * from my_table where id = @i1;
    

     

    2. PHP

    mysql_query("insert into my_table (...) values (...)");
    $lid = mysql_insert_id();
    mysql_query("select * from my_table where id = $lid");
    

  3. This is how yours should look:

     

    select t1.user_email, t2.img_thumb from table_1 as t1 left join table_2 as t2 on t1.user_id = t2.img_id_fk having t2.img_thumb is not null order by rand() limit 5

     

    Yours does NOT check NULLs after the result set is built, if a member doesn't have a row in table 2 you will get a NULL in your result set when using a left join and no HAVING.

     

    My method will automatically ignore the NULLs, so I don't need to check for a null during a search and after the search.

  4. You don't have to check for NULL if you do join instead of a left join, the is not null would also be in the having, not the where. Also you want to order by rand and limit it to 5 results.

     

    select t1.*, t2.img_thumb from table1 t1 joint table2 t2 on (t1.user_id = t2.img_id_fk) order by rand() limit 5;

  5. scootstah, I don't think your code will work, because it doesn't support multiline

     

    This supports multiline:

    $source = file_get_contents('test.txt');
    $pattern = '/<blockquote class="postcontent restore">(.*)<\/blockquote>/isU';
    preg_match_all($pattern, $source, $matches);
    print_r($matches);

  6. Like this:

     

    <?php
    $var = "Arson"
    ?>
    <script type="text/javascript" src="js/swfobject.js"></script>
    <script type="text/javascript">
    
    swfobject.embedSWF(
      "open-flash-chart.swf", "my_chart",
      "550", "400", "9.0.0", "expressInstall.swf",
      {"data-file":"ofc-chart.php?crime=<?php echo $var; ?>"} );
    
    </script>

  7. lets say I own a file, and you own a file,  both these files are the exact same file, the only difference is the filename. So lets say we both have The Gimp 2.6 but one is named TG2.6.exe and the other is named the_Gimp-2.6.exe. What would be the best way to count the files that are the same even if they have a different file name? Another example would be:

     

    I have a file called me.jpg and someone else has a file me.jpg but they are two completely different pictures. What would I do to tell that?

  8. string is one of the following (loop through them):

    Chrysanthemum.jpg

    Cindy.jpg

    Jaimee.jpg

     

    string2 is:

    Family.jpg

     

    here is the actual code I am using if that helps:

    $("td.basename").each(function(){
    var itmid = $(this).parent().attr("id");
    var type = $(this).parent().children(".type").text().toLowerCase();
    if($(this).text() >= newName && !added && type != "folder"){
    	$("#"+itmid).before("<tr class='item' id='item_"+openFile+"'>"+rowData+"</tr>");
    	added = true;
    	return;
    }
    });

  9. What is the best way to compare two strings and alphabetize them?

     

    if(string >= string2){
    $("#"+currentTestID).before(html);
    }

     

    But that doesn't seem to always work.

    I had these three strings:

    - Chrysanthemum.jpg

    - Cindy.jpg

    - Jaimee.jpg

     

    I was then trying to decide where to place this string:

    - Family.jpg

     

    The code above decided it goes best between the two strings That start with "C", when really it should go after "Cindy.jpg".

     

    So, Am I comparing strings wrong for alphabetizing?

  10. Sorry, I didn't read the full question, you want a CSV, well mysql can do that for you:

     

    $query = 'SELECT * INTO OUTFILE '/tmp/name.csv'
    FIELDS TERMINATED BY \',\'
    OPTIONALLY ENCLOSED BY \'"\'
    ESCAPED BY \'\\\'
    LINES TERMINATED BY \'\n\'
    FROM '.$current_table_results.' where id between '.$start_id.' and '.$end_id;
    $result = mysql_query($query);
    
    $zip = new ZipArchive;
    $res = $zip->open('tables.zip', ZipArchive::CREATE);
    if ($res === TRUE) {
        $zip->addFile('/tmp/name.csv', 'name.csv');
        $zip->close();
    }
    
    header("content-type: application/zip");
    header("Content-Length: ".filesize("tables.zip").";");
    readfile('tables.zip');
    

  11. here is what I would do:

     

    Page to start the table builds:

    $email = "something@site.com";
    exec("nohup php /location/to/php/file.php $email 2>&1 &");
    echo "You will receive an email with a link to the file shortly.";
    

     

    file.php

    exec("mysqldump --skip-lock-tables -h localhost -u username --password=mypassword database table1 table2 table3 > /path/to/download/location/file.sql");
    
    $message = "To download your tables, follow the link below \n\n http://mysite.com/downloads/file.sql";
    
    mail($argv[1], "Table Build Complete" $message);
    
    

  12. Recently PHP had security issues with people being able to get data that shouldn't have been able to get (I don't remember which version it was). A few weeks after it was released a new version was released to patch the security hole.

     

    Now lets say you have a site that grabs that data from a database, php releases a new version and you decide to upgrade your version of php which has a hole that allows people to grab variables on a page which now has all the data you grabbed from the database is now accessible.

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