Forum Moderators: coopster
<?
// Connect to the MySQL database
$username="walkevent";
$password="#*$!#*$!";
$database="walkevent";
mysql_connect("localhost",$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$name = mysql_real_escape_string(htmlentities($_POST['name']));
$email = mysql_real_escape_string(htmlentities($_POST['email']));
$phone = mysql_real_escape_string(htmlentities($_POST['phone']));
$teamName = mysql_real_escape_string(htmlentities($_POST['teamName']));
$query = "CREATE TABLE $teamName (id int(6) NOT NULL auto_increment,name varchar(60) NOT NULL,email varchar(50) NOT NULL,phone varchar(15) NOT NULL,INDEX (id))";
$query = "INSERT INTO $teamName VALUES ('','$name','$email','$phone')";
mysql_query($QueryOne);
if(!mysql_error()) {
// Confirmation
} else {
}
mysql_query($query);
?>
$teamTableName = ereg_replace('[^A-Za-z0-9]', '',$_POST['teamTableName']); [edited by: DigitalSky at 8:54 am (utc) on Jun 1, 2010]
what I can to to make sure that if someone enters a team name like 'Jason's Team' it will instead use something like 'JasonsTeam'.
table for their team
$id=(isset($_GET['m']) and is_numeric($_GET['m']) and ($_GET['m']>0))?$_GET['m']:null;
if (! $id) { do_error_trap_here(); }
//
// set these to null, we'll only need them once and it's going to return multiple rows
$member_name=$teamname=$total=$results_rows=$out=null;
//
// Of course, use classes instead . . .
$lt = ' style="background:#fff"';
$dk = ' style="background:#f5f5f5"';
$hd = 'text-align:center;color:#fff;font-weight:bold;background:#000;';
//
$query = "select sum(amt_raised) as tot, members.fname,members.lname,
members.team_name,teams.t_fname,teams.t_lname,teams.amt_raised
from members,teams where members.id=teams.member_id and
members.id=$id order by teams.amt_raised desc, teams.t_lname asc,
teams.t_fname asc group by teams.member_id";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//
// alternate BG colors . . .
$bg = ($bg == $lt)?$dk:$lt;
if (! $member) { $member = $row['fname'] . ' ' . $row['lname']; }
if (! $teamname) { $teamname = $row['team_name']; }
if (! $total) { $total = $row['tot']; }
//
$results_rows .= '
<tr><td ' . $bg . ' nowrap>' . $row['t_fname'] . ' ' . $row['t_lname'] . '</td>
<td ' . $bg . ' nowrap> $' . $row['amt_raised'] . '</td></tr>
';
}
//
if ($results_rows) {
$out = '<table style="width: 400px; margin:auto;">
<tr><td colspan="2">Earnings for ' .
"$member of team: $teamname" .
'</td></tr>
<tr><td style="' . $hd . '">TEAM MEMBER</td>
<td style="' . $hd . '">EARNINGS</td></tr>' .
$results_rows .
'</table>
';
}
else {
// If there's no results, you'll have to do a new query here
// to get their name for output.
$out = '<p>Member ' . $member . ' has not yet assembled a team.</p>';
}
//
echo $out;
What will then happen is that other users (or friends of theirs) will be able to come to the site and opt to join any team of their choice (from a drop down list in a registration form).
$team_list = get_team_list('team_name'); // now just put $team_list in your form
//
function get_team_list($name) {
if (preg_match('/^[^a-z\_\-]$/i',$name)) { die("Invalid name passed to get team list"); }
//
$list = '<select name="' . $name . '" id="' . $name . '">
<option value="">Select Team</option>
';
//
$query = "select id,team_name,fname,lname from members order by
lname asc,fname asc, team_name asc";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$list .='<option value="' . $row['id'];
if (isset($_POST[$name]) and ($_POST[$name]==$row['id'])) {
// selected="selected" for XHTML types
$list .= ' selected';
}
$list .= '">' . $row['team_name'] . ' (' .
$row['fname'] . ' ' . $row['lname'] . ')</option>';
//you get: <option value="123">Flaming Tigers (John Doe)</option>
}
$list .= '</select>';
return $list;
}
$query="SELECT * FROM members";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$firstName=mysql_result($result,$i,"fname");
$lastName=mysql_result($result,$i,"lname");
$i++;
} <?php echo $firstName; ?> <?php echo $lastName; ?>
I tried this code but all it does is output the most recent row in that column.... Oh and obviously I'm outputting the data in my HTML using this line...
$query="SELECT * FROM members";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
$firstName=$row['fname']; // see note below
$lastName=$row['lname'];
echo "$firstName $lastName <br>";
}
require_once('includes/output.php'); <?php echo $firstName, $lastName; ?> On one of the pages I'm listing the members of each individual team. On another page I'm listing ALL of the names of the people who signed up (regardless of what team they're on).
BUT it does so in the upper corner of the screen.