So i am trying to increment the $i in the actual call if that makes sense, please look at the code to understand:
<?php
for ($i=0; $i < 8 ; $i++) { ?>
<td><img src="http://ddragon.leagueoflegends.com/cdn/6.6.1/img/item/<?php echo $game->stats->item.$i; ?>.png"></img></td>
<?php }
?>
essentially what i need to do is increment it like follows:
$game->stats->item1
$game->stats->item2 etc..
Try it like this:
<?php
for ($i = 0; $i < 8 ; $i++) {
?>
<td>
<img src="http://ddragon.leagueoflegends.com/cdn/6.6.1/img/item/<?php echo $game->stats->{'item' . $i}; ?>.png" />
</td>
<?php
}
?>
Related
this is the sample logic i want to use.
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
this is my sample code. i'm just getting the logic from numbers so i can use to to what i want to display. thank you in advance to those who can help me.
<?php
$counter = 0;
$columnctr = 0;
for ($x = 0; $x <= 4; $x++) :?>
<tr>
<?php for ($j = 0; $j <= 17; $j++) :?>
<?php if($counter == $x) : ?>
<?php
$i = 0;
?>
<?php foreach ($iterator as $val) :?>
<?php if($x == $i) : ?>
<td>
<?php if($val == "meron") : ?>
<span class="circle-blue">
</span>
<?php $counter++;?>
<?php else : ?>
<span class="circle-red">
</span>
<?php $counter++;?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php $i++;?>
<?php endforeach;?>
<?php else : ?>
<td>
</td>
<?php endif; ?>
<?php endfor;?>
</tr>
$total = 20;
$totalRow = 5;
$totalCol = ceil($total/$totalRow);
echo '<pre>';
for($x = 1; $x <= $totalRow; $x++){
for($y=1; $y <= $totalCol; $y++){
$number = $x + (($y -1) * $totalRow);
// don't print extra number for last column, check for $total = 21 or 22
if($number <= $total)
echo $number. ' ';
}
echo PHP_EOL;
}
for($i=1;$i<=5;$i++):
$f = 0;
for($j=$i;$j < ($i+4) ; $j++ ):
if($f == 0):
echo $j." ";
$p = $j;
else:
echo $p = ($p + 5)." ";
endif;
$f = 1;
endfor;
echo "<br/>";
endfor;
I need to fill a 10x10 html table using php code with a random number from 1-10 rand(1,10), then depending on the result paint the cell red if <5 or green if >5. i manually created 10 rows with 10 td each and inside I put echo(rand(1,10)) for each one of them but my syntax is wrong and it looks gross
<table>
<tbody>
<?php for ($i = 0; $i < 10; $i++) : ?>
<tr>
<?php for ($k = 0; $k < 10; $k++) : ?>
<?php $num = rand(1, 10); ?>
<td style="color: <?= $num < 5 ? 'red' : 'green'; ?>"><?= $num; ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</tbody>
</table>
I am Having an issue in my for loop using PHP, I want to create dynamic row and column, Each row has 10 column after 10 column, the second row also end with 10 column like this up to 5 row, how to do It for a loop.
My for loop code:
<table width="100%" border="1">
<?php
for($i=1; $i<=72; $i++)
{
?>
<tr>
<td width="100%">
<?php echo "Click Here to see Site No.'".$i."'. & Area sqft No" .$i;?></a></td>
</tr>
<?php
}
?>
</tr>
</table>
I tried like this also
<table width="100%">
<tr>
<?php
for($i=1; $i<=72; $i++)
{
$x = 10;
if ($i % $x == 0)
{
?>
<td><?php echo $i;?></td>
<?php
}
}
?>
</tr>
</table>
<?php
echo '<table width="100%" border="1">';
for($i=1; $i<=8; $i++)
{
$y=10;
$y*=($i-1);
echo '<tr>';
for ($x=1; $x <=10; $x++) {
if ($i==1) {
echo '<td>'.$x.'</td>';
}else{
$y+=$x;
echo '<td>'.$y.'</td>';
if ($y==72) {
break;
}
$y-=$x;
}
}
echo '</tr>';
}
echo '</table>';
This will print the bellow table:
As per what I understand you want simple 10 column in each row.
Here is my code which may help you:
<table style="border:1px solid #000">
<tr>
<?php $t=1; for($k=1;$k<=72;$k++){?>
<?php if($t == 10) { $t=0;?><td style="border:1px solid #000"> <?php echo $k; ?> </tr><?php } else {?><td style="border:1px solid #000"> <?php echo $k; ?></td><?php } ?>
<?php $t++;}?>
<?php $x = 10; if ($i % $x == 0) { ?>
....
<?php } ?>
If I am getting the question correct, why don't you do as below:
echo '<table>';
for($i=1; $i<=5; $i++) {
echo '<tr>';
for ($y=1; $y<=10; $y++) {
echo '<td>Row_'.$i.' - Col_'.$y.'</td>';
}
echo '</tr>';
}
echo '</table>';
It will print something like below:
I don't even have an idea of where to start for this. I need to display 100 numbers in a table and would like to use a while loop to do so. Is there a "shortcut" to doing this?
For a table you need some tags table, tr and td. The tr and td are in while loop and the value $i will print inside the td.
<table>
<?php
$i = 1;
while($i != 101){?>
<tr><td><?php echo $i++;?></td></tr>
<?php }?>
</table>
You can use while, for, foreach for your convenience, like below code
<table>
<thead>
<tr>
<th class="header">Number</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($i != 101){
?>
<tr>
<td><?php echo $i; ?></td>
</tr>
<?php
$i++;
} ?>
</tbody>
</table>
You can dipslay 100 numbers simply in tbale like this:
<?php
// Using For loop
echo "<table>";
for ($i = 1;$i <= 100; $i++) { // use for loop
echo "<tr><td>".$i."</td></tr>";
}
echo "</table>";
// OR
// Using while loop
$i = 1;
echo "<table>";
while($i <= 100) {
echo "<tr><td>".$i."</td></tr>";
$i++;
}
echo "</table>";
?>
You can use a while loop:
while ($i <= 100) {
echo "<td><tr>" . $i++ . "</tr></td>";
}
My code is
<center>
<?php
for($i = 0; $i < 7 ; $i++) {
for($j = 0; $j < $i; $j++) {
echo "*";
}
echo "<br/>";
}
?>
<center>
But I want is pyramid with useing <center></center> html tags.
You're looking for something like this:
<div class="text-center"><!-- or however you choose to center this -->
<?php
$w = 7;
for ($n = 0; $n < $w; $n++) {
echo str_repeat("-", $n) . "<br>";
}
?>
</div>
<?php
int k =0;
for($i=1;$i<=20;$i++){
for(a=1;a<=20;$a++){
echo " ";
}
while(k!=(2*i-1){
echo "* ";
k++;
}
k=0;
echo "\n";
}
?>