Hi Laurie,
If the data to be displayed was in a database, and each row of data
corresponded to an auto incrementing id, you could reference by id number,
which is a much better way of doing things via the GET method than messing
around with long names. Assuming that you have two tables, one that
contains the categories (with its own unique id, adn one which contains the
elements of each category):
table categories:
id category
1 Apples
2 Pears
3 Oranges
table contents:
id cat_id name contents
1 1 Green apples etc etc
2 1 Red Apples etc etc
3 1 Exotic apples etc
Then the contents page:
<?
$connection = //Connection details.
$get_categories = @mysql_query("SELECT * FROM categories ORDER BY category
DESC", $connection)
or die (mysql_error());
while($row = mysql_fetch_array($get_categories)) {
$id = $row['id'];
$category = $row['category'];
echo "<a href=\"category.php?id=" . $id . "\">" .
stripslashes(htmlentities($category)) . "</a>";
}
?>
The category page, where all the fruits are held:
<?
$connection = //Connection details.
$get_contents = @mysql_query("SELECT * FROM contents WHERE cat_id = '$id'
ORDER BY name DESC", $connection)
or die (mysql_error());
while($row = mysql_fetch_array($get_contents)) {
$id = $row['id'];
$name = $row['name'];
$contents = $row['contents'];
echo stripslashes(htmlentities($name)) . "<BR><BR>";
echo stripslashes(htmlentities($contents));
}
?>
Or you could combine the both:
<?
$connection = //Connection details.
$get_categories = @mysql_query("SELECT * FROM categories ORDER BY category
DESC", $connection)
or die (mysql_error());
while($row = mysql_fetch_array($get_categories)) {
$id = $row['id'];
$category = $row['category'];
echo "<a href=\"category.php?id=" . $id . "\">" .
stripslashes(htmlentities($category)) . "</a>";
echo "<UL>";
$get_contents = @mysql_query("SELECT * FROM contents WHERE cat_id =
'$id' ORDER BY name DESC", $connection)
or die (mysql_error());
while($row = mysql_fetch_array($get_contents)) {
$name = $row['name'];
$contents = $row['contents'];
echo "<LI>" . stripslashes(htmlentities($name)) . "<BR><BR>";
echo "<LI>" . stripslashes(htmlentities($contents));
}
echo "</UL>";
}
?>
The last example would give you something like:
Apples:
Green apples
Green apples are greener than green.
Red Apples
Red apples are redder than red.
Exotic apples
Are,.... Exotic.
Pears:
Etc
Of course, that won't look too pretty, but I leave the layout to you. Have
a play, see how you get on :)
James.
""Laurie Landry"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I understand how to use a dropdown box to make your selection in which
that
> selection is the criteria to display a database content; but I was
wondering
> how I can achieve a query by link.
>
> For example, if you went to index.html file where there is a php coding
that
> generates the categories available (arrays) and outputs:
>
> <a href="showdata.php">Apples</a>
> <a href="showdata.php">Oranges</a>
> <a href="showdata.php">Bananas</a>
>
> If you click on apples, it will send a query to the database to show all
> listings under the category "apples". (SELECT category FROM FRUITS WHERE
> category=apples)
>
> how would I add the query criteria to the link? and how would I set up
> showdata to take the information from the selected link?
>
> thanks in advance,
>
> Laurie M. Landry
> <lmlweb> Design & Development
>
> www.lmlweb.com
> [EMAIL PROTECTED]
>
> T: (604) 872-6915
> F: (425) 732-1547
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]