PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have an 'items for sale' mysql database of categories (garden, outdoors, automotive, etc.) and their status (sold or selling) thats loads dynamic text links for each active category. My problem is querying the database, when a unique category is selected (or clicked on), I want to generate a page where categories = 'selection' and status = 'selling.' So it would list all of the items in the database.
Here is an example of what I have so far, however, they arent linked to anything, Im having problems generating a page from this point. Here is a link to the page:
http://www.onestopauctionshop.net/preview/ddtest.php
And here is the code:
==================================
Ok, so I should create a php page that will query the database, based on the data passed through the url. Right? What would the category.php page look like?
get category from url
loop/query the database where * = 'category'
Using the info for from my above script, what someone quickly write out what the script should look like. I am having trouble tring to find a get/post tutorial. Please help!
<?php
//make sure the var in the url is iset
if (!empty($_GET["catagory"])) {
//get all the items from the select catagory
$result = mysql_query("SELECT FROM `items` WHERE catagory='"$_GET["catagory"]."'") or die("mysql error: ". mysql_error());
//check if there are any items in the catagory
if (mysql_num_rows($result) == 0)
{
echo "No items found in this catagory";
}
//if there are items, display them
else
{
//show your items here
}
//if the var was not set means there is an error, or the user access this file directly
}
else
{
echo "You cannot directly access this page.";
}
?>
<?phpmysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM bookmark WHERE status='selling'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$category=mysql_result($result,$i,"category");
echo "<a href='http://onestopauctionshop.com/spinco/category.php?category='>$category</a> | ";
++$i;
}
?>
Right now the problem is that it is not it is not posting the url correctly. When it loads "category.php" the url does not contain the category. So I know that this is the first problem I have to deal with. Try clicking on a category from the above link http://www.onestopauctionshop.net/spinco/ddtest.php and lets solve the url problem. This is my first adventure into custom programming, and I have purchased at least 4 books and refrenced them in detail, so I appreciate your help on this.