Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. Give this a go:

     

    select * from deals d join handsets h on(d.handset = h.handet_numeric) where h.manufacturer_id = 3 order by d.popularity desc limit 20;

     

    you would want to index:

     

    deals.handset

    handset.handet_numeric

     

    you may even want a doube index on:

    handset.handet_numeric, handset.manufacturer_id

  2. Try this, it looks like you are missing a pair of parenthesis, and a limit

     

    I am not sure if you can have a sub select inside of an in, but if you can I would assume it would look like this.

     

    UPDATE  x_orders
    SET OrderStatus = 1
    WHERE OrderID IN(
    (
    	SELECT     *
    	FROM         x_orders INNER JOIN
    	x_payments ON x_orders.OrderID = x_payments.OrderID
    	WHERE (x_payments.PaymentComplete = 1) AND (x_orders.OrderStatus = 0) limit 1
    )
    );

  3. Do you have any heavy queries running?

    mysql> show full processlist;

     

    Do your servers get too much traffic to handle?

    tail -f /usr/weblogs/access.log

     

    Do an explain on all your queries, and make sure they are using an index, if not modify the query or create an index that the query can use. if it is using an index, can you make the index better?

  4. you don't change max size through phpmyadmin, it is done in your ini file, you need to change your php ini file to allow for larger imports, and you will need to change the php max memory in there too.

     

    Once you save your ini file, shut down Apache and start it back up, your settings should not take affect.

  5. Because an update query is in this format:

    $lyhene = mysql_real_escape_string($_POST['lyhene']);
    $nimi= mysql_real_escape_string($_POST['nimi']);
    $id = (int)$_POST['id'];
    $query =  "update tolkit set lyhenne = '$lyhene', nimi = '$nimi' ... where id = $id;";

  6. here is basically how I like to do it:

     

    (untested)

    <?php
    function between($min, $max, $str){
    if(strlen($str) >= $min && strlen($str) <= $max)
    	return true;
    return false;
    }
    function post($key, $default = ""){
    if(isset($_POST[$key]))
    	return $_POST[$key];
    return $default;
    }
    
    $title = post('title');
    $comment = post('comment');
    $description = post('description');
    $errors = array();
    if(!between(3, 20, $title)){
    $errors[] = "Title is an invalid length)";
    }
    if(!between(10, 1000, $comment)){
    $errors[] = "Comment is an invalid length)";
    }
    if(!between(3, 150, $description)){
    $errors[] = "Description is an invalid length)";
    }
    
    if(count($errors) > 0){
    implode("<br />", $errors);
    }else{
    $title = mysql_real_escape_string($title);
    $descr = mysql_real_escape_string($description);
    $comment = mysql_real_escape_string($comment);
    mysql_query("insert into comments (title, descr, comment) values ('$title', '$descr', '$comment')");
    header("location: /comments.php#new");
    exit;
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="text" name="title" maxlength="20" value="<?php echo $title; ?>" />
    <input type="text" name="description" maxlength="150" value="<?php echo $description; ?>" />
    <textarea cols="100" rows="5"><?php echo $description; ?></textarea>
    </form>

  7. by running the following code, you will create two datetime columns.

    1. is the time it was create

    2. is the time it was last updated.

     

    When you insert a new row, you need to use MySQL's now() function for the date_add column, the date_update column will automatically create a timestamp

     

    alter table some_table add column  date_add datetime null, date_updated timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

  8. You would/could use it like this:

    $q = "INSERT INTO blah(username, password) VALUES('$username', '$password', 1);";
    
    $q .= "INSERT INTO blah2(first_name, last_name, user_id) VALUES('$first_name', '$last_name', last_insert_id());";
    
    $r = mysqli_multi_query($db, $q);

  9. Save it to a mysql variable like this:

     

    $q = "INSERT INTO blah(username, password) VALUES('$username', '$password', 1);";
    
    $q .= "set @user_id = (SELECT user_id FROM blah WHERE login_name='$login_name' limit 1);";
    
    $q .= "INSERT INTO blah2(first_name, last_name, user_id) VALUES('$first_name', '$last_name', @user_id);";
    
    $r = mysqli_multi_query($db, $q);

  10. your queries need semi colons at the end of them, notice my code. Also your first query has more values than columns

     

    $q = "INSERT INTO blah(username, password) VALUES('$username', '$password', 1);";
    
    $q .= "SELECT user_id FROM blah WHERE login_name='$login_name';";
    
    $q .= "INSERT INTO blah2(first_name, last_name, user_id) VALUES('$first_name', '$last_name', '$user_id');";
    
    $r = mysqli_multi_query($db, $q);

  11. insert into all (firstname, lastname, '2011-09-10', info) SELECT firstname, lastname, date, info FROM all WHERE date = '2011-08-30'

     

    Just realized the above has a tiny error

     

    insert into all (firstname, lastname, date, info) SELECT firstname, lastname, '2011-09-10', info FROM all WHERE date = '2011-08-30'

  12. It outputs 1 chunk that is sent to the browser.

     

    It actually outputs one thing, but that can make multiple requests, such as: images, css, javascript, flash, audio, video, xml, etc.

     

    Steps (I believe, correct me if I am wrong or missed something):

    - Client goes to your website
    - Browser makes request to the dns server
    - The dns sever converts to ip
    - the ip is found and it is considered an http request
    - your web server (probably Apache) intercepts the request since it is listening on port 80
         - Apache uploads data (when using: <input type="file">) it is then put into a tmp folder
    - When Apache loads the file requested, it checks for the file extension
    - If there is a if there is something associated with that extension, and the plugin is installed Apache sends the request to the program to do the work
    - The program (php in our case) takes the file and runs it through php doing what ever the php script tells it to do.
    - When the script is complete html is sent back to Apache, and Apache then sends it back out to the web to the requesting client

  13. Nightslyr

     

    for inserting data into your database I am using strip_tags and  addslashes, but do u think mysql_real_escape_string()  is best?

     

    of course mysql_real_escape_string is best :) It was't added for kicks and giggles...

     

    Always, Always, Always, Always, Always, Always, Always, Always, Always, Always, Always, Always, Always, Always use mysql_real_escape_string when inserting strings into a database.

     

    When not using strings you can do this:

     

    <?php
    echo $int = (int)"12.123's";  // $int = 12
    echo "<br />";
    echo $float = (float)"34.234";  // $float = 34.234
    echo "<br />";
    echo $bool = (bool)"kitty"; // $bool = 1
    echo "<br />";
    echo $bool = (bool)null; // $bool = 0
    ?>

  14. You want to do a insert into ... select from.

     

    It would look something like this:

    insert into all (firstname, lastname, '2011-09-10', info) SELECT firstname, lastname, date, info FROM all WHERE date = '2011-08-30'

  15. Come to think of it, I would create a temporary table (mostly because I like them)

     

    The query would looks something like this:

    create temporary table temp_dates (the_date, temp);
    insert into temp_dates (the_date, temp) select Date, TempMax FROM wx_daily ORDER BY TempMax DESC LIMIT 10;
    select * from temp_dates order by the_date desc limit 1;

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