Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    what I need is for a loop to run to make tabbed pannels according to categories. then I need the buttons to be put into the correct tab based on the category it falls under. then a subcategory tabs inside the other tabs for products that have that specific sub category.

    here is what I sorta made....it doesn't work though....

    PHP Code:
    <div id="TabbedPanels1" class="TabbedPanels">
            <ul class="TabbedPanelsTabGroup"><?php $sql mysql_query("SELECT * FROM categories");
    while(
    $row mysql_fetch_array($sql)){
    $category $row["category"];
    $sub =$row["subcategory"];
    ?>

    <li class="TabbedPanelsTab" tabindex="0"><?php echo $category?></li>
    <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
    <?php
    // set layout vars
    $x 1// set $x
    $start = array ('1''10''19''28''37''46''55''64''73''82''91''100''109''118''127''135'); //columns will be started at each of these numbers
    $end = array( '9''18''27''36''45''54''63''72''81''90''99','108','117''126' ); // set numbers to end columns at
    ?>

            <?php echo '<table border="1px" cellpadding="0px" cellspacing="0px" ><tr height=\'50px\'>'//start the table, and the row.
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM products where category=".$category."");
    while(
    $row mysql_fetch_array($sql)){
    $product $row["product"];
    $id =$row["id"];
    $price =$row["price"];
    if (
    in_array($x$start)) { // if x equals a number in the start array
    echo '<td width="100">';                  // start a column
    ?>

        <?php $sql mysql_query("SELECT * FROM categories");
    while(
    $row mysql_fetch_array($sql)){
    $category $row["category"];
    $sub =$row["subcategory"];
    ?>

    <?php
    }
    ?>
     
        <div id="products">
          <form action="" method="POST" name="myform<?php echo $id?>" class="myform<?php echo $id?>">
            <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product?>" />
            <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id?>" />
            <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price?>" />
          <input type="submit" name="submit" class="submit" value="<?php echo $product?>" style="background-color:lightgreen; height:50px; padding: 0px; margin:0px; width:100px;">  </form>
        </div>
    <?php
    if (!in_array($x$end)){ // if $x equals anything OTHER than 9, 18, etc - put in a line break
    } else { // else if it DOES equal 9, 18 ,etc end the column
    echo '</td>';
    }
    $x ++; // increase x to keep count
    // while loop ends
    //now outside of the loop,
    $x $x 1//subtract the last $X++ so you know exactly how many buttons were added
    if (!in_array($x$end)){ // if $x equals anything OTHER than 9, 18, etc - end the column as it wouldn't have ended itself
    echo '</td>';
    }
    echo 
    '</tr></table>'// close the row and table

    ?><?php
    }
    ?>            </div>

      </ul>

          </div>
    any help is greatly appreciated.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    define "it doesn't work" ...

    Do you get script errors?
    Tell us what isn't working.
    Realize that we can't test what you're showing us, we don't have your MySQL database installed.


  4. #3
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    well.... I get this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/tkdpostk/public_html/index.php on line 395. by it doesn't work......I mean it doesn't work. the tabs don't display.....well the first does and that is the error I get. and no products display. I know you can't access my database. thats fine. I am just looking for suggestions basically.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Tell me which of those lines in your posted script is line 395.
    You must not have posted the whole script?


  6. #5
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    while($row = mysql_fetch_array($sql)){

    from <?php echo '<table border="1px" cellpadding="0px" cellspacing="0px" ><tr height=\'50px\'>'; //start the table, and the row.
    // Query member data from the database and ready it for display
    $sql = mysql_query("SELECT * FROM products where category=".$category."");
    while($row = mysql_fetch_array($sql)){
    $product = $row["product"];
    $id =$row["id"];
    $price =$row["price"];
    if (in_array($x, $start)) { // if x equals a number in the start array
    echo '<td width="100">'; // start a column
    } ?>

    about the third "paragraph" down.

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    I see a mistake on this line ....
    $sql = mysql_query("SELECT * FROM products where category=".$category."");

    Should be:

    $sql = mysql_query("SELECT * FROM products where category='$category' ");

    You're OK with the periods, but missing the first single quote.
    I did the same thing without the periods in my "should be".

    Use single quotes in all of these:
    $product = $row["product"];


  8. #7
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    so now it is displaying one button and one tab. there are over 100 buttons that should all fall under their specific tab. here is the entire body if it helps:
    PHP Code:
    <body>

    <div class="container">
      <div class="content">
        <div id="price">
          <?php
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM cart where cart_id = ".$cid."");
    while(
    $row mysql_fetch_array($sql)){
    $product $row["product123"];
    $price1 $row["price"];
    $id $row["id"];
    $qty $row["quantity"];
    if(
    $product !=""){
      
    ?>
    <form name="delete<?php echo $id?>" class="delete<?php echo $id?>" method="POST" action="">
    <input type="image" name="submit" value="delete" src="pics/x.jpg" style="height:25px; width:40px;">
      <input type="hidden" name="hiddenField" value="<?php echo $id?>" />

      <?php  echo $product;
    ?>
    </form>
    <div id="name">
    <form action="" class="update<?php echo $id?>" method="POST">

      <input name="id" type="hidden" value="<?php echo $id?>" />
        Quantity
        <input name="qty" type="text" value="<?php echo $qty?>" size="2" />$<input name="price" type="text" value="<?php echo $price1?>" size="6" />

        <input type="submit" name="update" id="update" value="update" />
    </form><hr /></div>
     
        <?php
        $price1 
    $price1 $qty;
    $total =  $price1 $total;
    ?>
    <?php
    }}
    ?>
          <br />

    </div> <?php
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM products");
    while(
    $row mysql_fetch_array($sql)){
    $product $row["product"];
    $id =$row["id"];
    $price =$row["price"];

    ?>

    <?php

    }
    ?>
    <form action="" method="POST" name="empty" class="empty">

        <input name="cart_id" type="hidden" value="<?php echo $cid?>" /><input type="submit" name="empty" class="submit" value="empty cart" style="background-color:lightgreen; height:50px; width:100px;left:0px;"">  </form>
    <div id="total"><form name="pay" class="pay" method="POST" action="collect.php">
      <p>
        <?php if ($total == ""){$total "0";} ?>
        <?php echo "$".$total.""?>
        <?php
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM cart where cart_id = ".$_SESSION['cart_id']."");
    while(
    $row mysql_fetch_array($sql)){
    $product $row['product123'];
    $price1 $row['price'];
    $id $row['product_id'];
    $qty $row['quantity'];
      
    $month date("F Y");
    $day date("d");
    $year date("Y");
    $date date("Y-m-d");
    ?>
        <input name="product[]" type="hidden" value="<?php echo $product?>" /><input name="academy[]" type="hidden" value="<?php echo $academy?>" /><input name="month[]" type="hidden" value="<?php echo $month?>" /><input name="day[]" type="hidden" value="<?php echo $day?>" /><input name="year[]" type="hidden" value="<?php echo $year?>" /><input name="date[]" type="hidden" value="<?php echo $date?>" /><input name="price[]" type="hidden" value="<?php echo $price1?>" /><input name="id[]" type="hidden" value="<?php echo $id?>" />
      <input name="qty[]" type="hidden" value="<?php echo $qty?>" /><input name="total" type="hidden" value="<?php echo $total?>" />
      
      <?php
    }
    ?>
      <?php if ($total == " "){$total "0";} ?><input type="submit" name="pay" id="pay" class="pay1" value="" />
      </p>
    </form><br />

    </div>

    $x = 1; // set $x
    for ($i=1; $i<=100; $i += 9)
      {  $start = array ($i);} //columns will be started at each of these numbers
    for ($n=0; $n<=100; $n += 9)
    {
    $end = array($n);}

    <form class="myfor" id="myfor" method="POST">
    <select>
     
    <?php //start the table, and the row.
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM products");
    while(
    $row mysql_fetch_array($sql)){
    $product $row['product'];
    $id =$row['id'];
    $price =$row['price'];
    ?>

    <option name="submit"><?php echo $product?> </option>
         
    <?php
                      
    // start a column
    ?>
    </select>
    <input type="submit" value="Go" name="submit" />

    </form>
    <div id="TabbedPanels1" class="TabbedPanels">
            <ul class="TabbedPanelsTabGroup"><?php $sql mysql_query("SELECT * FROM categories");
    while(
    $row mysql_fetch_array($sql)){
    $category $row['category'];
    $sub =$row['subcategory'];
    ?>

    <li class="TabbedPanelsTab" tabindex="0"><?php echo $category?></li>
    <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
    <?php
    // set layout vars
    $x 1// set $x
    $start = array ('1''10''19''28''37''46''55''64''73''82''91''100''109''118''127''135'); //columns will be started at each of these numbers
    $end = array( '9''18''27''36''45''54''63''72''81''90''99','108','117''126' ); // set numbers to end columns at
    ?>

            <?php echo '<table border="1px" cellpadding="0px" cellspacing="0px" ><tr height=\'50px\'>'//start the table, and the row.
    // Query member data from the database and ready it for display
    $sql mysql_query("SELECT * FROM products where category='$category'");
    while(
    $row mysql_fetch_array($sql)){
    $product $row['product'];
    $id =$row['id'];
    $price =$row['price'];
    if (
    in_array($x$start)) { // if x equals a number in the start array
    echo '<td width="100">';                  // start a column
    ?>

        <?php $sql mysql_query("SELECT * FROM categories");
    while(
    $row mysql_fetch_array($sql)){
    $category $row['category'];
    $sub =$row['subcategory'];
    ?>

    <?php
    }
    ?>

        <div id="products">
          <form action="" method="POST" name="myform<?php echo $id?>" class="myform<?php echo $id?>">
            <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product?>" />
            <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id?>" />
            <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price?>" />
          <input type="submit" name="submit" class="submit" value="<?php echo $product?>" style="background-color:lightgreen; height:50px; padding: 0px; margin:0px; width:100px;">  </form>
        </div>
    <?php
    if (!in_array($x$end)){ // if $x equals anything OTHER than 9, 18, etc - put in a line break
    } else { // else if it DOES equal 9, 18 ,etc end the column
    echo '</td>';
    }
    $x ++; // increase x to keep count
    // while loop ends
    //now outside of the loop,
    $x $x 1//subtract the last $X++ so you know exactly how many buttons were added
    if (!in_array($x$end)){ // if $x equals anything OTHER than 9, 18, etc - end the column as it wouldn't have ended itself
    echo '</td>';
    }
    echo 
    '</tr></table>'// close the row and table

    ?><?php
    }
    ?>            </div>

      </ul>

          </div>

        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      <!-- end .content --></div>

      <!-- end .container --></div>
    <script type="text/javascript">
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    </script>
    </body>

  9. #8
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    oh, and just kinda worry about where we talkin about....I know there is some other stuff in there I need to clean up

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    You're using $row multiple times in the loop for different queries ... you can't do that.

    See the red part as an example of what you're doing wrong ...

    while($row = mysql_fetch_array($sql)){
    $category = $row['category'];
    $sub =$row['subcategory'];
    ?>
    <li class="TabbedPanelsTab" tabindex="0"><?php echo $category; ?></li>
    <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
    <?php
    // set layout vars
    $x = 1; // set $x
    $start = array ('1', '10', '19', '28', '37', '46', '55', '64', '73', '82', '91', '100', '109', '118', '127', '135'); //columns will be started at each of these numbers
    $end = array( '9', '18', '27', '36', '45', '54', '63', '72', '81', '90', '99','108','117', '126' ); // set numbers to end columns at
    ?>
    <?php echo '<table border="1px" cellpadding="0px" cellspacing="0px" ><tr height=\'50px\'>'; //start the table, and the row.
    // Query member data from the database and ready it for display
    $sql = mysql_query("SELECT * FROM products where category='$category'");
    while($row = mysql_fetch_array($sql)){
    $product = $row['product'];

    Call them different names, like $row1, $row2, $row3, etc.


  11. #10
    Senior Member
    Join Date
    Feb 2011
    Posts
    101
    Member #
    26966
    even at that it still only displays one button and one tab.....it should be like 6 tabs and 130 buttons.......I am pretty sure it has to do with how I am looping stuff. I almost KNOW for a fact that the structure of my original code is not correct......maybe help me get the syntax of that right.

    here is an example of what I want:

    Category1 category2 category3 category4
    product1 product2 product3 product4
    subcat1(if applicable)

    etc.

    product2 could be under any category, just depending on what it would fall under.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

how to create tabbed panels while php loop

Click on a term to search for related topics.
All times are GMT -6. The time now is 02:44 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com