Jump to content

Fetch Categories with Get method


eugene2009

Recommended Posts

Lets start with this code..

 

CREATE TABLE category(
category_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
parent INT DEFAULT NULL);

INSERT INTO category
VALUES(1,'ELECTRONICS',NULL),(2,'TELEVISIONS',1),(3,'TUBE',2),
(4,'LCD',2),(5,'PLASMA',2),(6,'PORTABLE ELECTRONICS',1),
(7,'MP3 PLAYERS',6),(8,'FLASH',7),
(9,'CD PLAYERS',6),(10,'2 WAY RADIOS',6);

SELECT * FROM category ORDER BY category_id;

 

So look.. i create this table.. but how do I actually create more inputs for items under that category for prices, and other information.. How will I be able to have a page named categories.php and have it list only the categories linked with the get method going to the products in each category.. somebody please help..

 

Link to comment
Share on other sites

i know how to connect to the database.. i got this..

 

$query = "SELECT * FROM comments ORDER BY tutorialid"; //get the customer list
$result = mysql_query($query); //perform the query

//display the customer list
$array = array();
while($row = mysql_fetch_array($result)){
     $array[] = $row;
}
$midPoint = ceil(count($array) / 2);
echo "<table border=\"1\">";
for($i = 0; $i < $midPoint; $i++){



echo "<tr>";

echo '<td><a href="category.php?tutorialid='.$array[$i]['tutorialid'].'">'.$array[$i]['tutorialid'].'</a>';

echo "</td>";


if (isset($array[$i + $midPoint]))


echo '<td><a href="category.php?tutorialid='.$array[$i+$midPoint]['tutorialid'].'">'.$array[$i+$midPoint]['tutorialid'].'</a></td';

echo "</td>";

echo "</tr>";
}

 

My problem is it displays the same category over and over.. i want it to display it only once.. thats where im stuck at..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.