# Webshop stuck

**URL:** <https://forum.kirupa.com/t/webshop-stuck/261981>\
**Category:** programming\
**Created:** [June 2, 2008, 12:09pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981 "2008-06-02T12:09:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 12:09pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/1 "2008-06-02T12:09:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 1:15pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/2 "2008-06-02T13:15:31Z")

</div>

Probably it makes sense but i don’ get it 🙂  
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.

```php

<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.

```php

<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.

```php

<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

<?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…

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 1:37pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/3 "2008-06-02T13:37:39Z")

</div>

Hi ahmednuaman,

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

Greetz

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 2:21pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/4 "2008-06-02T14:21:38Z")

</div>

Why do you make the endif?

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 3:27pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/5 "2008-06-02T15:27:28Z")

</div>

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 🙂 , my shop is running perfect only these pages to select are difficult

```php
<?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");
?>

```

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 7:57pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/6 "2008-06-02T19:57:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 2, 2008, 8:20pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/7 "2008-06-02T20:20:48Z")

</div>

> [@ahmednuaman;2335051](#):
>
> Ok I strongly recommend you get the following book: [http://www.dmcinsights.com/php/](http://www.dmcinsights.com/php/)

: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:

---

<div class="post-metadata">

**Author:** ![agnus](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@agnus](https://forum.kirupa.com/u/agnus)\
**Post date:** [June 3, 2008, 9:51am UTC](https://forum.kirupa.com/t/webshop-stuck/261981/8 "2008-06-03T09:51:04Z")

</div>

i recommend that you take a look at tree structures. [Here](http://www.tonymarston.net/php-mysql/tree-structure.html) is something I found.

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 3, 2008, 6:48pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/9 "2008-06-03T18:48:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 4, 2008, 7:31pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/10 "2008-06-04T19:31:04Z")

</div>

Ok, I tried something [http://www.e-meel.be/test/](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=](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
<?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

```

```auto

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 4, 2008, 7:46pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/11 "2008-06-04T19:46:30Z")

</div>

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

echo ‘$row[$maingroup]’;

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

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 4, 2008, 8:10pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/12 "2008-06-04T20:10:24Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![agnus](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@agnus](https://forum.kirupa.com/u/agnus)\
**Post date:** [June 5, 2008, 10:18am UTC](https://forum.kirupa.com/t/webshop-stuck/261981/13 "2008-06-05T10:18:29Z")

</div>

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

```php
$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.

---

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [June 5, 2008, 3:33pm UTC](https://forum.kirupa.com/t/webshop-stuck/261981/14 "2008-06-05T15:33:07Z")

</div>

Thanks Agnus,

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

Thanks everyone
