Jump to content

[SOLVED] Print record


hola hola

Recommended Posts

I feel stupid here...  I am updating my sports game report form and now do not want my drop down menu on the form.  I only want it to print "<?print $teamname;?>\n";

 

I and getting a horizontal list of the $teamname (s) associated with the respective $divname.

 

<b>Home Team</b>: <select name="winner">
<?php
$query2="SELECT s2010_teams.teamid, s2010_teams.teamname, s2010_divs.divname FROM s2010_teams, s2010_divs WHERE s2010_teams.active = 1 AND s2010_teams.teamdiv = s2010_divs.divid AND s2010_divs.conference = $confid ORDER BY divorder ASC, teamname ASC";
$result2=mysql_query($query2);

while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) {
	print "<option value=\"{$teams['teamid']}\"";

	if ($teams['teamid'] == $score['winner']) {
		print " selected=\"selected\"";
	}
	print ">{$teams['teamname']}</option>\n";
}
print "</select>\n";
?>

 

Please help!  My head hurts!  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/
Share on other sites

That is exactly what I am looking for...  Home Team: (The Respective Team) instead of the <Option> drop down menu with selected $teamname plus all teamnames of that division.  I thought I had it right and al getting:

Home Team: Team1 Team2 Team3 Team4 Team5 Team6

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/#findComment-920778
Share on other sites

well the code you posted doesn't do that at all. post the code that creates the output

Home Team: Team1 Team2 Team3 Team4 Team5 Team6

 

but it should look something like

while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) {
echo "Hometeam: ".$teams['teamname']."<br />";
}

 

assuming you wanted to precede each team name with the word Home Team

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/#findComment-920779
Share on other sites

This gets me the previously stated result.

 

<tr><td bgcolor='#FFFF00'><b>Home Team</b>: 
<?php
$query2="SELECT s2010_teams.teamid, s2010_teams.teamname, s2010_divs.divname FROM s2010_teams, s2010_divs WHERE s2010_teams.active = 1 AND s2010_teams.teamdiv = s2010_divs.divid AND s2010_divs.conference = $confid ORDER BY divorder ASC, teamname ASC";
$result2=mysql_query($query2);

while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) {
	print "<option value=\"{$teams['teamid']}\"";

	if ($teams['teamid'] == $score['winner']) {
		print " selected=\"selected\"";
	}
	print ">{$teams['teamname']}</option>\n";
}
print "</td><td bgcolor='#FFFF00'><b>Score:</b> <input type=\"text\" name=\"rf\" size=\"2\" maxlength=\"2\" value=\"{$score['rf']}\" /></td></tr>\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/#findComment-920785
Share on other sites

The Status was an example of another field that exists on the form.

 

Here is my full code:

case 'editscore':

$confid = intval($_GET['conf']);

$winid=$_POST['winid'];
$query="SELECT s2010_wins.status, s2010_wins.windate, s2010_wins.wintime, s2010_wins.wincomments, s2010_wins.teamcomments, s2010_wins.field, s2010_wins.field_no, s2010_wins.winner, s2010_wins.loser, s2010_wins.winortie, s2010_wins.rf, s2010_wins.ra, s2010_teams.teamname AS winningteam, s2010_teams2.teamname AS losingteam FROM s2010_wins, s2010_teams, s2010_teams AS s2010_teams2 WHERE s2010_wins.winid=$winid AND s2010_teams.teamid = s2010_wins.winner AND s2010_teams2.teamid = s2010_wins.loser";
$result=mysql_query($query);
$score = mysql_fetch_array($result, MYSQL_ASSOC);
$wincomments = str_replace('"','"',$score['wincomments']);
$wincomments = str_replace("'",'&#039;',$wincomments);
$teamcomments = str_replace('"','"',$score['teamcomments']);
$teamcomments = str_replace("'",'&#039;',$teamcomments);
$field = str_replace('"','"',$score['field']);
$field = str_replace("'",'&#039;',$field);
$status = str_replace('"','"',$score['status']);
$status = str_replace("'",'&#039;',$status);
$field_no = str_replace('"','"',$score['field_no']);
$field_no = str_replace("'",'&#039;',$field_no);
$month=date('m',$score['windate']);
$day=date('d',$score['windate']);
$year=date('Y',$score['windate']);
$hour=date('g',$score['wintime']);
$minute=date('i',$score['wintime']);
$ampm=date('a',$score['wintime']);
print "<form action=\"$report_page?action=updatescore&conf=$confid\" method=\"post\">\n";
?>
<table width='100%' class='tbl-border'>
<tr><td colspan='2' class='tbl1'><b>Status:</b> <?print $status;?></td></tr>
<tr><td colspan='2' class='tbl1'><b>Date:</b> <?print $month?>/<?print $day?>/<?print $year?></td></tr>
<tr><td colspan='2' class='tbl1'><b>Time:</b> <?print $hour?>:<?print $minute?> <?print $ampm?></td></tr>
<tr><td class='tbl1'><b>Field:</b> <?print $field;?></td><td class='tbl1'><b>Field No:</b> <?print $field_no;?></div></td></tr>

