PHP:HotelList

From Devicenull's Code

Jump to: navigation, search

I wrote this to let people keep track of who was staying at what hotel for a FIRST championship event. Pretty simple code

<?php
	error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
 
	$link = mysql_connect($sql_host, $sql_user, $sql_pass)
  		or die("Could not connect : " . mysql_error());
	mysql_select_db($sql_db,$link) 
		or die("Could not select database");
 
	if ($_POST['teamnum'] > 0) 
	{
		$newteam = round($_POST['teamnum']);
		$newhotel = mysql_escape_string($_POST['hotel']);
 
		mysql_query("INSERT INTO team_list VALUES($newteam,$newhotel)",$link);
		if (mysql_errno() > 0) echo 'An error occured: '.mysql_errno().' ('.mysql_error().')';
	}
	$res = mysql_query("SELECT * FROM team_list as TL LEFT JOIN hotel_list as HL on HL.hid=TL.hid ORDER BY TL.hid, team",$link);
	$hotels = array();
	while ($row = mysql_fetch_array($res))
	{
		$hotels[$row['hid']]["name"] = $row['hName'];
		array_push($hotels[$row['hid']],$row['team']);
	}
 
	echo '<table width="500px">';
	$c = 0;
	foreach ($hotels as $cur)
	{
		if ($c % 2 == 0)echo '<tr bgcolor="#CCCCCC">';
		else echo '<tr>';
		$c++;
		echo '<td><b>'.$cur['name'].':</b></td>';
		$out = '<td>';
		foreach ($cur as $teamnum) if (is_numeric($teamnum)) $out .= $teamnum.', ';
		$out = substr($out,0,strlen($out)-2).'</td></tr>';
		echo $out;
	}
	echo '</table>';
?>
 
<form action="list.php" method="POST">
Team number: <input type="text" size="5" name="teamnum"> will be at <select name="hotel">
<?php
	$res2 = mysql_query("SELECT * from hotel_list",$link);
	$count = mysql_num_rows($res2);
	for ($i=0;$i<$count;$i++) 
	{
		$row = mysql_fetch_array($res2);
		echo '<option value='.$row['hid'].'>'.$row['hName'].'</option>';
	}
?>
</select>
 ... <input type="submit" name="add" value="Add"></form>
Personal tools