|
Posted by Rik on 02/21/07 01:43
On Wed, 21 Feb 2007 02:20:49 +0100, <fishmonger1972@gmail.com> wrote:
> Hi!
> I'm a librarian with a little PHP knowledge.. I'm trying to make a
> catalog from scratch for my library. I don't like the look of the
> current catalog so I'm trying to make a custom PHP/MySQL
> implementation.
>
> I can do everything I need to do except, I don't completely understand=
> a detail. Ideally I could write this:
>
> <a href=3D"catalogrecord.php?recordnum=3D4">Tom Sawyer</a>
>
> The idea would be to pass the number 4 to the catalogrecord.php page
> when the hyperlink is clicked. Then it would know which number in the=
> catalog it should pull up and display on the next page. Is this
> possible? And if so, how could I access the recordnum=3D4 on the next
> php file?
The question is a bit vague, but to get you started:
You say MySQL, so I assume that number 4 is an index in the database whe=
re =
the records are stored? A list of links could be made by:
<?php
mysql_connect('hostname','username','password');//of you mysql db
mysql_select_db('catalogue');
$books =3D mysql_query('SELECT `id`, `name` FROM `book`');
while($book =3D mysql_fetch_assoc($books)){
print '<a =
href=3D"catalogrecord.php?recordnum=3D'.$book['id'].'">'.$book['name'].'=
</a><br>';
}
?>
And the receiving script would do something like this:
<?php
$book_id =3D intval($_GET['recordnum']);
mysql_connect('hostname','username','password');//of you mysql db
mysql_select_db('catalogue');
$bookresult =3D mysql_query('SELECT * FROM `book` WHERE `id` =3D '.$book=
_id);
if(mysql_num_rows($bookresult) > 0){
$book =3D mysql_fetch_assoc($bookresult);
foreach($book as $key =3D> $value){
print $key.':'.$value.'<br>';
}
} else {
echo 'Book not found in database.';
}
?>
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|