RE: [PHP-DB] Selecting Drop Down Value From DB to Edit

2002-03-27 Thread Rick Emery

I'm trying to decipher:
when I select the record to edit the drop-downlist has
the first option as the value instead of what the corresponding
StateID in  
the column reads. How can I correct this? The form to insert and
edit have
the below code and correctly insert the StateID

What exactly is happening?  Run the script, do a View Source on the
resulting page; show us the HTML generated.

-Original Message-
From: Steve Fitzgerald [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 26, 2002 5:22 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Selecting Drop Down Value From DB to Edit


I have the below code that populates a drop down list. The code will
correctly insert the value $StateID into another a table. The problem I am
running into is that when I select the record to edit the drop-downlist has
the first option as the value instead of what the corresponding StateID in
the column reads. How can I correct this? The form to insert and edit have
the below code and correctly insert the StateID. I tried to write and if
statement to state that if the StateID were == to the StateID in he table
then print selected, but I think I am missing something.

Any suggestions?

Thanks.

?php

// populates state drop-down list

$get_stateid_query = mysql_query(SELECT * FROM State INNER JOIN RaceResults
ON State.StateID WHERE RaceID='$RaceID');

echo  select name=\StateID\\n;

while ($myrow = mysql_fetch_array($get_stateid_query)) {

echo ' option
value='.$myrow[StateID].''.$myrow[StateName]./option\n;
}
echo  /select\n;
?



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Selecting Drop Down Value From DB to Edit

2002-03-27 Thread Dan Harrelson

If I understand your question, when editing an existing record where
StateID = CA, you want the drop-down to show California as
selected.

You need to add a little code into your while loop to echo SELECTED
into the appropriate option tag.

-Dan


--- Steve Fitzgerald [EMAIL PROTECTED] wrote:
 I have the below code that populates a drop down list. The code will
 correctly insert the value $StateID into another a table. The problem
 I am
 running into is that when I select the record to edit the
 drop-downlist has
 the first option as the value instead of what the corresponding
 StateID in
 the column reads. How can I correct this? The form to insert and edit
 have
 the below code and correctly insert the StateID. I tried to write and
 if
 statement to state that if the StateID were == to the StateID in he
 table
 then print selected, but I think I am missing something.
 
 Any suggestions?
 
 Thanks.
 
 ?php
 
 // populates state drop-down list
 
 $get_stateid_query = mysql_query(SELECT * FROM State INNER JOIN
 RaceResults
 ON State.StateID WHERE RaceID='$RaceID');
 
 echo  select name=\StateID\\n;
 
 while ($myrow = mysql_fetch_array($get_stateid_query)) {
 
 echo ' option
 value='.$myrow[StateID].''.$myrow[StateName]./option\n;
 }
 echo  /select\n;
 ?
 
 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Selecting Drop Down Value From DB to Edit

2002-03-27 Thread Steve Fitzgerald

This is the entire code for the page edit_race.php

?php

// editrace.php - edit race results

?
?php

// includes
 include(../includes/config.php);
 include(../includes/functions.php);

// open database connection
  $connection = mysql_connect($host, $user, $pass) or die (Unable to
connect!);

// select database
  mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
  $get_raceresults_query = SELECT * FROM RaceResults WHERE RaceID =
'$RaceID';
  $get_raceresults_result = mysql_query($get_raceresults_query) or die
(Error in query: $get_raceresults_query.  . mysql_error());

// if a result is returned
if (mysql_num_rows($get_raceresults_result) 0)

 // turn it into an object
 $row = mysql_fetch_object($get_raceresults_result);

?

html
head
titleRace Results: Edit Race Results/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
link rel=stylesheet href=../css/styles.css type=text/css
script language=javascript src=../scripts/CascadeMenu.js/script
script language=JavaScript src=../scripts/ts_picker4.js/script/head

body OnLoad=InitMenu() Onclick=HideMenu(menuBar) ID=Bdy
bgcolor=#FF text=#00 topmargin=0 leftmargin=0
marginwidth=0 marginheight=0

form action=do_editrace.php method=POST enctype=multipart/form-data
  table width=799 border=0 cellpadding=0 cellspacing=0
bgcolor=#ff
tr
  td width=339 height=112 valign=top
bgcolor=#0066ccnbsp;/td
  td width=460 valign=top rowspan=2
?php include (../includes/nav.php3);?


input type=hidden name=RaceID value=?php echo $RaceID; ?


  /td
/tr
tr
  td height=16/td
/tr
tr
  td height=12/td
  td/td
/tr
  /table
  table width=800 border=0 cellpadding=0 cellspacing=0
tr
  td width=10 bgcolor=#ff height=25
  td valign=middle colspan=2 class=raceresutlstitle
bgcolor=#ffAdmin
gt; Add a Race/td
  /tr
tr
  td width=10 bgcolor=#CC
  td width=131 valign=middle height=25 class=raceresutlstitle
bgcolor=#CCRace
Date:/td
  td width=660 valign=middle bgcolor=#CC
input type=Text name=RaceDate value=?php echo $row-RaceDate; ?
/td
/tr
tr
  td width=10
  td valign=middle height=25 class=raceresutlstitleRace
Name:/td
  td valign=middle
input type=text name=RaceName value=?php echo $row-RaceName;
?
  /td
/tr
tr
  td width=10 bgcolor=#CC
  td valign=middle height=25 class=raceresutlstitle
bgcolor=#CCRace
Distance:/td
  td valign=middle bgcolor=#CC

?php

// populates race distance drop-down list

$get_racedistid_query = mysql_query(SELECT * FROM RaceDistance INNER JOIN
RaceResults ON RaceDistance.RaceDistID WHERE RaceID='$RaceID');

echo  select name=\RaceDistID\\n;

while ($myrow = mysql_fetch_array($get_racedistid_query)) {

echo ' option
value='.$myrow[RaceDistID].''.$myrow[RaceDistName]./option\n;
}
echo  /select\n;
?

  /td
/tr
tr
  td width=10
  td valign=middle height=25 class=raceresutlstitleRace Type:


/td
td valign=middle class=newstxt



?php

// populates race type drop-down list

$get_racetypeid_query = mysql_query(SELECT * FROM RaceType INNER JOIN
RaceResults ON RaceType.RaceTypeID WHERE RaceID='$RaceID');

echo  select name=\RaceTypeID\\n;

while ($myrow = mysql_fetch_array($get_racetypeid_query)) {

echo ' option
value='.$myrow[RaceTypeID].''.$myrow[RaceTypeName]./option\n;
}
echo  /select\n;
?
/td
/tr
tr
  td width=10 bgcolor=#CC
  td valign=middle height=25 class=raceresutlstitle
bgcolor=#CCRace
Time:/td
  td valign=middle bgcolor=#CC span class=hdtxtHH
input type=text name=RaceTimeHH size=2 maxlength=2
value=? echo $row-RaceTimeHH; ??php if ($row-RaceTimeHH ==0) print
0;?
MM
input type=text name=RaceTimeMM size=2 maxlength=2
value=?php echo $row-RaceTimeMM; ?
SS
input type=text name=RaceTimeSS size=2 maxlength=2
value=?php echo $row-RaceTimeSS; ?
/span/td
/tr
tr
  td width=10
  td valign=middle height=25 class=raceresutlstitleRace
Pace:/td
  td valign=middle span class=hdtxt MM
input type=text name=RacePaceMM size=2 maxlength=2
value=? echo $row-RacePaceMM; ?
SS
input type=text name=RacePaceSS size=2 maxlength=2
value=? echo $row-RacePaceSS; ?
/span/td
/tr
tr
  td width=10 bgcolor=#CC
  td valign=middle height=25 class=raceresutlstitle
bgcolor=#CC#
of Comp.:/td
  td valign=middle bgcolor=#CC
input type=text name=RaceNumbComp value=?php echo
$row-RaceNumbComp; ?
  /td
/tr
tr
  td width=10 bgcolor=#ff
  td valign=middle height=25 class=raceresutlstitle
bgcolor=#ffRace
Place:/td
  td valign=middle bgcolor=#ff
input type=text name=RacePlace value=?php echo
$row-RacePlace; ?
  /td
/tr
tr
  td width=10 bgcolor=#cc
  td valign=middle