0

Here is my code segment:

for($i=0;$i<23;$i++){
    echo "<div id=slotshead></div>";
    for($j=0;$j<30;$j++) {
        echo " <div id=slots></div>";
    }
    echo '<br>';
}

But, it doesn't work. I want the two echo statements inside the loop to be continued, not break into a new line. How can I fix it?

Tchoupi
  • 14,560
  • 5
  • 37
  • 71
ZameerMoh
  • 1,149
  • 1
  • 17
  • 26
  • 1
    If you dont want it to create new lines why do you have echo '
    '?
    –  Mar 16 '13 at 02:03
  • Why are you applying the CSS to the H3 when that's what's wrapping all the block-level content within it? Further, you're explicitly putting a line-break after each `$i` loop... I'm completely lost on what you're trying to do. – animuson Mar 16 '13 at 02:03
  • I want the two echos inside the loops to be joined as one line.... – ZameerMoh Mar 16 '13 at 02:04
  • Just a side not, `id`s must be unique. – hjpotter92 Mar 16 '13 at 02:13
  • @DreamEater .... I cudn't get u...? – ZameerMoh Mar 16 '13 at 02:15
  • @MohammedZameer: Those `
    `s and `
    `s you're printing out...there will be 23 and 690 of each, respectively, with the same IDs. A number of browsers will positively hate that, and you'll have a heck of a time trying to access the elements by ID. You'll probably want to use classes instead of IDs here.
    – cHao Mar 16 '13 at 02:19
  • @cHao Thank you mate, I understood what IDs are..I changed it! ...thanx – ZameerMoh Mar 16 '13 at 02:32

2 Answers2

1

If you just want to have each looped output display in a single line, you were nearly there.

Add the following to CSS; and you're done.

h3 > div {
    display: inline-block;
}

It'll generate the output as this fiddle.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

If I understand what you're asking... this will combine your loops:

 for ($i = 0; $i < 23; $i++) {
   echo "<div id=slotshead></div>";
   for ($j = 0; $j < 30; $j++) {
     echo " <div id=slots></div>";
   }
 }
 echo '<br>';
Aiias
  • 4,683
  • 1
  • 18
  • 34
  • I need slothead to be at first. e.g [slothead][slot][slot][slot][slot]
    [slothead][slot][slot][slot][slot]
    – ZameerMoh Mar 16 '13 at 02:13
  • Edited and moved the `
    ` outside of the loops. What kind of output are you expecting? (Where should the `
    `s be?)
    – Aiias Mar 16 '13 at 02:15