almightyegg Posted April 3, 2008 Share Posted April 3, 2008 Each player has a plot of land. Then each player can plant 5 different crops at one time. I've used GD library to draw the image of the land which works fine. my table is like this: id code1 start1 fin1 time1 code2 start2 fin2 time2 code3 start3 fin3 time3 code4 start4 fin4 time4 code5 start5 fin5 time5 The codes are the codes of items that they have planted, time is the time of planting, start is on which square of the plot of land the crop starts and fin is on which square the plot of land the crop ends. My problem is this, I'm not sure how to find out which squares aren't in use using the start and finish columns. I just can't get my head around it, any ideas would be greatly received Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/ Share on other sites More sharing options...
trq Posted April 3, 2008 Share Posted April 3, 2008 Nothing to do with your actual issue, but you really need to look into database normalization. Theres a link in my signiture to a free php book/wiki. Within that is an entire chapter devoted to the subject. Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508343 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 I'll have a look into it :-) the page is tsaking ages to load atm. Do you have anyideas how it could be done? Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508350 Share on other sites More sharing options...
laffin Posted April 3, 2008 Share Posted April 3, 2008 as thorpe suggested use normalization seperate the plots of land into there own db. TABLE ( userid position crop end_time ) KEY `userplot` (userid,position) than ya can grab userid and position from the table. and build a positional array. $res=mysql_query("SELECT position WHERE userid=$uid") while($row=mysql_fetch_row($res)) { $plots[$row[0]]=true; } notice that the position of the crop is not a value. thus making a simple check if a plot is used by if(isset($plots[5])) echo "Plot 5 is used"; else echo "Plot 5 is not used"; Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508362 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 Right, with the whole finding out what's in use thing: Your land is 15 by 15 squares. and the crops are planted as such: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ... etc... crop1 = somevalue start1 = 1 fin1 = 5 That means that land squares 1 to 5 are in use. crop2 = somevalue start3 = 6 fin4 = 19 That means that land squares 6 - 19 are in use From this I need to find out which squares aren't in use And I'll look into this normalizing thing Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508375 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 Sorry to have to bump this Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508520 Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Author Share Posted April 3, 2008 Right I'll explain it in more detail because I think I've confused you on exactly what I want... This is an example table row: id = 1 code1 = mugh start1 = 1 fin1 = 25 code2 = fevh start2 = 26 fin2 = 144 code3 = wolh start3 = 156 fin3 = 200 code4 = NULL time4 = NULL start4 = NULL fin4 = NULL code5 = wilh start5 = 224 fin5 = 225 Crop 1 has squares 1-25 filled - meaning 25 squares in total. Crop 2 has squares 26-144 filled - meaning 119 squares in total. Crop 3 has squares 156-200 filled - meaning 45 squares in total. Crop 4 - none. Crop 5 has squares 224-225 filled - meaning 2 squares in total. Now from this I can find out the total amount of free squares fine. What I want to do is find how many gaps there are and how big they are. From the above example it would find 2 gaps: $gap1 = 11; $gap2 = 23; Can anyone think of a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/99357-cant-get-my-head-around/#findComment-508627 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.