0

I am trying to style my output data, but I do not know how exactly do this.

My code looks like this:

$Sql99 = "SELECT Cat_Name, Cat_Id, COUNT(Product_Id) AS itemcount FROM tabproducts 
      INNER JOIN tabcats ON tabproducts.Cat_Id = tabcats.Cat_Id  
      GROUP BY tabproducts.Cat_Id ORDER BY itemcount DESC LIMIT 0,4";
$Query99 = mysql_query($Sql99, $Conn);
while($Rs99 = mysql_fetch_array($Query99)){ 

 $cats .= "<li><a href=\"\">".$Rs99["Cat_Name"]."</a></li>"; //this is fine


 $Sql08 = "SELECT tabproducts.*
      FROM tabproducts
      WHERE tabproducts.Cat_Id = '".$Rs99["Cat_Id"]."' ORDER BY Product_Id DESC
      LIMIT 0,5";
$Query08 = mysql_query($Sql08, $Conn) or die(mysql_error());
while($Rs08 = mysql_fetch_array($Query08)){

//OUTPUT

}
 }

My problem is on the second select the information I am try do output should look like this:

      <div>
        <ul class="home-listagem-empresas"> //categorie 1
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
        </ul>
      </div>
      <div>
        <ul class="home-listagem-empresas"> //categorie 2
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
        </ul>
      </div>
      <div>
        <ul class="home-listagem-empresas"> //categorie 3
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
        </ul>
      </div>
      <div>
        <ul class="home-listagem-empresas"> //categorie 4
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
          <li>
            <h1>".$Rs08["Product_Name"]."</h1>
          </li>
        </ul>
      </div>

Each ul with the li's will represent the results from the 4 categories.

Sorry if I cannot explain it well, my English is not very good.

1
  • Do the output correctly with the DIV UL and LI's Commented Dec 6, 2012 at 22:23

1 Answer 1

1

If I understand correctly your problem is that you are unable to present the data in a way that is convenient for you. These types of problems (nested loops) occur a lot in application development and you should probably look into practicing basic algorithms for this. Here are a couple of tutorials to help you out.

That being said, to obtain the output you desire, you would do this:

$cats .= "<div><ul class='home-listagem-empresas'>";
while($Rs08 = mysql_fetch_array($Query08)){
  //OUTPUT
  $cats .= "<li><h1>".$Rs08["Product_Name"]."</h1></li>";
}
$cats .= "</ul></div>";

All the best,

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help @KerrM i was on right way my mistake was on the first $cats for open the div i was doing $cats = and not .= thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.