I think I have it all figured out now, so as promised, here is the
code. Thanks everyone for your suggestions.
$id_query = "select id from <table> WHERE id LIKE '$post_date%' ORDER
BY <id> DESC LIMIT 1 ";
$id_results = mysql_query($id_query,$conn);
$id_row = mysql_fetch_array($id_results);
$id_num_rows = mysql_num_rows($id_results);
if ($id_num_rows != "0")
{
$id_last = $id_row["id"];
$id_letter = ord(ltrim($id_last,"\0..9,-"));
$new_id = $post_date;
$new_id .= chr($id_letter+1);
}
else
{
$new_id = $post_date;
$new_id .= "a";
}
So, it calls the database, gets the last rows with this date as part
of the id (2006-05-08d), strips out the date part, adds one to the
letter and outputs back the next ID (2006-05-08e).
On Mar 8, 2006, at 8:39 AM, Kevin Murphy wrote:
Thanks for the info, but I think you are misunderstanding what I am
trying to do. I am simply trying to create a sequential ID based on
a Date and a Letter (or number, if I have to) field that will be
used as part of the link. After they are created, they will not
change. And Its not about how they appear on the page in the HTML
(I know how to make those be sequential in that way), I am more
concerned with the ID making them unique.
And yes, people do care about the way the link works. People, say
for example, like my bosses, whom I am trying to accommodate. :-)
And some SEO people will tell you that the link does indeed matter
when doing that kind of stuff.
I think I have figured it out using a combination of MAX and Limit
to check to see what the last one is and then write the next one.
Thanks all for your help. If I figure it out, I will post the code
for future reference.
On Mar 8, 2006, at 12:00 AM, Paul Novitski wrote:
At 05:05 PM 3/7/2006, Kevin Murphy wrote:
Well, part of the issue is that I want to be able to use this as
part
of the link:
/news.php?article=2006-03-05a
/news.php?article=2006-03-05b
With respect, I too think you should re-examine your reasons for
wanting to number (or letter) the links consecutively in the
database.
To whom does the spelling of an URL really matter? I believe that
website visitors rarely care; they care about how things are
labelled in the foreground and they want to get to the correct
page, but I don't think many people really study the details of
the address bar and even fewer make judgements about the quality
or completeness of website content on that basis.
There are in fact solid reasons for NOT changing URLs once they're
established -- for example, the persistence of bookmarks, links
from other websites, and search engine memory. Once you establish
an URL pointing to a particular page it's going to be recorded,
stored, and repeated by many other entities on the internet. If
you're whimsically changing URLs at random intervals, old URLs
will no longer point to the same content. You'll be doing your
own material a disservice by frustrating one of the most powerful
assets the internet can lend you: its persistence of vision.
I wonder if your desire for contiguously lettered URLs can be
satisfied by simply assigning consecutive letters to the display
text that links to the articles:
HTML:
<ol>
<li><a href="/news.php?article=9568367">Title of
article</a></li>
<li><a href="/news.php?article=1937452">Title of
article</a></li>
<li><a href="/news.php?article=4694832">Title of
article</a></li>
CSS:
ol
{
list-style-type: lower-alpha;
}
RESULT:
a. Title of article
b. Title of article
c. Title of article
As others have pointed out, the sequence in which the URLs spill
out from the database can be controlled by a timestamp in each
record. The lettering of the articles a-z can be controlled by
the ordered list for the benefit of the visitor. When an article
is inserted into or deleted from the list, the list retains its
contiguity IN THE PRESENTATION and you aren't put in the inelegant
position of trying to renumber records in a database.
Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php