?
Solved

PHP Mysql Image Gallery Cat/Subcat problems.

Posted on 2005-05-11
6
Medium Priority
?
633 Views
Last Modified: 2013-12-12
I'm working on building myself an image gallery to store my graphics. I'm starting to get there :) But I've run across one slight problem....


When I click on the category to view the subcat, it doesn't show *all* of the subcats... It cuts off 1 - 3 of them. I can't find any sort of pattern with this, and I double checked my table to make sure that their cat_id was set properly...

Here is my code:
----------------------------------
     require "database.php";
     $title = "Live Journal Icons - $catname/$subcat";
     $contenttitle = "Live Journal Icons $catname/$subcat";
     include "header.php";
     $images_dir = "/icons/";

     $result_array = array();
     $counter = 0;

     $sid = (int)($_GET['sid']);
     $cid = (int)($_GET['cid']);


//Are We Viewing a category?
if (empty($cid) && empty($sid)) {
     //no?
     echo "<h3>Please select a Category</h3>";
     echo "<table border='0' cellspacing='0' cellpadding='5' width='100%'>";
     echo "<tr>";
     $cols = 4;
     //fetch the categories
          $query = mysql_query("SELECT c.cat_id as catid, c.cat_name as catname, COUNT(s.cat_id) AS subs FROM icon_categories as c LEFT JOIN icon_subcats as s ON c.cat_id = s.cat_id GROUP BY c.catname ASC");
          while ($row = mysql_fetch_array($query)) {
               if ($counter == $cols) {
                    $counter = 1;
                    echo "</tr><tr>";
               } else {
                    $counter++;
                    echo "<td align='center'><a href='icons.php?cid=", $row['catid'], "'>", $row['catname'], "</a> (", $row['subs'], ")</td>";
               }
          }
     echo "</tr></table>";
                   
} else if (!empty($cid) && empty($sid)) {
     //Yes?
     echo "<h3>Please select a Sub-Category</h3>";
     echo "<table border='0' cellspacing='0' cellpadding='5' width='100%'>";
     echo "<tr>";
     $cols = 3;
     // fetch the sub categories
          $query = mysql_query("SELECT sub_id as subid, sub_name as subname, cat_id FROM icon_subcats WHERE cat_id = '$cid' ORDER BY subname ASC");
          while ($row = mysql_fetch_array($query)) {
               if($counter == $cols) {
                    $counter = 0;
                    echo "</tr><tr>";
               } else{
                    $counter++;
                    echo "<td align='left'><a href='icons.php?cid=", $cid, "&sid=", $row['subid'], "'>", $row['subname'], "</a></td>";
               }
          }
     echo "</tr></table>";
}
---------------------------------------

If you'd like to see it "in action" to see what I'm talking about - it's located at the following URL:

http://www.jeanies-creations.com/icons.php

Thanks!
0
Comment
Question by:ReekaJean
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:ljw87505
ID: 13983635
Hi ReekaJean,
In your first query:
> "SELECT c.cat_id as catid, c.cat_name as catname, COUNT(s.cat_id) AS
> subs FROM icon_categories as c LEFT JOIN icon_subcats as s ON c.cat_id
> = s.cat_id GROUP BY c.catname ASC"

Is that supposed to be "ORDER BY c.catname ASC"?

0
 

Author Comment

by:ReekaJean
ID: 13983796
When I put ORDER BY, I get the following error:

Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause

So, I'm assuming it's supposed to be GROUP BY.

To be honest, I don't really know. lol. Is there a way to count something from a table without using the count() function? I'm fairly new at this... lol.
0
 

Author Comment

by:ReekaJean
ID: 13983813
Oh, and I didn't think about this - I guess seeing it in action doesn't do any good if you don't know what subcats are in each category. lol.

The three I'm having problems with are Star Wars, Harry Potter and Icon Bases.

The subcats that aren't showing up in those three are as follows:

Star Wars
--Revenge of the Sith
--Empire Strikes Back

Harry Potter
--Philosopher's Stone

Icon Bases
--Harry Potter - Philosopher's Stone
--Star Wars - Revenge of the Sith
--Star Wars - Clone Wars

--------------

Also, now that I've got the icon-viewing part up, the following Icons aren't showing up either o.O

Actors -> Johnny Depp -> johnny5.gif
Harry Potter ->Goblet of Fire -> fleur.jpg

The code for the icon part is:

--------------------------------
} else {
      //We're viewing the icons! Yay!
      $query1 = mysql_query("SELECT cat_name FROM icon_categories WHERE cat_id = '$cid'");
      while ($row = mysql_fetch_array($query1)) {
            $catname = $row['cat_name'];
            echo "<h3>$catname Icons</h3>";
      }
      echo "<table border='0' cellspacing='0' cellpadding='5' width='100%'>";
      echo "<tr>";
      $cols = 4;
      //Fetch the Icons
            $query2 = mysql_query("SELECT * FROM icon_images WHERE sub_id = '$sid' ORDER BY icon_id ASC");
            while($row2 = mysql_fetch_array($query2)) {
                  if ($counter == $cols) {
                        $counter = 1;
                        echo "</tr><tr>";
                  } else {
                        $counter++;
                        
                        echo "<td align=\"center\"><img src=\"", $imgdir, $row2['icon_filename'], "\" alt=\"", $row2['icon_caption'], "\" /><br />", $row2['icon_caption'], "</td>";
                  }
            }
      echo "</tr></table>";
}

Which is just at the end of the code I posted earlier. :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Accepted Solution

by:
matt_mcswain earned 2000 total points
ID: 13983861
Looks like just a slight error in logic. In your while loops that echo out the data your not echoing when it's time to create a new row. So try changing your loops to something like:

while ($row = mysql_fetch_array($query)) {
               if($counter == $cols) {
                    $counter = 0;
                    echo "</tr><tr>";
               } else{
                    $counter++;
                 }
                    echo "<td align='left'><a href='icons.php?cid=", $cid, "&sid=", $row['subid'], "'>", $row['subname'], "</a></td>";
}
0
 

Author Comment

by:ReekaJean
ID: 13983933
THANK YOU! I knew it had to have been something simple. lol.

Totally appreciated! :D
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13983964
No problem ;)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question