Xzi Posted April 15, 2010 Share Posted April 15, 2010 Hi! im new to php and mysql and am having some trouble working out the best way to achieve a result. I apologise in advance as the the answer is probably so simple a child could figure it out but... i cant Anyway, i am wanting to make a VERY VERY basic queue'ing system for a 1v1 tournament for a game i play. There are two sides (GOOD side & BAD side) and the amount of people participating from each "side" will vary and will never be the same amount. All i want is that each player is able to type there name into a form and select which team they are on and then be added to a queue. Then be able to display the queue on a page. As each game is complete i will simply want to remove the 2 entries from the mysql database and the next 2 in the queue will display at the top. Now im not sure how my database schema should be setup, should i have a table for each side and record the timestamp when entering the the data and simply list it order by time stamp ? (eg: GoodTable & BadTable) or should i have one table to encapulate all the data ? any suggestions would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 From what I understand something like this should suffice, but I'm not 100% sure yet. I think 1 table should suffice for now. Have something like the following: id int not null auto-increment [Primary Key] name varchar(255) not null IsGood tinyint not null -- 1 = good, 0 = bad I think that's it. Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042078 Share on other sites More sharing options...
Xzi Posted April 15, 2010 Author Share Posted April 15, 2010 ah ok ty for the advice, i will have to include a "timestamp" column in that table. my next question is what would be the best way to display the table as follow's with php GoodTeam | Badteam Player1 | PlayerA Player2 | PlayerB So this would be displayed in the order in which the data was entered into the table (using the timestamp to work it out) To clarify on the question. This is a 1v1 type of tournament in which anyone can signup. i want this script so that anyone who wishes to participate can sign up and be put in a queue automatically which will match up players from "GoodTeam" with players from the "BadTeam" on a first in first served basis (eg: 1st "goodteam" signing up is matched with the 1st "badteam" signing up). Apologies in advance for making something simple so complicated to explain hehe Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042090 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 The table is really up to you, but what you have up there is fine. Including the timestamp would give you all the information you need. Any other questions? Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042093 Share on other sites More sharing options...
Xzi Posted April 15, 2010 Author Share Posted April 15, 2010 now the only problem is i dont have any idea on what sql query and php to use to display that information the way i want to. I am able to echo the table out and display it in order of timestamp ( with both teams mixed in together ). what i want tho is to display each team side by side in the same table and have it order by timestamp for each particular team like GoodSide | BadSide Player1 playerA player1 being the first to reg on the "GoodSide" and playerA being the first that registered and the "BadSide" and to continue until all records are displayed in order of timestamp relevant to each side. would it be easier to just have a WHERE clause in my sql statement to select on 1 team and then just display two tables side by side in html ? ideally i want all the information displayed in 1 table thankjs in advance again Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042104 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 It's pretty much just 2 select statements. One for good and one for bad. Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042110 Share on other sites More sharing options...
jcbones Posted April 15, 2010 Share Posted April 15, 2010 Try this. It may not be exactly what you are looking for, but should get you started in the general direction. Edit your $sql line for the right table and columns of course. <?php $sql = "SELECT * FROM `table` ORDER BY `timestamp` DESC"; $result = mysql_query($sql); if(mysql_num_rows($result)) { while($r = mysql_fetch_assoc($result)) { $side = ($r['IsGood'] == 1) ? 'Good' : 'Bad'; $arr[$side][] = $name; } $startGood = (is_array($arr['Good'])) ? 1 : 0; $startBad = (is_array($arr['Bad'])) ? 1 : 0; echo '<table border="1"><th>Good Team</th><th>Bad Team</th>'; if($startGood === 1) { foreach($arr['Good'] as $k => $v) { echo '<tr><td>' . $v . '</td>'; echo (isset($arr['Bad'][$k])) ? '<td>' . $arr['Bad'][$k] . '</td>' : '<td> </td>'; echo '</tr>'; } } elseif($startBad === 1) { foreach($arr['Bad'] as $k => $v) { echo '<tr><td> </td><td>' . $v . '</td></tr>'; } } else { die('Error.'); } echo '</table>'; } else { echo 'There are no players present.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042117 Share on other sites More sharing options...
Xzi Posted April 15, 2010 Author Share Posted April 15, 2010 Awesome thanks allot for the help its got me going in the right direction!!!! Quote Link to comment https://forums.phpfreaks.com/topic/198587-really-basic-question/#findComment-1042144 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.