Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by PFMaBiSmAd

  1. We try to discourage people from using output_buffering on a page -

     

    1) It takes additional memory and processing time.

     

    2) If you are redirecting on a page, it will hide both php error messages and any messages your code outputs that would help you determine why your code on that page isn't doing what you expect.

     

    3) It doesn't work for one of the things that causes header errors, so suggesting it as a 'fix-all' doesn't always work.

     

    Also, by using output_buffering to hide the problems that cause header errors, your code ends up being more disorganized, so that you or the next person who must use that code or debug what it is doing, will have a harder time.

     

    It's always better to find and fix the root cause of a problem, then to mask the problem.

  2. The following takes ~ 2.3/2.4 seconds on my development system for 61000 rows made up of repeated blocks of the sample data you posted -

     

    <?php
    // database connection here...
    
    $filename = "zip.txt";
    $block_size = 10000; // how many lines of data per multi-query
    $lines = file($filename,FILE_IGNORE_NEW_LINES);
    
    function make_line($line){
       $f_office  = substr($line,0,4);
       $zip_code   = substr($line,4,5);
       $zip_plus   = substr($line,9,4);
       $city_name = substr($line,13,17);
       $state_code    = substr($line,30,2);
       $county_code   = substr($line,32,3);
       $county_name   = substr($line,35,15);
       $l_option = substr($line,50,1);
       return "('$f_office','$zip_code','$zip_plus','$city_name','$state_code','$county_code','$county_name','$l_option')";
    }
    
    $lines = array_map('make_line',$lines);
    $lines = array_chunk($lines ,$block_size);
    $i = 1;
    $start = microtime(true);
    foreach($lines as $chunk){
       $query = "INSERT INTO zipdb (f_office,zip_code,zip_plus,city_name,state_code,county_code,county_name,l_option) VALUES " . implode(',',$chunk);
       // run query here...
       $result = $mysqli->query($query);
       echo "$i - ".count($chunk)." - ".strlen($query)." - ";
       var_dump($result);
       echo "<br />";
       $i++;
    
    }
    $end = microtime(true);
    $diff = number_format($end - $start,2);
    echo "Done, in $diff seconds.";
    

     

    Some of your speed issues might be due to using PDO, because of what it does to make it general purpose, isn't going to result in the fastest execution.

     

    Also, using a prepared query for a repeated simple query like this doesn't help much (5%-10% time savings) because you must still transfer the data that goes into each query to the database server, which takes significantly longer than it takes the server to run the actual query.

  3. Your links and redirect statements are changing the www. vs no-www. in the URL and the session id cookie doesn't match all variations of your domain name.

     

    A) You need to be consistent in using a www. or no-www. on your domain name,

     

    B) You need to redirect any request that doesn't have the www. on it to the same url with the www. on it (or visa-versa.)

     

    C) You need to set the session cookie id domain setting so that it matches all variations of your domain name. See the 'domain' parameter at this link - http://us1.php.net/session_set_cookie_params

  4. I would do the following (since you can read the whole file into an array using file)-

     

    1) Write a function that takes a (one) line and converts it to the data string that would go in the VALUES (....) portion of the query statement.

     

    2) Use array_map to apply the function from item #1 to the array of lines, replacing the same array of lines so as to not consume more memory then needed.

     

    3) Use array_chunk to split the array of lines into an array of arrays of lines (5k-10k in size for each chunk), replacing the same array of lines so as to not consume more memory then needed.

     

    4) Iterate over the resulting array of chunks and implode each sub-array to make and execute a multi-value insert query from that sub-array.

     

    Only one loop will be used and let php's array functions do most of the work.

  5. And once you have a query that does what you want, here's example code (untested) that will produce the output you are trying to make -

     

    edit - modified the 'tab' code to detect when the gallery changes -

    $tab_content = '';
    $gallery_content = '';
    
    $last_gallery = null;
    
    $query = "single query that gets the joined information you want in the order that you want it";
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)){
    // category/tab values
    $catid = $row['category_id'];
    $category_name = $row['category_name'];
    
    // gallery values
    $photo_caption = $row['photo_caption'];
    $photo_filename = $row['photo_filename'];
    
    // build tab content
    if($last_gallery != $catid){
    $tab_content .= "<li><a href='#' rel='view{$catid}'>$category_name</a></li>";
    $last_gallery = $catid;
    }
    
    // build gallery content
    $gallery_content .= "<div id='view{$catid}' class='tabcontent'>";
    $gallery_content .= "$photo_caption</br>";
    $gallery_content .= "<img src='{$images_dir}/tb_{$photo_filename}' border='0'>";
    $gallery_content .= "</div>";
    }
    
    
    // output the HTML document -
    ?>
    <ul class="tabs">
    <?php echo $tab_content; ?>
    </ul>
    
    <div class="tabcontents">
    <?php echo $gallery_content; ?>
    </div>

  6. $tournament_row = mysql_fetch_assoc($tournament_result);

     

    The first row from each set of data is missing. You are fetching the first row using the above line of code.

     

    You need to do a couple of things -

     

    1) Don't put a query inside of a loop. You need to execute ONE query that gets the rows you want in the order that you want them. Then you simply output the data the way you want it when you iterate over the rows.

     

    2) To output the heading, you simply remember the last heading (initialize to a value that won't ever appear in the data, such as a null) and detect when it changes to output the new heading, then save the new heading value as the last heading.

  7. Your post doesn't contain enough relevant or actual information to help you. In fact your database table names don't match what the code is using, so the posted code cannot be producing any output (yes it matters if you post actual information or altered/paraphrased/off-the-top-of-your-head information.) If you find yourself bumping a thread, but you are not adding any information or clarifying the problem in those bumps, you might as well not bump the thread.

     

    It's likely that the tabbed gallery javascript code expects the content <div>'s to all be output when the page is requested and they are just reveled when the corresponding tab is clicked.

     

    If on the other hand, you expect to click on the link in a tab and request the correct gallery, you would need to write your code so that when $_GET['catid'] is set that you output the correct <div></div> contents for just the requested gallery.

     

    Clarification is needed on what you are actually trying to produce as output on the page.

  8. All the errors you are getting are follow-on errors because something your code is doing in a previous step failed and you don't have the expected result. You need error checking (check if something worked or not), error reporting/logging (output a user message and log all actual error information), and error recovery logic (don't blindly execute following code that is dependent on a result that doesn't exist) in your code.

  9. The following is the SELECT query syntax definition. When an element is present, it must be in the order shown. The most commonly used parts highlighted in red -

     

    SELECT

    [ALL | DISTINCT | DISTINCTROW ]

    [HIGH_PRIORITY]

    [sTRAIGHT_JOIN]

    [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT]

    [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS]

    select_expr [, select_expr ...]

    [FROM table_references

    [WHERE where_condition]

    [GROUP BY {col_name | expr | position}

    [ASC | DESC], ... [WITH ROLLUP]]

    [HAVING where_condition]

    [ORDER BY {col_name | expr | position}

    [ASC | DESC], ...]

    [LIMIT {[offset,] row_count | row_count OFFSET offset}]

    [PROCEDURE procedure_name(argument_list)]

    [iNTO OUTFILE 'file_name'

    [CHARACTER SET charset_name]

    export_options

    | INTO DUMPFILE 'file_name'

    | INTO var_name [, var_name]]

    [FOR UPDATE | LOCK IN SHARE MODE]]

  10. Since you didn't provide any of the requested and actual information that we would need to help you, I'm going to guess that the code you posted isn't the actual and complete code that is producing the incorrect results, since it would be impossible for that code to output what you state.

  11. You would replace your existing mail statement with the code needed to use one of the smtp mailer classes.

     

    You would need to include the file containing the class definition, create an instance of that class, then setup the parameters it needs for smtp authentication and supply it with the to/from/subject/message data from your existing code.

     

    I would recommend starting with one of the smtp authentication examples from the documentation for the class you choose and get that working first before you try to integrate it into your existing script.

  12. Your error messages refer to mysql_ (without the i) statements. That's not what you posted for the code in init.php. You either have more than one file named init.php and the wrong one is being included (due to the actual path where it is at) or the actual file isn't the one you have posted the code for.

     

    All your mysqli_ statements must be the same 'flavor', with the i

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