MySQL question

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Thanks very much for the response. What will the poem view file be?
 
0
Close
I dunno. You have to make it & name it whatever... then make sure the a href goes to that file.
 
0
Close
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
Close
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
Close
Thanks but how can I have just the title as a link. Thanks
 
0
Close
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
Close
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
Close
Is there an actual page where we can see it?
 
0
Close
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
Close
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
Close
Thanks but it only returned the "There are 5 poems" bit
 
0
Close
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
Close
It works! Thanks a lot, man!
 
0
Close
No problem :)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back