Jump to content

What would be a better way to do this?


joecooper

Recommended Posts

Basically its a while loop that generates a table from a mysql database. The database has 100 rows, each new row will have a new number under "row".

 

The problem is that to display the colours of the cells that is stored in the mysql database, i have to set the cell background colour cell by cell. which when i try making a larger table (1000x1000) the page size is like 2MB big (too big for most users).

 

Is there a better way anyone could see of doing this?

 

(Please note that its not just the cell colour, its the mouse over title and other things but i have taken them out to make things more simple.)

 

<table border="1" cellpadding="0" cellspacing="0">
<?
while ($row = mysql_fetch_assoc($query)){     //with each entry, run the code below. $i will equal the id. (i think!)

if($state=="0"){    //if the state is "0" (if the square hasnt yet been clicked...)
    $cellcolour="F0F6FF";  //hasnt been clicked, show light blue
}else{
               //THE BELOW IF COMMAND IS JUST CHECKING SOME STUFF FROM THE DATABASE TO PUT IN THE CELLS

    if($row['status']=="0"){     //if the cell is a normal one with no win
        $cellcolour= "3D8BFF";   //blue
    }elseif($row['status']=="1"){    //if the cell is a winning one
        $cellcolour="8BFF3D";  //green
    }
?>


<td BGCOLOR="#<? echo "$cellcolour"; ?>" title="<? echo "$title";?>" width="10" height="10" nowrap="nowrap"><a style="line-height:.75em;width:100%;height:100%;display:block;" href="index.php?row=<? echo "{$row['row']}"; ?>&col=<? echo "{$row['column']}"; ?>"></a></td>

<?
$i++;
}
?>

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/
Share on other sites

Could clean up your php code a bit, but that won't really help on your html output.  I suggest looking into making a style sheet (CSS).  You can use CSS to assign colors, attributes, dimensions...pretty much anything, and then replace all that stuff in your tags with a simple id='blah' or class='blah'.  That should significantly reduce your filesize. 

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.