Hi all, I'm new to php and just wanted to know a few things about it. Can I create a database (mysql) which could update a sitemap page (php) with a link to each new page i would create on the website? How can i go about having multiple id's from a table in the database update the sitemap page?
Hey Goppss, The short answer is yes. The long answer is that doing that will take several steps as you'd have to recognize a newly created page; store the links on your DB; update your DB on demand or dynamically; then write your results out to your sitemap page etc. Programmatically speaking, the answer to your second question may be as simple as writing your script to "loop" your database (ie: a "While" loop). I'm curious to know why you'd want to do this anyway? Are you just trying to create a static html or php sitemap page for better indexing? There are tons of scripts that already do that. Did you try checking HotScripts dot com? In addition, you may get more in-depth answers by also using the forum at Tek-Tips dot com. Hope this helps.
Hi Goppss, Is your site going to be database driven i.e. are all the pages/articles going to be stored in the db? If so it'd be fairly straightforward to create a dynamic sitemap page that is always up to date whenever a new page is added. If you're creating the pages in HTML (or other) then your database somehow needs to have the information fed into it before it will be able to update the sitemap. Brett
elchulo You're quite correct as to what I'm up to. I'm trying to avoid having dynamic links in preference for static links. It all in an effort to maintain good indexing by the bots as you realized. With the little knowledge I have after now reading up on PHP/MYSQL for the past couple of days I have decided to create php pages which will be updated by a database which itself will be updated possibly by a form. The database will also update the sitemap page which carries link to all pages. The sitemap link will look like: __________________________________________ Title text which carries link to the page written by: | date created Some text on the topic will be placed here __________________________________________ The problem I have is that I don't know how to write the script. I have been using a loop as you mentioned but it has been pulling only one ID from the database throughout the loop which runs for 20 instances. here is the code for that: <?php $counter = 2; while ( $counter <= 1048576 ) { echo "<div class=''><div class='bytitle'>"; echo $menuDisplay; echo "</div>"; echo "<div class='byline'><span class='byline1'>"; echo "written by:"; echo "</span>"; echo " | "; echo "<span class='byline2'>"; echo $lastmodified; echo "</span></div>"; echo "<div class='byphrase'>"; echo $bycomment; echo "</div></div>"; $counter = $counter * 2; } ?> Any further info will be appreciated. I will take a look at those sites you mentioned. Bret Thanks also for comments, you have also realized what i'm up to.
Following on from above. Can anyone help as to how i can pull ids 1 through 20 to show on the sitemap page? I have been working with the following but it only pulls on id=2 Any suggested tweaks? <?php require_once "../mysql/connect_to_mysql.php"; $pageid = '2'; //------------------------------------------------------------------------------------------- $sqlCommand = "SELECT * FROM archive WHERE id='$pageid' "; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); while ($row = mysqli_fetch_array($query)) { $bycomment = $row["byphrase"]; } mysqli_free_result($query); //------------------------------------------------------------------------------------------- $sqlCommand = "SELECT * FROM archive WHERE id='$pageid' "; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); while ($row = mysqli_fetch_array($query)) { $lastmodified = $row["lastmodified"]; } mysqli_free_result($query); //------------------------------------------------------------------------------------------- $sqlCommand = "SELECT * FROM archive WHERE id='$pageid' "; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); while ($row = mysqli_fetch_array($query)) { $writtenby = $row["writtenby"]; } mysqli_free_result($query); //------------------------------------------------------------------------------------------- $sqlCommand = "SELECT linkurl, linklabel FROM archive WHERE id='$pageid' ORDER BY id DESC "; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); $menuDisplay = ''; while ($row = mysqli_fetch_array($query)) { $linkurl = $row["linkurl"]; $linklabel = $row["linklabel"]; $menuDisplay .= '<a href="../' . $linkurl . '">' . $linklabel . '</a>'; } mysqli_free_result($query); //------------------------------------------------------------------------------------------- //mysqli_close($myConnection); ?>
I suspect i might have to use an array to pull multiple ids from the database which would carry the link and link text. Can someone show me what the expression of the array would look like?
Your code can be optimized like this one: $sql = ' SELECT linkurl, linklabel FROM archive WHERE id BETWEEN 1 AND 20 ORDER BY id DESC '; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); $menuDisplay = ''; while ($row = mysqli_fetch_array($query)) { $menuDisplay .= '<a href="../' . $row['linkurl'] . '">' . $row['linklabel'] . '</a><br />'; } mysqli_free_result($query); mysqli_close($myConnection); echo $menuDisplay; Code (markup):
Thanks for the comment drctaccess, the code has helped. I am still having a problem as in how to get the links 1 through 20 to fill each iteration incrementally, without each iteration having all 20 links. Can anyone help? <?php $counter = 2; while ( $counter <= 1048576 ) { echo "<div class=''><div class='bytitle'>"; echo $menuDisplay; echo "</div>"; echo "<div class='byline'><span class='byline1'>"; echo "written by:"; echo "</span>"; echo " | "; echo "<span class='byline2'>"; echo $lastmodified; echo "</span></div>"; echo "<div class='byphrase'>"; echo $bycomment; echo "</div></div>"; $counter = $counter * 2; } ?> Code (markup): $sql = ' SELECT linkurl, linklabel FROM archive WHERE id BETWEEN 1 AND 20 ORDER BY id DESC '; $query = mysqli_query($myConnection, $sql) or die (mysqli_error($myConnection)); $menuDisplay = ''; while ($row = mysqli_fetch_array($query)) { $menuDisplay .= '<a href="../' . $row['linkurl'] . '">' . $row['linklabel'] . '</a><br />'; } mysqli_free_result($query); mysqli_close($myConnection); echo $menuDisplay; Code (markup):
db structure: id pagetitle linklabel byphrase linkurl writtenby lastmodified 1 text text text link text date 2 " " " " " " 3 4 Code (markup): sitemap page structure: __________________________________________ Title text which carries link to the page written by: | date created Some text on the topic will be placed here __________________________________________ Title text which carries link to the page written by: | date created Some text on the topic will be placed here __________________________________________ Title text which carries link to the page written by: | date created Some text on the topic will be placed here __________________________________________ etc, etc Code (markup):