Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by hitman6003

  1. Put the loop outside of inserting it into the array for output.


    $output[] = '<table width="90%" class="onepxtable" align="center"">';
    $output[] = '<tr>';
    $output[] = '<td><h2><a href="store_info.php?id='.$rst["uid"].'">'.$rs_t["username"].' Store</a></h2></td>';
    $output[] = '</tr>';
    $output[] = '<tr>';
    $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'"><img src="http://www.misi.me.uk/uploadedimages/'.$freetplq_img["url"].'" width="75" height="75" border="0" class="onepxtable"></a></td>';
    $output[] = '<td align="left"><a href="cart.php?action=delete&id='.$id.'" class="smlgrey">Remove<img src="http://www.misi.me.uk/images/delete.gif" border="0" align="left"></a></td>';
    $output[] = '<td align="left"><a href="http://www.misi.me.uk/product_desc.php?id='.$id.'">'.$product_name.'</td>';
    $output[] = '<td align="left">£'.$buy_price.'</td>';
    $select_options = '';
    for ($i = 1; $i < $qty; $i++) {
    $select_options .= '<option value="'.$i.'" ' . ($i == $qty ? 'selected="selected" : '') . '>'.$i.'</option>';
    $output[] = '<td align="left"><select name="qty">' . $select_options . '</select></td></tr>';
    $output[] = '<tr><td colspan="5" align="right"><class="smlgrey">Sub total</class> £'.($buy_price * $qty).'</td></tr>';
    $total += $buy_price * $qty;
    $output[] = '</tr>';
    $output[] = '</table><br><br>';

  2. If you have control over your mysql server, turn on query caching....when the exact same query is issued it will pull the result from the cache and not actually query the database.  When the table (or tables) that are selected from are updated in anyway (INSERT, UPDATE, DELETE), it will invalidate the cache and requery...


    If that isn't an option, then your best bet is to write a text file with the result set.  Then use the file's modified time to gauge when to requery.


    Cookies are user specific...unless that is what you want.

  3. Sorry, got distracted and gave you an incomplete example...


    $data = array_map(create_function('$a', 'return "option_" . $a;'), range(1, 20));
    $data = shuffle($data);
    echo "Group One:<br />";
    for ($i = 0; $i < 10; $i++_
    echo '<input type="checkbox" value="' . $data[$i] . '"> ' . $data[$i] . '<br />';
    echo "Group Two:<br />";
    for ($i = 10; $i < 20; $i++_
    echo '<input type="checkbox" value="' . $data[$i] . '"> ' . $data[$i] . '<br />';

  4. MySQL is a multi-threaded application...so it will automatically spawn a thread for each connection.


    Have you actually timed the different parts to determine where the bottle necks are?  I saw you noted one in your code, but have to used microtime to actually time each of the queries and the "specialMath" function?


    Also, buffer the deletes so that you can do only one query for all of them...


    //Get all records from queue, oldest first
    $start = microtime(true);
    $sql = "SELECT id, latitude, longitude, date_inserted FROM queue ORDER BY date_inserted ASC";
    $result = mysql_query($sql) or die(mysql_error());
    echo "The initial query took " . (microtime(true) - $start) . " seconds\n";
    echo "There are " . mysql_num_rows($result) . " rows in the result set\n";
    $delete_ids = array();
    while ($row = mysql_fetch_array($result)) {
       $start = microtime(true);
       $address_object = spacialMath($row[1], $row[2]);
    echo "It took " . (microtime(true) - $start) . " seconds for spacialMath on row with id " . $row[0] . "\n";
       $start = microtime(true);
       $sql = "UPDATE spacial_data SET address = '" . $address_object->address . "', polygon_min = " . $address_object->polygon_min . ", polygon_max = " . $address_object->polygon_max . " WHERE id = " . $row[0];
       // use an unbuffered query here...no need to return a result
       mysql_unbuffered_query($sql) or die(mysql_error());
    echo "It took " . (microtime(true) - $start) . " seconds to update the row\n";
    $delete_ids[] = $row[0];
    $sql = "DELETE FROM queue WHERE id IN(" . implode(", ", $delete_ids) . ")";
    mysql_unbuffered_query($sql) or die(mysql_error());

  5. pretty sure that unless that "script" is being called many thousands of times per second, it's not causing a problem.


    On my Core 2 Duo Laptop running Fedora 8, I ran the your code above one million times in 14.01 seconds, during that time, it consumed 48% CPU...or about 96% of one core.


    At that rate, your code would have to be called 71428 times per second to consume 100% of CPU resources.


    I think that either the problem lies somewhere else, or you need a new host who doesn't whine when you use more than 2% cpu.


    $iterations = 1000000;
    $start = microtime(true);
    for ($i = 0; $i < $iterations; $i++) {
    // Throw out a random image
    $pic = array(
    echo "\n\nTotal time for " . $iterations . " iterations: " . (microtime(true) - $start) . " seconds";

  6. Have you tried reducing the number of times that the script is run?


    Setup for the script takes some time (database connection and query for example), and perhaps eliminating that overhead every 60 seconds will enable the server to devote more cycles to actually processing the data.


    Currently, every 60 seconds the script does...


    check if self is running, if so, kill self
    connect to db
    query db
    loop through 250 rows (15000 rows per hour / 60 minutes) doing functions


    Perhaps changing that to 7500 rows every 30 minutes will help.


    Try to run the script once every 15 - 30 minutes (on a test data set, not live) and see if it makes a difference.


    Also, what "calculations" are you doing on the row(s) that it's taking longer than 60 seconds for ~ 250 rows?

  7. There is no form element with the name "submitform", therefor it will not be in the $_POST array.


    Use print_r to see what is in the $_POST array...


    echo '<pre>' . print_r($_POST, true);


    A better test to determine if the form was submitted would be to test if your text input contains a value...


    if ($_POST['query'] != "") {
      echo "The form was submitted.";

  8. I was sure that all function scope was global.


    No, a function's scope is limited to where it was declared at.  If it is declared in the global namespace, then, yes, it is global.  However, if it is declared in a class, it it not global, but local to the class.


    If cakePHP is anything like Zend, and assuming you are using your posted code in a view script, then it is probably evaluated code inside the view class...try calling the function using the $this-> nomenclature....


    function a() {
        echo "a";
    function b() {


    The worst that will happen is nothing.

  9. You have to get the result of your query out of the "Resource" returned by the query...


    $INK = mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); 
    echo mysql_result($INK, 0);

  10. First off, that is the most headache inducing description I've ever read.


    Secondly, does $username change (it's pulled from a mysql table, determined from a POSTed value, etc)?  If not, why are you putting it in a variable to begin with?  I can only assume it is dynamic, in which case, it has to be a variable.


    Memory wise, yes, it will consume a few bytes more, but nothing worth even noting.

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