// Attempted to Change to remove the DROP DOWN Menu - UNSUCCESSFUL!

<tr><td class='tbl1'><b>Home Team</b>: 
<?php
$query2="SELECT s2010_teams.teamid, s2010_teams.teamname, s2010_divs.divname FROM s2010_teams, s2010_divs WHERE s2010_teams.active = 1 AND s2010_teams.teamdiv = s2010_divs.divid AND s2010_divs.conference = $confid ORDER BY divorder ASC, teamname ASC";
$result2=mysql_query($query2);

while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) {
	echo "" . $teams['teamname']."";
}
print "</td><td bgcolor='#FFFF00'><b>Score:</b> <input type=\"text\" name=\"rf\" size=\"2\" maxlength=\"2\" value=\"{$score['rf']}\" /></td></tr>\n";
?>
<tr><td colspan='2' align='center' bgcolor='#FFFF00'> <select name="winortie">
<option value="3"
<?php
if ($score['winortie'] == 3) {
echo 'selected="selected"';
}
?>
>Play - Scheduled
</option>
<option value="1"
<?php
if ($score['winortie'] == 1) {
echo 'selected="selected"';
}
?>
>Beat
</option>
<?php if ($forfeit) {
print "<option value=\"2\" ";
if ($score['winortie'] == 2)
print "selected=\"selected\"";
print ">Beat (by forfeit)</option>\n";
}
?>
<?php if ($show_ties) {
print "<option value=\"0\" ";
if ($score['winortie'] == 0)
print "selected=\"selected\"";
print ">Tied</option>\n";
}
?>
<option value="4"
<?php
if ($score['winortie'] == 4) {
print "selected=\"selected\"";
}
?>
>Lost to
</option>
<?php if ($forfeit) {
print "<option value=\"5\" ";
if ($score['winortie'] == 5)
print "selected=\"selected\"";
print ">Lost to (by forfeit)</option>\n";
}
?>
</select></td></tr>

//  Original version of Team Display in DROP DOWN MENU

<tr><td class='tbl1'><b>Visiting Team:</b> <select name="loser">
<?php
$query3="SELECT s2010_teams.teamid, s2010_teams.teamname, s2010_divs.divname FROM s2010_teams, s2010_divs WHERE s2010_teams.active=1 AND s2010_teams.teamdiv = s2010_divs.divid AND s2010_divs.conference = $confid ORDER BY divorder ASC, teamname ASC";
$result3=mysql_query($query3);
while ($teams = mysql_fetch_array($result3, MYSQL_ASSOC)) {
	echo "<option value=\"{$teams['teamid']}\"";
	if ($teams['teamid'] == $score['loser']) {
		print " selected=\"selected\"";
	}
	print ">{$teams['teamname']}</option>\n";
}
print "</select></td><td bgcolor='#FFFF00'><b>Score:</b> <input type=\"text\" name=\"ra\" size=\"2\" maxlength=\"2\" value=\"{$score['ra']}\" /></td></tr>\n";
?>
<tr><td colspan='2' class='tbl1'><b>Comments:</b> <input name="teamcomments" type="text" value="<?php print $teamcomments;?>" size="70">
<input type="hidden" name="winid" value=<?php print $winid;?>>
</td></tr>
<tr><td colspan='2' class='tbl1' align='center'><input type="submit" value="Update"></p>
</form>
<?php 
print "<form method=\"get\" action=\"$report_page\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"mainview\" />\n";
print "<input type=\"hidden\" name=\"conf\" value=\"$confid\" />\n";
print "<input type=\"submit\" value=\"Cancel\"></td></tr></table></form>\n";

 

You can see my attempted change in Home Team display.  Visiting Team display is not alterred and displays the drop down menu with the predetermined team selected.  I am still getting a list of the Division Teams in Home Team echo and only want to echo the selected team in text display.

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/#findComment-920830
Share on other sites

add an if statement inside the loop ?

   while ($teams = mysql_fetch_array($result2, MYSQL_ASSOC)) {
     if ($winid == $teams['teamid']) 
        echo "" . $teams['teamname']."";
}

 

although, I think I would just add AND teamid = $winid to the query rather than return and loop through a bunch of rows that are not used.

Link to comment
https://forums.phpfreaks.com/topic/174718-solved-print-record/#findComment-920842
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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