|
-
Jan 19th, 2011, 12:42 AM
#1
Thread Starter
Hyperactive Member
multiple of 22
If I want a <tr> to appear every 22 <td>s, including the 0 at, the beginning how is the if statement written?
-
Jan 19th, 2011, 01:05 AM
#2
Re: multiple of 22
Well, first off the only way I know of is to mix php and html which isn't really good practice. What are you trying to achieve?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jan 19th, 2011, 01:21 AM
#3
Thread Starter
Hyperactive Member
Re: multiple of 22
 Originally Posted by Nightwalker83
Well, first off the only way I know of is to mix php and html which isn't really good practice. What are you trying to achieve?
Code:
<tr>
<td></td>
x22
</tr>
<tr>
<td></td>
x22
</tr>
-
Jan 19th, 2011, 11:43 AM
#4
Fanatic Member
Re: multiple of 22
well if you could provide a bit code for us to work on, would make it a lot easier.
i have done this before, i made a seating plan for a lan-party, and used php to show the table seats.
i don't have access to the code on that site anymore so i can't really tell you how i did it.
-
Jan 19th, 2011, 12:19 PM
#5
Re: multiple of 22
You need a nested for-loop...?
PHP Code:
for($i=0;$i<=2;$i++){ echo '<tr>'; for($j=0;$j<=21;$j++){ echo '<td></td>'; } echo '</tr>'; }
-
Jan 19th, 2011, 04:42 PM
#6
Thread Starter
Hyperactive Member
Re: multiple of 22
 Originally Posted by SambaNeko
