Jump to content

help with code


MDanz

Recommended Posts

i've added a count to each cell. so each column it counts the cells.  the problem is the count resets on another row.  how do i fix this?

 

e.g.

12345

12345  ...

 

when it should be..

 

12345

678910

 

you can run the code below and see what i mean.

 

<?php

$width = 1024;
$height = 768;

$rows2=$height/250;
$cols2=$width/120;


$rows=round($rows2,0);
$cols=round($cols2,0);


echo "<br />$rows $cols";

echo "<table border='1' bordercolor='#000000' cellspacing='3' >\n";
// $i=1 means 1 row. so for every $rows equal or greater than $i, add another row.
for($i=1;$i<=$rows;$i++) {

echo "<tr>\n";

// $j=1 means 1 column. so for every $cols equal or greater than $j, add another column.
for($j=1;$j<=$cols;$j++) {

echo "<td width='101px' height='101px' >$j</td>\n";


}


echo "</tr>\n";

}
echo "</table>\n";

?>

Link to comment
https://forums.phpfreaks.com/topic/197966-help-with-code/
Share on other sites

echo "<td width='101px' height='101px' >$j</td>\n";

 

in that line you should use a different variable instead of $j because $j will always reset to one

 

you could have a code there

for($j=1;$j<=$cols;$j++) {
echo "<td width='101px' height='101px' >$counter</td>\n";
$counter++;
}

 

you should declare the $counter variable outside the loops

Link to comment
https://forums.phpfreaks.com/topic/197966-help-with-code/#findComment-1038800
Share on other sites

i need some help fixing this part... i've made the td id the counter, which works. 

 

In mysql i have a column named position. For this particular row in mysql the position is 1.

 

how do i input this result into the td id='1'?

 

i tried below but it for obvious reasons it didn't work. 

 

how do i match the td id with the mysql result?

 

 

<?php
$width = 1024;
$height = 768;

$rows2=$height/250;
$cols2=$width/120;


$rows=round($rows2,0);
$cols=round($cols2,0);


echo "<br />$rows $cols";
$counter = 0;

$position = 1;
$table = "SELECT * FROM `Stacks` WHERE origin='$position'";
$found = mysql_num_rows(mysql_query($table));
if ($found==0){
$template = "<img src='empty.jpg' />";
} else {
$template = "";

}

echo "<table border='1' bordercolor='#000000' cellspacing='3' >\n";

// $i=1 means 1 row. so for every $rows equal or greater than $i, add another row.
for($i=1;$i<=$rows;$i++) {

echo "<tr>\n";

// $j=1 means 1 column. so for every $cols equal or greater than $j, add another column.
for($j=1;$j<=$cols;$j++) {
echo "<td width='101px' height='101px' id='$counter'>$template</td>\n";
$counter++;
}


echo "</tr>\n";

}

echo "</table>\n";


?>

Link to comment
https://forums.phpfreaks.com/topic/197966-help-with-code/#findComment-1038811
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.