1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

100 % dynamic sitemap generator {php code}

Discussion in 'Google Sitemaps' started by samehzone, Jun 25, 2008.

  1. #1
    <?php
    mysql_connect("localhost", "DataBase-UserName", "database-password") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("DataBase-Name");//////////// <   
    ?>
    <?php
     $sql = "SELECT  * FROM thread";
     $result = mysql_query($sql) or die(mysql_error());
     header('Content-Type: application/xml');
     echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
     echo "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">";
     while($row = mysql_fetch_assoc($result)) {
     ?>
     <url>
     <loc>http://www.yoursite.com/?t=<?php echo $row['threadid']; ?></loc>
     <lastmod>2008-03-23T13:36:17+00:00</lastmod>
     <priority>0.50</priority>
     <changefreq>weekly</changefreq>
     </url>
     <?php } ?>
     </urlset>
    
    PHP:
    this code will generate XML sitemap directly from the database you just need to adjust the code according to your database and php script
    SEMrush
     $sql = "SELECT  * FROM thread";
    PHP:
    thread is the mysql taple

    <?php echo $row['threadid']; ?>
    PHP:
    threadid is the item id


    for help with modwrite feel free to ask me
     
    If someone posts a solution, use the "Best Answer" link in their post to pick it as the best answer.
    samehzone, Jun 25, 2008 IP
    SEMrush
  2. alexts

    alexts Well-Known Member

    Messages:
    1,126
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    Digital Goods:
    1
    #2
    Thanks for the code.
    Very useful to me.
     
    alexts, Jun 26, 2008 Set Best Answer IP
  3. alexts

    alexts Well-Known Member

    Messages:
    1,126
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    Digital Goods:
    1
    #3
    how to I save the output into separate xml file?
     
    alexts, Jun 26, 2008 Set Best Answer IP
  4. dreamcon

    dreamcon Peon

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I will definitly use this code for my directory....we have PHP based web directory so it will definitly help improve page rank of my website....

    Thank you so much for sharing this code with us...
     
    dreamcon, Jun 26, 2008 Set Best Answer IP
  5. samehzone

    samehzone Guest

    Best Answers:
    0
    #5
    google understand it as xml when u submit it to the webmaster tools
     
    samehzone, Jun 28, 2008 Set Best Answer IP
  6. alexts

    alexts Well-Known Member

    Messages:
    1,126
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    Digital Goods:
    1
    #6
    Thank you,It worked.
     
    alexts, Jun 28, 2008 Set Best Answer IP
  7. xfreex

    xfreex Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    mysql_fetch_assoc slower than mysql_fetch_object so you must use a object ;)
     
    xfreex, Jun 29, 2008 Set Best Answer IP
  8. samehzone

    samehzone Guest

    Best Answers:
    0
    #8

    will try it thank u
     
    samehzone, Jun 29, 2008 Set Best Answer IP
  9. anuradhan

    anuradhan Active Member

    Messages:
    372
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    #9
    good tutorial.
    btw, writing the same output in xml file will be a plus.
     
    anuradhan, Oct 23, 2011 Set Best Answer IP
  10. dakshinfo

    dakshinfo Peon

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    thanks for the code bro it is very useful! keep up the good work bro
     
    dakshinfo, Nov 29, 2011 Set Best Answer IP
  11. shibli123

    shibli123 Active Member

    Messages:
    325
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #11
    really handy information. thank you so much :) i must try this instead of using sitemap generator wp plugins..
     
  12. netboy78

    netboy78 Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #12
    hey.. thanks for sharing . This script is working for my site. i have result on sitemap like this: at php code <loc>http://www.mysite.com/search/<?php echo $row['tag']; ?>.html</loc> and i get full resul for tag like this:
    <loc>http://www.mysite.com/search/1/lost wold.html</loc>
    <loc>http://www.mysite.com/search/1/my new story.html.html</loc>

    my question now, how to make the result to auto add - before and after word if the result have more than 1 word? e.g lost wold can change to lost-wold.html, my new story can change to my-new-story.html?
    hope can help me ... ;)
     
    netboy78, Jul 10, 2013 Set Best Answer IP
  13. hilhilginger

    hilhilginger Active Member

    Messages:
    312
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #13
    I tried the code for one of my new site and it is not working.I suspect this code is not completed