You need a nested for-loop...?
PHP Code:
for($i=0;$i<=2;$i++){ echo '<tr>'; for($j=0;$j<=21;$j++){ echo '<td></td>'; } echo '</tr>'; }
Ok here's what I have so far where everything fits fair and square:
PHP Code:
<table style="float: left; direction: rtl; text-align: left; padding: 5px;"> <tr> <?php //<th style="border: 1px solid black;"></th> for($i=0; $i<$skiprow; $i++){ $num=$i+1; echo "<th style=\"border: 1px solid black; font-size: 14px;\">".$num."</th>\n"; } ?> </tr> <?php $chap_letters= Array(); for($tdid=0; $tdid < count($id); $tdid++){ $strText=stripslashes(mysql_escape_string($textData[$tdid])); include("../includefiles/vowelmarks.php"); for($i=0; $i<count($vm); $i++){ $strText=str_replace($vm[$i], "", $strText); } for($i=0; $i<count($alephbet); $i++){ $strText=str_replace($alephbet[$i], $alphabet[$i], $strText); } $strText=str_replace(" ", "", $strText); $letters=str_split($strText); //print_r($letters); for($i=0; $i<count($letters); $i++){ $chap_letters[]=$letters[$i]; } } //print_r($chap_letters); for($i=0; $i<count($chap_letters); $i++){ $num=$i+1;//for the sake of the tr problem if($i==0){ echo "<tr>\n"; //echo "<td style=\"border: 1px solid black; font-size: 14px;\">".$num."</td>\n"; } $hebrew_font="font-family:'SBL Hebrew';"; $td="<td id=\"".$num."\" style=\"border: 1px solid black; font-size: 14px;".$hebrew_font."\">".$chap_letters[$i]."</td>\n"; for($j=0; $j<count($alephbet); $j++){ $td=str_replace(">".$alphabet[$j]."</", ">".$alephbet[$j]."</", $td); } echo $td; if($i!==0 && $num % $skiprow == 0){ echo "</tr>\n"; if($i<(count($letters)-1)){ echo "\n"; echo "<tr>\n"; //echo "<td style=\"border: 1px solid black; font-size: 14px;\">".$num."</td>\n"; } } } ?></table>
In html this is how it shows:
Code:
<table style="float: left; direction: rtl; text-align: left; padding: 5px;">
<tr>
<th style="border: 1px solid black; font-size: 14px;">1</th>
<th style="border: 1px solid black; font-size: 14px;">2</th>
<th style="border: 1px solid black; font-size: 14px;">3</th>
<th style="border: 1px solid black; font-size: 14px;">4</th>
<th style="border: 1px solid black; font-size: 14px;">5</th>
<th style="border: 1px solid black; font-size: 14px;">6</th>
<th style="border: 1px solid black; font-size: 14px;">7</th>
<th style="border: 1px solid black; font-size: 14px;">8</th>
<th style="border: 1px solid black; font-size: 14px;">9</th>
<th style="border: 1px solid black; font-size: 14px;">10</th>
<th style="border: 1px solid black; font-size: 14px;">11</th>
<th style="border: 1px solid black; font-size: 14px;">12</th>
<th style="border: 1px solid black; font-size: 14px;">13</th>
<th style="border: 1px solid black; font-size: 14px;">14</th>
<th style="border: 1px solid black; font-size: 14px;">15</th>
<th style="border: 1px solid black; font-size: 14px;">16</th>
<th style="border: 1px solid black; font-size: 14px;">17</th>
<th style="border: 1px solid black; font-size: 14px;">18</th>
<th style="border: 1px solid black; font-size: 14px;">19</th>
<th style="border: 1px solid black; font-size: 14px;">20</th>
<th style="border: 1px solid black; font-size: 14px;">21</th>
<th style="border: 1px solid black; font-size: 14px;">22</th>
</tr>
<tr>
<td id="1" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ב</td>
<td id="2" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ר</td>
<td id="3" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">א</td>
<td id="4" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ש</td>
<td id="5" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">י</td>
<td id="6" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ת</td>
<td id="7" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ב</td>
<td id="8" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ר</td>
<td id="9" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">א</td>
<td id="10" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">א</td>
<td id="11" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ל</td>
<td id="12" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ה</td>
<td id="13" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">י</td>
<td id="14" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">מ</td>
<td id="15" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">א</td>
<td id="16" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ת</td>
<td id="17" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ה</td>
<td id="18" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ש</td>
<td id="19" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">מ</td>
<td id="20" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">י</td>
<td id="21" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">מ</td>
<td id="22" style="border: 1px solid black; font-size: 14px; font-family: 'SBL Hebrew';">ו</td>
</tr>
...and so on
</table>
I want to add a td tag in the beginning of the opening tr tag with a incremental number: id ="td_1", id ="td_2", id ="td_3"...
Oops! I should place the id ="td_1" in the other td tags but this one simply 1, 2, 3...
Last edited by gilgalbiblewhee; Jan 19th, 2011 at 04:47 PM.
-
Jan 21st, 2011, 02:15 AM
#7
Re: multiple of 22
similar to Samba's, but one for loop utilizing modulus:
Code:
<table>
<?php
// Number of records
$count = 47;
// Loop through records
for($i = 0; $i < $count; $i++){
// Start a new row
if($i % 22 == 0){
echo ' <tr>' . "\n";
}
// Table data
echo ' <td id="td_' . ($i + 1) . '"></td>' . "\n";
// End a row
if(($i + 1) % 22 == 0 || ($i + 1) == $count){
echo ' </tr>' . "\n";
}
}
?>
</table>
While I do not suggest emitting HTML using PHP, this was simply an easy way to show you the logic behind what you're trying to do. This script will produce:
Code:
<table>
<tr>
<td id="td_1"></td>
<td id="td_2"></td>
<td id="td_3"></td>
<td id="td_4"></td>
<td id="td_5"></td>
<td id="td_6"></td>
<td id="td_7"></td>
<td id="td_8"></td>
<td id="td_9"></td>
<td id="td_10"></td>
<td id="td_11"></td>
<td id="td_12"></td>
<td id="td_13"></td>
<td id="td_14"></td>
<td id="td_15"></td>
<td id="td_16"></td>
<td id="td_17"></td>
<td id="td_18"></td>
<td id="td_19"></td>
<td id="td_20"></td>
<td id="td_21"></td>
<td id="td_22"></td>
</tr>
<tr>
<td id="td_23"></td>
<td id="td_24"></td>
<td id="td_25"></td>
<td id="td_26"></td>
<td id="td_27"></td>
<td id="td_28"></td>
<td id="td_29"></td>
<td id="td_30"></td>
<td id="td_31"></td>
<td id="td_32"></td>
<td id="td_33"></td>
<td id="td_34"></td>
<td id="td_35"></td>
<td id="td_36"></td>
<td id="td_37"></td>
<td id="td_38"></td>
<td id="td_39"></td>
<td id="td_40"></td>
<td id="td_41"></td>
<td id="td_42"></td>
<td id="td_43"></td>
<td id="td_44"></td>
</tr>
<tr>
<td id="td_45"></td>
<td id="td_46"></td>
<td id="td_47"></td>
</tr>
</table>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|