Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:15:42+00:00 2026-06-10T18:15:42+00:00

I have two navigation one is in the header and the other is in

  • 0

I have two navigation one is in the header and the other is in the same page, now what I want is to do is be able to pull all the data from the table product a specific product from the sub category when I click the sub category. what I have now, is when I click on the menu that is on the header page that I have included in every page I get the product listed but the menu that is on product page produce an error that the foreach is empty. when I use my other function to pull all the sub category it works fine but I want to pull only the sub category that belong to that particular main category. the code below will make more sense.

header Page:

<?php 
error_reporting(E_ALL);
ini_set('display_errors','1');?>
<?php require_once("initi.php");?>
<html>
<head>
<title></title>
 <link rel="stylesheet" href="css/reset.css" />
 <link rel="stylesheet" href="css/main.css" />
 <link rel="stylesheet" href="css/footer.css" />
<script type="text/javascript" src="/ghaniya.com/javascript/jqu.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".logbtn").click(function(){ 
      $("#login2").hide("show");
      $("#login1").slideToggle("slow");
      $(this).toggleClass("active");

});

$(".logbtn2").click(function(){ 
      $("#login1").hide("show");
      $("#login2").slideToggle("slow");
      $(this).toggleClass("active");      
});
});
</script>
<style type="text/css">

div#login1{
background-color:#efebee;
margin:0 auto;
width:100%;
display:none;
height:100px;
}

div#login2{
background-color:#f5dce4;
margin:0 auto;
width:100%;
display:none;
height:100px;
}
.size{width:960px; }
.flotl{float:left; font-size:11px; text-decoration:none; height:30px; margin-left:20px;}
div#centerl{ width:960px; margin:0 auto; }
</style>
</head>
<body>
<div id="head">

<div class="size center">
<img src="img/logosmall.png">
<ul id="mainLink">
<li><a class="logbtn">Women</a></li><li><a class="logbtn2" href="#">man</a></li><li><a href="#">Beauty</a></li><li><a href="">Gifts</a></li><li><a href="">Perfumes</a></li>
</ul>

<div id="loginBox">
<h3>REGISTER | SIGN IN</h3>
</div>

<div id="search">
<input type="submit"/><input type="text" value="Search"/>
</div>
<div id="bag"></div>
</div>
</div>


<div id="login1" >
<div id="centerl">
<ul class="flotl" >
<?php
$cata = Catagory::find_all(); 
foreach($cata as $catag){?>
      <li><a href="/ghaniya.com/product.php?catid=<?php echo $catag->catagory_id;?>"><?php echo $catag->name; ?></a></li>
<?php }?>
</ul> 
</div>
</div>

Product Page:

<?php require_once("includes/head.php"); ?>
<?php
  $cata_id = "";  
  $subcat ="";
  if(isset($_GET['catid']))
    {
         $cata_id = $_GET['catid'];
         $product = Product::find_by_cata_id($cata_id);
    }
    elseif(isset($_GET['subcat']))
    {
    $subcat =$_GET['subcat'];
    $subcat = SubCata::find_by_cata_id(1);
    print_r($subcat);
    }
?>
<div class="cBoth"></div>
<div id="contentEveryWhere" class="center">
<div id="cata">
<div id="leftNoticeBoard"></div>
<ul id="catagories">
<h1>CLOTHING</h1>
<?php foreach($subcat as $sub){ ?>
<li><a href="product.php?subcat=<?php echo $sub->subcata_id; ?>"><?php echo $sub->name; ?></a></li>
<?php } ?>
</ul>
</div>
<div id="products">
<div id="catatitle"> 
<ul>
<li>Home ></li><li>Women ></li><li>Coat<li>
</ul>
<h1>Coat</h1>
<p class="floatl">Sort items by Price: High | Low View as: <img src="#" alt="icon png"/> |<img src="#" alt="icon png"/></p>
</div>
<ul id="product">
<?php $product = Product::find_by_cata_id($cata_id);?>
<?php foreach($product as $pro){?>
<?php $image = Image::find_by_product_id( $pro->product_id);?>
          <li>
               <?php if(isset($image->filename)){ ?>
               <img src="/ghaniya.com/img/products/<?php echo $image->filename;?>"/>
               <?php } ?>

              <h2><?php echo $pro->name;?></h2>
              <h3> <?php echo $pro->product_desc;?></h3>
              <h4><?php echo $pro->price;?></h4>
          </li>
<?php } ?>
</ul><!--end of product list-->
</div> <!--end of products div-->


</div><!--end of contentEveryWhere div-->
<div class="cBoth"></div>
<?php require_once("includes/footer.php"); ?>

Warning: Invalid argument supplied for foreach() in /Users/mughery/Website/ghaniya.com/product.php on line 25

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:15:44+00:00Added an answer on June 10, 2026 at 6:15 pm

    The problem is quite simple:

    if(isset($_GET['catid']))
    {
        $cata_id = $_GET['catid'];
        $product = Product::find_by_cata_id($cata_id);
    }
    elseif(isset($_GET['subcat']))
    {
        $subcat =$_GET['subcat'];
        $subcat = SubCata::find_by_cata_id(1);
    }
    

    That means you’re only setting $subcat if, and only if $_GET['catid'] isn’t set and $_GET['subcat'] is. In all other cases $subcat is an empty string, not an array. Just add a line like:

    $subcat = (is_array($subcat) ? $subcat : SubCata::find_by_cata_id(1));
    //or: 
    $subcat = (is_array($subcat) ? $subcat : array());
    

    And you’ll be good to go

    Also, this:

    $subcat =$_GET['subcat'];
    $subcat = SubCata::find_by_cata_id(1);
    

    Doesn’t really make sense to me, I think you need something like:

    elseif(isset($_GET['subcat']))
    {
        $subcat =SubCata::find_by_cata_id($_GET['subcat']);
    }
    $subcat = (is_array($subcat) ? $subcat : SubCata::find_by_cata_id(1));
    

    If not, regardless of the subcat parameters actual value, your fetching all data for id 1…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two pages that inherit from one master page, First.aspx or second.aspx. Navigation
I have two user controls on the same page. One contains a ListView that
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
We have two forms where we need to pass values from one to the
I have one main page in my Silverlight project. I have two frame inside
I want to have two separate interfaces to my website, one that is silverlight,
I have two XAML pages. One page (named Page1) has a listbox named strangers
I have two jquery scripts on one page that both target on-site links via
So I have a rails application that has two different navigation headers. One that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.