#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22

    Generate unlimited boxes for div classes


    Hi guys,

    I have got a problem with the code in my PHP. I stored 8 rows of channels in mysql database and I use var totalrowcount to display 8 boxes for div classes to display with rows that I stored from mysql, but I cannot be able to display more than 8 boxes of div classes when I store more than 8 rows in mysql.

    I want to create the unlimited boxes for div classes with any range of number to match the rows depends on how many rows that I store in mysql database.

    Here is the code I found where the trouble is coming from:

    PHP Code:
    var totalrowcount 8;

    <
    div class="mainWrap">
        <
    div class="row" id="row1">
            <
    div id="image1" class="channelList div_1_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe1" class="pgmFirstRow div_1_2"></div>
                <
    div id="programe2" class="pgmFirstRow div_1_3"></div>
                <
    div id="programe3" class="pgmFirstRow div_1_4"></div>
            </
    div>
        </
    div>
        <
    div class="clear"></div>
        <
    div class="row"  id="row2">
            <
    div id="image2" class="channelList div_2_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe4" class="pgmFirstRow div_2_2"></div>
                <
    div id="programe5" class="pgmFirstRow div_2_3"></div>
                <
    div id="programe6" class="pgmFirstRow div_2_4"></div>
            </
    div>
        </
    div>
        <
    div class="clear"></div>
        <
    div class="row"  id="row3">
            <
    div id="image3" class="channelList div_3_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe7" class="pgmFirstRow div_3_2"></div>
                <
    div id="programe8" class="pgmFirstRow div_3_3"></div>
                <
    div id="programe9" class="pgmFirstRow div_3_4"></div>
           </
    div>
        </
    div>
        <
    div class="clear"></div>
        <
    div class="row"  id="row4">
            <
    div id="image4" class="channelList div_4_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe10" class="pgmFirstRow div_4_2"></div>
                <
    div id="programe11" class="pgmFirstRow div_4_3"></div>
                <
    div id="programe12" class="pgmFirstRow div_4_4"></div>
           </
    div>
        </
    div>
        <
    div class="clear"></div>
        <
    div class="row"  id="row5">
            <
    div id="image5" class="channelList div_5_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe13" class="pgmFirstRow div_5_2"></div>
                <
    div id="programe14" class="pgmFirstRow div_5_3"></div>
                <
    div id="programe15" class="pgmFirstRow div_5_4"></div>
            </
    div>
        </
    div>
        <
    div class="clear"></div>
        <
    div class="row" id="row6">
            <
    div id="image6" class="channelList div_6_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe16" class="pgmFirstRow div_6_2"></div>
                <
    div id="programe17" class="pgmFirstRow div_6_3"></div>
                <
    div id="programe18" class="pgmFirstRow div_6_4"></div>
           </
    div>
        </
    div>
        <
    div class="clear"></div>
            <
    div class="row"  id="row7">
            <
    div id="image7" class="channelList div_7_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe19" class="pgmFirstRow div_7_2"></div>
                <
    div id="programe20" class="pgmFirstRow div_7_3"></div>
                <
    div id="programe21" class="pgmFirstRow div_7_4"></div>
            </
    div>
        </
    div>
        <
    div class="clear"></div>
            <
    div class="row"  id="row8">
            <
    div id="image8" class="channelList div_8_1"></div>
            <
    div class="rowSubPgm">
                <
    div id="programe22" class="pgmFirstRow div_8_2"></div>
                <
    div id="programe23" class="pgmFirstRow div_8_3"></div>
                <
    div id="programe24" class="pgmFirstRow div_8_4"></div>
            </
    div>
        </
    div>
        <
    div class="clear"></div

    I can output the unlimited rows from mysql without have any problem, but I cannot display more than 8 boxes for div classes. If I want to create the classes, I would have to change the last number in each line at the end, e.g: pgmFirstRow div_9_4, pgmFirstRow div_10_4 and so on.

    I am going to store thousand of rows in mysql and I find that it would be too much for me to work it on to add thousand lines of codes for add div classes.

    Does anyone know how to create the code to allow me to add unlimited number of div classes using with the arrays for the totalrowcount to match the rows that I store in mysql to allow me to add any range of boxes for div classes??

    Any advice would be much appreciated.

    Thanks in advance
    Last edited by stephen100; June 4th, 2013 at 05:53 PM.
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    So use a counter in a loop. Basically just
    PHP Code:
    <?php $i 1; foreach (all the rows) { ?>
    <div class="row" id="row1">
        <div id="image1" class="channelList div_<?=$i?>_1"></div>
        <div class="rowSubPgm">
            <div id="programe1" class="pgmFirstRow div_<?=$i?>_2"></div>
            <div id="programe2" class="pgmFirstRow div_<?=$i?>_3"></div>
            <div id="programe3" class="pgmFirstRow div_<?=$i?>_4"></div>
        </div>
    </div>
    <div class="clear"></div>
    <?php $i++; } ?>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22
    thanks for your quick reply, do i have to replace the code you suggest me to and what about the var totalcount??

    do i have to replace from this:
    PHP Code:
    var totalrowcount 8
    to this?
    PHP Code:
    var totalrowcount

    if not plz let me know.

    thanks in advance
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    First you have to learn what you're doing. That thing you posted was your actual code? You have a "var totalrowcount" just sitting there out in the open?

    I posted PHP code. Not exact code either, you have to make a change to it (tip: it's the thing that isn't valid code). Look at it and understand how it works. Then figure out how it fits into what you have now. If it doesn't fit perfectly then figure out why not and what you need to change to make it work.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22
    Yeah i just know that. I have just removed the code var totalcount and I have pasted the code in my code list, but it is only display one row when I have more than one rows in mysql:

    I tried this:

    PHP Code:
    $i = 1; foreach (all the rows) { ?>
    <div class="row" id="row1">
        <div id="image1" class="channelList div_<?=$i?>_1"></div>
        <div class="rowSubPgm">
            <div id="programe1" class="pgmFirstRow div_<?=$i?>_2"></div>
            <div id="programe2" class="pgmFirstRow div_<?=$i?>_3"></div>
            <div id="programe3" class="pgmFirstRow div_<?=$i?>_4"></div>
        </div>
    </div>
    <div class="clear"></div>
    $i++; } ?>


    It is shows " $i = 1; foreach (all the rows) {" before the box and "$i++; }" after the box.

    Please fix the code the one you posted.
    Last edited by stephen100; June 4th, 2013 at 07:01 PM.
  10. #6
  11. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    The code I posted is fine. Learn how to write PHP yourself. I'm willing to help you once you've done that.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22
    The code you posted are ONLY show one row and nothing is else. I WANT to count how many rows I stored in mysql before create the rows using with div classes.

    However, it give me an idea what i need to do. Do you know how to count on each tags of span id like <p id='channels'> from my other script get-listing.php before i create the rows using with div class??
  14. #8
  15. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    That's right, it is not the complete and absolute answer to your problem. But with a tiny bit of effort on your part it could be. That's what I'm trying to get you to do: that bit of effort. It's really not much at all.

    As for your new question, yes but it's not the way to go. Doesn't it sound much more complicated than what you had so far?

    I'm not sure how the stuff you posted at first turns into the content you seem to be looking for, but apparently it simply does.
    1. I posted PHP code. That means it has to execute as PHP code. That means you need <?php and ?> tags somewhere around it.
    2. The loop needs actual things to loop over. Have a number instead of an array? Then use a for instead of a foreach. Have something else? Then elaborate.
    3. If there's still a problem then you have to start talking about what's going on and how things work. You can't just walk up to a forum and say "I have this it doesn't work fix it". You have to explain yourself, describe the situation, and be willing to answer questions because we really really have no clue what you're talking about unless you do so.
    Last edited by requinix; June 4th, 2013 at 07:30 PM.

IMN logo majestic logo threadwatch logo seochat tools logo