0

While genrating sitemap using php and mysql i am tottaly stuck with the errors in this, my requirement was to gerante multiple files sitmaps with the sitemap index if urls are greater than 5000 but this code i followed from a site totaly stucks me with errors please help me in this regards will be thankful to you mycode is here

<?php // Table Names
include("config.php");
$buffer = array();
    $tables = array( 'tblusers', 'tblshares', 'tblreviews');
    $custom_pre = array( 'users/', 'shares/', 'reviews/');
    $pirorities = array( '0.8', '0.9', '1.0');


    // Iterate over $tables
    foreach($tables as $table and $custom_pre as $custom_pres and $pirorities as $piroritie)
    {
        // Build Query
        $query = "SELECT `seo_url`, `added` FROM $table" .
                 "ORDER BY added DESC";

        // Get Result
        $result = mysql_query( $query );

        // Iterate over Result
        while( $row = mysql_fetch_array($result) )
        {
            // Chop up the Date
            $date = substr($row['added'],0,4) . '-' .
                    substr($row['added'],5,2) . '-' .
                    substr($row['added'],8,2);

            // Add page details to $buffer
            $buffer[] = '<url>' .
                        '<loc>' . $site_baseurl . $custom_pres . $row['seo_url'] . '</loc>' .
                        '<lastmod>' . $date . '</lastmod>' .
                        '<changefreq>daily</changefreq>' .
                        '<priority>' . $piroritie . '</priority>' .
                        '</url>';
        }
        // Free MySQLi Result
        $result->close();
    }

    // Output the Buffer to view. Make sure it looks good.
    echo implode( "\r\n", $buffer );

    // Remove the echo above and uncomment below if it looks good.

    // if( ( $xml = fopen( 'sitemap.xml', "w" ) ) !== FALSE )
    // {
    //     fwrite( $xml, implode( "\r\n", $buffer ) );
    // }

?>
2
Contributors
1
Reply
20
Views
2 Years
Discussion Span
Last Post by Taywin
0

Line 13 & 14, you are building a query without giving a condition for it to search for. You need to look at how to compose a query for SQL (look at Select).

Line 20, you are retrieving the row as ARRAY. If you want to retrieve it to use as an ASSOC, you must pass the keyword to your mysql_fetch_array() to indicate that you will also access it as an associated array (i.e. hash).

Line 28, what are you trying to do here? Are you strying to initiate an array, or assigning string to one of array index?

Do you know PHP? Please do not simply copy & paste code/script from online...

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.