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 ) ); // } ?> PHP:
It would be helpful to know what errors you are getting and what the config file contains if you want us to help solve it.
I am getting error on Line number 9 of logical_AND and then error on // Iterate over Result while( $row = mysql_fetch_array($result) ) PHP: my connection is statment is as follow define('DB_HOST', 'localhost'); define('DB_NAME', 'site'); define('DB_USER','site'); define('DB_PASSWORD','site'); $con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); $db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); PHP:
It would be easier if you just copied what the error says. You could try changing your query to: <?php $query = "SELECT seo_url, added FROM ". $table . " ORDER BY added DESC"; PHP: and make sure all the tables you are accessing have a seo_url and added column. Also consider using PDO (http://php.net/manual/en/book.pdo.php) as mysql functions are no longer recommended.