Forum Moderators: coopster
$query = "SELECT * FROM mysteries ORDER by title ASC";
$result = mysql_query ($query); // Run the query.
while ($row = mysql_fetch_array($result)) {
$md_id = $row['book_id'];
$title = stripslashes($row['title']);
$author = stripslashes($row['author']);
Thankful for a suggestion.
For titles beginning with 'The', why not list them like this:
Philospher`s Stone, The
Goblet of Fire, The
As for stripping characters, easiest way to display them alphabetically, would be to create a field in your database to get the first letter when you process. This will make it easier when displaying your data. So, a char(1) field should do and when you add to your database do the following:
$booktitle = $_POST['booktitle'];
$actualtitle = $booktitle; //Make a Copy and insert this as the title
$booktitle = str_replace("An ", "", $booktitle);
$booktitle = str_replace("A ", "", $booktitle);
$booktitle = str_replace("The ", "", $booktitle);
//Then use substr to get the first character:
$character = substr($booktitle,0,1);
Insert this character into your new field and then you can order by this when you pull your data.
Think that should work ok.
dc
$title = $_POST['title'];
$title = str_replace("An ", "", $title);
$title = str_replace("A ", "", $title);
$title = str_replace("The ", "", $title);
$actualtitle = $title; //The title to INSERT
//Substr to get the first letter:
$first_letter = substr($title,0,1);
// Check for an author's last name.
$author = trim($_POST['author']);
if (empty($author)) {
$author = '';
}
if (isset($_POST['submit'])){
$query = "INSERT INTO trial (first_letter, actualtitle, author) VALUES ('$first_letter','$actualtitle','$author')";
// Run the query.
$result = @mysql_query ($query);
}
?>
It might be a case sensitive issue. Try juggling the code around:
$title = $_POST['title'];$actualtitle = $title; //The title to INSERT
$title = str_replace("an ", "", strtolower($title));
$title = str_replace("a ", "", strtolower($title));
$title = str_replace("the ", "", strtolower($title));//Substr to get the first letter:
$first_letter = substr($title,0,1);
I changed the case to lower case for string replace, then forced lower case on the data by using strtolower.
dc
// Declare a title.
$actualtitle = ($_POST['actualtitle']);
$title = ($_POST['title']);
$actualtitle = $title;
//:
$title = strtr("an ", "",($title));
$title = strtr("a ", "", ($title));
$title = strtr("the ", "",($title));
$query = "SELECT * FROM trial ORDER by first_letter ASC";
$result = mysql_query ($query); // Run the query.
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$first_letter = stripslashes($row['first_letter']);
$actualtitle = stripslashes($row['actualtitle']);
$author = stripslashes($row['author']);
$display_block .= "<p><strong>$actualtitle </strong><br />
$author
</p>";
}
$shortened_title = preg_replace("/^(the¦a¦an)\b\ */i", "", "Some title");
This is case-insensitive and will only look for the first word in the title (i.e. it will not remove a 'the' halfway through the title). You can also add new words to replace within the function, insert anything in the section
the¦a¦an