Dynadot โ€” .com Registration $8.99

MySQL question

Spaceship Spaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
Hey. I have yet another problem with MySQL. Basically, I have a website about poems and users can submit their own which then go into the database. However, I have a page which displays the title and the author but I want the title to be a link to the poem. How can I do this? Help is, like always, much apreciated

Here is the code I have

PHP:
$result = mysql_query( "SELECT id, title, author, date FROM poems" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
echo "There are $num_rows poems.<P>";
echo "<table width=200 border=0>\n";
while ($get_info = mysql_fetch_row($result)){
echo "<tr>\n";
foreach ($get_info as $field)
echo "\t<td><font face=arial size=1/>$field</font></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
HTML:
<a href="view_poem.php?poem_id=<?php echo($id) ?>"><?php echo($field) ?></a>

Change the filename to whatever your poem view file is, and any other variables that you need... like the ID.
 
0
•••
Thanks very much for the response. What will the poem view file be?
 
0
•••
I dunno. You have to make it & name it whatever... then make sure the a href goes to that file.
 
0
•••
Sorry, i'm a bit confused. Where do I put

HTML:
<a href="view_poem.php?poem_id=<?php echo($id) ?>"><?php echo($field) ?></a>
 
0
•••
PHP:
$result = mysql_query( "SELECT id, title, author, date FROM poems" ) 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
echo "There are $num_rows poems.<P>"; 
echo "<table width=200 border=0>\n"; 
while ($get_info = mysql_fetch_row($result)){ 
echo "<tr>\n"; 
foreach ($get_info as $field) 
echo "\t<td><font face=arial size=1/><a href=\"view_poem.php?poem_id=$id\">$field</a></font></td>\n"; 
echo "</tr>\n"; 
} 
echo "</table>\n";
 
0
•••
Thanks but how can I have just the title as a link. Thanks
 
0
•••
I'm not too familiar with retrieving DB query results with that method of mysql_fetch_row but I think I know how it works...

ATM, what does that link display as? Have you tried it?
 
0
•••
Well I have the data displayed in the following format:

ID title author date

However, I want just the title to be a link to the actual poem. The previous code made each piece of data a link :|
 
0
•••
Is there an actual page where we can see it?
 
0
•••
Sure, sorry. But first, I've found some kind of fix but has brought me to a new problem. Click here.

It's repeating the first poem 16 times. Here's the code

PHP:
$result = mysql_query( "SELECT id, title, author, date FROM poems" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
echo "There are $num_rows poems.<P>";

$id=mysql_result($result,0,"id");
$title=mysql_result($result,0,"title");
$author=mysql_result($result,0,"author");
$date=mysql_result($result,0,"date");

while ($get_info = mysql_fetch_row($result)){
foreach ($get_info as $field)
echo "<a href=\"view_poem.php?poem_id=$id\">$title</a> by $author<br>";
}
 
0
•••
Not too familiar with mysql_fetch_row either, but wouldn't this work :? And CompuXP feel free to correct me, I know you want to :p Lol. j/k but yea..
PHP:
$result = mysql_query( "SELECT id, title, author, date FROM poems" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
echo "There are $num_rows poems.<P>";
echo "<table width=200 border=0>\n";
while ($get_info = mysql_fetch_row($result)){
echo "<tr>\n";

$id = $get_info['id'];
$title = $get_info['title'];
$author = $get_info['author'];
$date = $get_info['date'];

echo "\t<td><font face=arial size=1/><a href=\"view_poem.php?poem_id=$id\">$title</a><br>$author<br>$date</font></td>\n";

echo "</tr>\n";
}
echo "</table>\n";
 
Last edited:
0
•••
Thanks but it only returned the "There are 5 poems" bit
 
0
•••
wait a sec..Lol

Ok... why not try something like this:

PHP:
$result = mysql_query( "SELECT id, title, author, date FROM poems" ) or die("SELECT Error: " .mysql_error());
$num_rows = mysql_num_rows($result);
echo "There are $num_rows poems.<P>";
echo "<table width=200 border=0>\n";

$q = mysql_query("SELECT * FROM poems") or die("SELECT Error: " .mysql_error());

while ($row = mysql_fetch_array($q))
{
echo "<tr>\n";
$id = $row['id'];
$title = $row['title'];
$author = $row['author'];
$date = $row['date'];

echo "\t<td><font face=arial size=1/><a href=\"view_poem.php?poem_id=$id\">$title</a><br>$author<br>$date</font></td>\n";

echo "</tr>\n";
}
echo "</table>\n";
 
0
•••
It works! Thanks a lot, man!
 
0
•••
No problem :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back