You see how the repeated images on the right
they overlap the box and would like to make them appear only in groups of 6,. then move down 75 on each new row . This sounds like a solution for %
$x = 70;
foreach ($cb_result as $value) {
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo '<image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="225" width="20" height=""25 />';
echo "</a>";
echo "\r\n";
$x += 30;
}
produces the 1 row
$x = 70;
$image = 1;
$row = 1;
foreach ($cb_result as $value) {
if($image % 6 = 0) {
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo '<image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.(225 * $row).'" width="20" height=""25 />';
echo "</a>";
$row++;
} else {
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo '<image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.(225 * $row).'" width="20" height=""25 />';
echo "</a>";
}
echo "\r\n";
$x += 30;
$image++
}
Is this rignt?
I’m fond of using array functions when operating on sets of data -
<?php
// starting x
$x_start = 70;
// x increment
$x_inc = 30;
$y = 225;
// y increment
$y_inc = 75;
foreach(array_chunk($cb_result,6) as $chunk)
{
// start a new row
$x = $x_start;
// output the data for one row
foreach($chunk as $value)
{
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo '<image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.$y.'" width="20" height="25" />';
echo "</a>\r\n";
$x += $x_inc;
}
// finished a row, goto next row
$y += $y_inc;
}
Note: you had a closing "
in the wrong place on the height attribute.
1 Like
lurtnowski:
if($image % 6 = 0) {
I just get an error when I try the above line, until I change it to
if($image % 6 == 0) {
1 Like
I prefer not to even check for a zero result and use the positive remainder results of 1…5 to echo values and only add a line feed when the module is zero. Beware of the first module result
like this
$x = 65;
$image = 1;
$row = 1;
foreach ($cb_result as $value) {
if($image % 7 != 0) {
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo "\r\n";
echo ' <image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.(($row * 50) + 175).' " width="20" height="25" />';
echo "\r\n";
echo "</a>";
echo "\r\n";
$x += 30;
$image++;
} else {
$x = 65;
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo "\r\n";
echo ' <image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.(($row * 50) + 175).' " width="20" height="25" />';
echo "\r\n";
echo "</a>";
echo "\r\n";
$x += 30;
$row ++;
$image++;
}
}
cause its result is
<a xlink:href="../recepticles/show_recepticle.php?id=1" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Happy Boi<br>Trip Rating: 30 Amps">
<image href="../images/circuit_breaker_icon.png" x="65" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=2" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Snow White<br>Trip Rating: 77 Amps">
<image href="../images/circuit_breaker_icon.png" x="95" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=3" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Idiot<br>Trip Rating: 45 Amps">
<image href="../images/circuit_breaker_icon.png" x="125" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=4" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Redrum<br>Trip Rating: 55 Amps">
<image href="../images/circuit_breaker_icon.png" x="155" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=5" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Hungry Boi<br>Trip Rating: 30 Amps">
<image href="../images/circuit_breaker_icon.png" x="185" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=6" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Nathan Explosion<br>Trip Rating: 77 Amps">
<image href="../images/circuit_breaker_icon.png" x="215" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=7" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Bobs Burgers<br>Trip Rating: 45 Amps">
<image href="../images/circuit_breaker_icon.png" x="65" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=8" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Redrum<br>Trip Rating: 55 Amps">
<image href="../images/circuit_breaker_icon.png" x="95" y="275 " width="20" height="25" />
</a>
*I dont understand why when I went to the second row, it skips 65.
I think I found a solution
$x = 65;
$image = 1;
$row = 1;
foreach ($cb_result as $value) {
if($image % 8 != 0) {
} else {
$x = 65;
$row ++;
}
echo '<a xlink:href="../recepticles/show_recepticle.php?id='.$value['recepticle_id'].'" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="'.$value['title'].'<br>Trip Rating: '.$value['trip_rating'].' Amps">';
echo "\r\n";
echo ' <image href="../images/circuit_breaker_icon.png" x="'.$x.'" y="'.(($row * 50) + 175).' " width="20" height="25" />';
echo "\r\n";
echo "</a>";
echo "\r\n";
$image++;
$x += 30;
}
produces
<a xlink:href="../recepticles/show_recepticle.php?id=1" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Happy Boi<br>Trip Rating: 30 Amps">
<image href="../images/circuit_breaker_icon.png" x="65" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=2" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Snow White<br>Trip Rating: 77 Amps">
<image href="../images/circuit_breaker_icon.png" x="95" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=3" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Idiot<br>Trip Rating: 45 Amps">
<image href="../images/circuit_breaker_icon.png" x="125" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=4" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Redrum<br>Trip Rating: 55 Amps">
<image href="../images/circuit_breaker_icon.png" x="155" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=5" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Hungry Boi<br>Trip Rating: 30 Amps">
<image href="../images/circuit_breaker_icon.png" x="185" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=6" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Nathan Explosion<br>Trip Rating: 77 Amps">
<image href="../images/circuit_breaker_icon.png" x="215" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=7" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Bobs Burgers<br>Trip Rating: 45 Amps">
<image href="../images/circuit_breaker_icon.png" x="245" y="225 " width="20" height="25" />
</a>
<a xlink:href="../recepticles/show_recepticle.php?id=8" class="jqeasytooltip" data-tiptheme="tipthemewhite" data-tipcontent="Redrum<br>Trip Rating: 55 Amps">
<image href="../images/circuit_breaker_icon.png" x="65" y="275 " width="20" height="25" />
</a>
seems a little cumbersome, but looks right
Try this:
<?php declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', 'true');
echo '<b>Results: </b><br>';
for($i2=0; $i2<42; $i2++) :
if( $i2 % 6 || $i2===0) :
echo '$i2='.$i2 .' ';
else :
# if($i2):
echo '$i2='.$i2 .'<br><br>';
#endif;
endif;
endfor;
Output:
Results:
$i2=0 $i2=1 $i2=2 $i2=3 $i2=4 $i2=5 $i2=6
$i2=7 $i2=8 $i2=9 $i2=10 $i2=11 $i2=12
$i2=13 $i2=14 $i2=15 $i2=16 $i2=17 $i2=18
$i2=19 $i2=20 $i2=21 $i2=22 $i2=23 $i2=24
$i2=25 $i2=26 $i2=27 $i2=28 $i2=29 $i2=30
$i2=31 $i2=32 $i2=33 $i2=34 $i2=35 $i2=36
$i2=37 $i2=38 $i2=39 $i2=40 $i2=41
Please copy and paste the script, get it to run without errors then try adapting to your own project.
The position of any given box in an 6xY grid based on iteration I
is defined to be I % 6, floor(I / 6)
.
For an array of defined image HTML blocks $images, the code to add separators to them is simply:
implode("glue",array_chunk($images, 6))
EDIT: Except there’s a second layer, Marc.
echo implode("glue",array_map(array_chunk($images,6), function($x) { implode(" ",$x); }));
1 Like
system
Closed
February 17, 2021, 4:34pm
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.