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
$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) . '-' .

            // 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>' .
        // Free MySQLi Result

    // 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 ) );
    // }


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.