Webshop stuck

Hi guys,

I’ve created with the help of kirupa’s forum small web shop.
I can let the php show the products in a grid, i can let show php every product but i can’t let php show me the groups and subgroups.

First i will explain how the database is set up:
The database “products” has a table “articles”.
In this table i have about 10 fields but the most important fields are like in the example
[LIST]
[]id (0001)
[
]maingroup (phones, accessoires, gadgets)
[]group (mobilephones, phones, wired phones)
[
]subgroup (smartphone, pocketphone)
[]brand (nokia, lg, samsung)
[
]type (E50, E65)
[/LIST]
I have an index page. On this page i will hardcode 3 links to the maingroups (phones, accessoires and gadgets)

[COLOR=Navy] When i click on the link “phones” i would like to view al of the groups that are under the maingroup “phones”.[/COLOR]
[LIST]
[][COLOR=Navy]mobilephones[/COLOR]
[
][COLOR=Navy]phones[/COLOR]
[][COLOR=Navy]wired phones[/COLOR]
[/LIST]
[COLOR=Navy]When i click on “mobilephones” i would like to see a list like[/COLOR]
[LIST]
[
][COLOR=Navy]smartphone[/COLOR]
[*][COLOR=Navy]pocketphone[/COLOR]
[/LIST]
And when i click on “smartphone” then i go to the grid “subprod.php?detail=smartphone” with al the smartphones, this grid i have.

The problem i have is the stuff in blue, its only this step that i’m missing. It’s a kind complicated i think but i did my best to explain it as good as possible

Probably it makes sense but i don’ get it :slight_smile:
I googled a bit and the distinct functions grabs the unique values in a column?

Maybe its easy to show the current structure of my site.

I first have my homepage.php with the 3 maingroups (phones,accessories,gadgets), this is a hardcoded page. This page i would like to generate automatically.


<a href="maingroup.php?detail=phones">Phone</a><br>
<a href="maingroup.php?detail=Accessories">Accessories</a><br>
<a href="maingroup.php?detail=Gadgets">Gadgets</a>

When the person clicks on “Phones” (maingroup.php?detail=phones) he comes to a hardcoded page (maingroup.php) with 2 links. This page i would like to generate automatically.


<a href="group.php?detail=mobile">mobile</a><br>
<a href="group.php?detail=fixed">fixed</a><br>

When the person clicks on “mobile” (subgroup.php?detail=mobile) he comes to a hardcoded page (subgroup.php) with 2 links. This page i would like to generate automatically.


<a href="subgroup.php?detail=Slidephone">Slidephone</a><br>
<a href="subgroup.php?detail=Candybar">Candybar</a><br>

When the person clicks on “Slidephone” he go’s to subgroup.php?detail=Slidephone. On this page he see’s a page with thumbnailss


