joecooper Posted October 18, 2008 Share Posted October 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/ Share on other sites More sharing options...
.josh Posted October 18, 2008 Share Posted October 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/#findComment-668446 Share on other sites More sharing options...
xtopolis Posted October 18, 2008 Share Posted October 18, 2008 Also, you could paginate the results to reduce size. Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/#findComment-668468 Share on other sites More sharing options...
joecooper Posted October 22, 2008 Author Share Posted October 22, 2008 Thanks for your replys. All the data will be in a 100x100 grid, so all needs to be displayed. Ill look into CSS. I think i will hit real problems if i attempt the 1000x1000 grid i had hoped for! Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/#findComment-671591 Share on other sites More sharing options...
.josh Posted October 22, 2008 Share Posted October 22, 2008 dunno what you really need this grid for, but perhaps just using the gd library to generate an image would work? Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/#findComment-671699 Share on other sites More sharing options...
PFMaBiSmAd Posted October 22, 2008 Share Posted October 22, 2008 You already have a thread on this, why not read the replies posted in it - http://www.phpfreaks.com/forums/index.php/topic,220628.0.html Quote Link to comment https://forums.phpfreaks.com/topic/128917-what-would-be-a-better-way-to-do-this/#findComment-671735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.