PDA

View Full Version : need php link help



tuxandpucks
31 Aug 2012, 06:14 PM
Hi everyone,

I am having trouble figuring out where my problem is with what I am trying to do. I am trying to let my users click on a letter of the alphabet (which I have listed) and when my users click on it, I want the next page to list all poems that start with what letter was clicked on. I know the if statement at the bottom of this post is wrong, I am not sure how to fix that - what type of operation to perform.

Thanks,
Randy

Example:
I click on letter “p”, and the next page shows:

P
Poem that starts with letter p
Poem that starts with letter p
Poem that starts with letter p
Poem that starts with letter p


So far I have the following code which prints out all the letters A-Z:


<?php
print date('F jS, Y');
echo "<h3>Browse By Letter</h3>";
?>

<div id="navletters">
<?php
foreach(range('A', 'Z') as $letter) {
echo "<a href=\"includes/poemsbyletter.inc.php?id= \">$letter</a><br>\n";
}
?>
</div><!--navletters-->


This is the code I am trying to use to list the poems. You can see that my SELECT query isn't complete as I am not too sure what to do with that:


<?php



$id = $_GET['id'];
$letter_id = $_GET['letter_id'];
$title = $_GET['title'];
$poem = $_GET['poem'];

$dbh = mysql_connect ($db_hostname, $db_username, $db_pass, $db_name) or die ('I am unable to connect to the database because of: ' . mysqli_error());

mysql_select_db("mydatabasename",$dbh);

$query = "SELECT * FROM `poems` WHERE letter_id ORDER BY `poems`.`letter_id` ASC LIMIT 0, 30 \n";

$result = mysql_query($query) or die(mysql_error());

if ($result == 0){
echo "<h3>Sorry, there are no poems beginning with the letter $letter_id</h3>\n";
}

echo "<br>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)/* or die('No records retrieved')*/)

{
if ($letter_id == $letter_id){
echo "letter_id";
}
}
echo "$letter_id";
echo "<br><br>";
echo "<a href=\"../index.php\" />Back To Home</a>\n";

?>