Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/198587-really-basic-question/
Share on other sites

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.

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

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

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.';
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.