<?php
$select = $_GET['detail'];
$dbserver = "localhost";
$user = "**********"; 
$passwd = "**************";
$dbnaam = "********_products";
$query = "SELECT * ";
$query = $query . "    FROM article";
$query = $query . "    WHERE brand = '$select'";
$link = mysql_connect($dbserver, $user, $passwd) or die("No connection");
$db = mysql_select_db($dbnaam,$link) or die("No connection"); 
?>
<table><tr><td><table><tr><td>          
<?php
if ($result=mysql_query($query)){
for ($ie=0; $ie < 1; $ie++);
{ $rij= mysql_fetch_array($result);
}}
//create table
if ($result=mysql_query($query)) {
print("
<table border='0'><tr>");
for ($i=0 ; $i < mysql_num_rows ($result) ; $i++) {
if ($teller <= 3) {
$rij= mysql_fetch_array($result);
print("<td width='130'><table><tr><td><a href='article.php?detail=$row[id]'>$row[brand] $row[type]</a>
</td></tr><tr><td></a></td></tr></table>        
</td>");
$teller++;
} else {
$teller = 0;
$i = $i -1;
print("</tr><tr>");
}
}
print("</tr></table>");
}
?>
</td></tr></table></td></tr></table>
<?php
mysql_close($link) or die("Can't close");
?>

When a person clicks on one of the thumbnails he go’s to the productpage that also i generated from the database. This works al fine.

Only to create the groups and subgroups I can’t get it working.

Thanks for the helping hand…

Hi ahmednuaman,

What do I have to place in the SQL Distinctive and php so automatically my groups appear?

Greetz

Why do you make the endif?

Hello,

I tried to follow your code, only the expression &&! is unknown for me?
As I suppose this is && (and) and ! (not) so this is “and not” ???

Sorry that i’m not a easy learner :slight_smile: , my shop is running perfect only these pages to select are difficult

<?php
$dbserver = "localhost";
$user = "**********"; 
$passwd = "**************";
$dbnaam = "********_products";
$var_maingroup = $_GET['cat1'];
$var_group = $_GET['cat2'];
$var_subgroup = $_GET['cat3'];
$link = mysql_connect($dbserver, $user, $passwd) or die("no connection");
$db = mysql_select_db($dbnaam,$link) or die("no connection"); 
// determine which query to use
if ($var_maingroup &&! $var_group &&! $var_subgroup) {
        $query = mysql_query("SELECT DISTINCT(group)");
} elseif ($var_maingroup && $var_group &&! $var_subgroup) {
        if ($var_maingroup &&! $var_group &&! $var_subgroup) {
                $query = mysql_query("SELECT DISTINCT(subgroup)");
        } elseif ($var_maingroup &&! $var_group && $var_subgroup) {
                        $query = mysql_query("SELECT DISTINCT(maingroup)");
        }
}
// check for results
if (mysql_num_rows($query) > 0) {
        // run loop
        while (($row = mysql_fetch_object($query)) !== false) {
                // write the links
                echo '<a href="page.php?">Link</a>';
        }
}
mysql_close($link) or die("cant close");
?>

Owke,

That didn’t worked, no connection with db it says. Where do i have to connect in this script? Could it be possible to help create this script for me? Because with the && !stuff i don’t follow and screwing my complete script.

:thumb2: I certainly do so but the problem is that only this page is the problem, for the rest my little online shop works great so could you be so kind to help me with a little look :look:

i recommend that you take a look at tree structures. Here is something I found.

Hi guys,

Thanks for the replys. I know that it is not good that you guys make this page and i don’t learn a thing but the problem is that i’m stuck on this page and don’t see a way out.

Ok, I tried something http://www.e-meel.be/test/

I create the page.php and getting some weird output http://www.e-meel.be/test/page.php?maingroup=gadget&group=&subgroup=

This is the page.php

Because i don’t know how to check multiple items i first tried to check one by one

<?php
$maingroup = $_GET['maingroup'];
$group = $_GET['group'];
$subgroup = $_GET['subgroup'];
$dbserver = "localhost";
$user = "****"; 
$passwd = "****";
$dbnaam = "e-meel_be_producten";
$link = mysql_connect($dbserver, $user, $passwd) or die("No connection");
$db = mysql_select_db($dbnaam,$link) or die("No connection"); 
// test query maingroup

if ($maingroup && !$group && !$subgroup) {
    $query = mysql_query("SELECT maingroup FROM products");
    // check for results
    if (mysql_num_rows($query) > 0) {
        // run loop
        while (($row = mysql_fetch_object($query)) !== false) {
        // write the links
        echo '$row[$maingroup]';
        }
    }
    //done checking
}
mysql_close($link) or die("Can't close");
?> 

This is my table

CREATE TABLE `products` (
  `id` int(99) NOT NULL auto_increment,
  `maingroup` varchar(99) NOT NULL default '',
  `group` varchar(99) NOT NULL default '',
  `subgroup` varchar(99) NOT NULL default '',
  `merk` varchar(99) NOT NULL default '',
  `type` varchar(99) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

INSERT INTO `products` (`id`, `maingroup`, `group`, `subgroup`, `merk`, `type`) VALUES 
(1, 'phone', 'mobile', 'slidephone', 'nokia', '2'),
(2, 'phone', 'mobile', 'pocket', 'nokia', '123'),
(3, 'phone', 'mobile', 'slidephone', 'nokia', '3'),
(4, 'phone', 'mobile', 'slidephone', 'nokia', '4'),
(5, 'gadget', 'fixed', 'voip', 'voipnokia', '2'),
(6, 'gadget', 'fixed', 'voip', 'nokivoip', '123'),
(7, 'phone', 'mobile', 'candybar', 'nokiaca', '2'),
(8, 'phone', 'mobile', 'candybar', 'nokiaca', '123'),
(9, 'gadget', 'toy', 'lol', 'tollo', '2'),
(10, 'gadget', 'truck', 'car', 'aa', '123'),
(11, 'gadget', 'ez', 'eze', 'nokia', '2'),
(12, 'gadget', 'a', 'de', 'nokia', '123');

I’m not a beggar but i’m really stuck and need this page because i cant finish the other pages. Could you please help me?

Look, tutorials are probably your best bet… but this line here;

echo ‘$row[$maingroup]’;

Is not awesome. (it’s getting parsed as a string)

Sekasi, what could be a solution to the echo line? or a solution for the entire page?
The problem with tutorials is that i already have a complete website but only this page is missing so a tutorial doesn’t fix this because its complete different.

I know that i’m totally a weenie on php but as you can see in previous topics i always make a great summary of the topic so other people can create the same thing so its not that i’m only ask questions …

In PHP when you put something between simple [SIZE=-1]quotation marks[/SIZE], it is parsed as a string. As a result your echo does not have the desired effect.
To avoid this, simply do echo

$row[$maingroup];

If you would use “”, the string would get parsed. I suggest you check the differences between simple and double [SIZE=-1]quotation [/SIZE]in PHP.

Thanks Agnus,

I verified and adjusted the original script from a tutorial mentioned by you.
That did the trick!

Thanks everyone