Reputation: 1237
I am struggling with one form I am building. I want to show a drop down of events which fulfil two conditions:
Unfortunately, I only manage to show the first instance of the list, as opposed to all of them. I know for certain that the system "sees" the others as if I order the results DESC, it'll show me the last one.
The first query, for $compcheck
, checks all the competitions that are active for a certain user. Competitions range from 1 to 5, and any user can be active in as many as he likes.
The problem occurs when trying to define the <options>
in the drop down. I thought that by putting it into the while, it'd do that for each of the results found in $compcheck
but it won't do it.
It's not that easy to explain either! This is at least my fourth re-write of the code (if anything, it streamlined it a lot).
$compcheck = mysql_query("SELECT competition FROM RCO_contracts WHERE partB='$UserID' AND state='A'");
$numrows = mysql_num_rows($compcheck);
if($numrows = 0)
{
echo "You are not participating in any competition at the moment.";
}
else
{
$yesterday = $day-1;
echo "<form action='$RKP/kernel/lib/php_lib/action/AC_Appeals_Add.php?op=add_appeal&id=$UserID' method='post'>";
MODW_Buttons_Select(Normal,UAdminSelUser,RCO_users,completename,id,completename,False,False,$UserID,$do,$RKP);
echo "<select name='event'>";
while($row=mysql_fetch_row($compcheck))
{
$comp = "$row[0]";
$complabel = mysql_query("SELECT competition FROM DCO_competitions WHERE id='$comp'");
while($row=mysql_fetch_row($complabel))
{
$compname = "$row[0]";
}
$calendarlist = mysql_query("SELECT id, event, category FROM DCO_calendar WHERE category='$comp' AND (day='$day' OR day='$yesterday') AND month=$month AND year=$year");
while($row=mysql_fetch_row($calendarlist))
{
$event_id = "$row[0]";
$event_name = "$row[1]";
echo "<option value='$event_id'>$compname $event_name</option>";
}
echo "</select>";
}
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //lap
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //timestamp
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //textarea
MODW_Buttons_Button(Normal,Normal,Normal,Normal,None,$RKP,$id,BGenSu,$intern,$intcont);
echo "</form>";
}
Upvotes: 3
Views: 167
Reputation: 2343
you were also closing </select>
after each occurrence of the user (it's worth checking source code of the page php script has produced) - your query weren't for each occurrence of competition. try this:
if($numrows == 0)
{
echo "You are not participating in any competition at the moment.";
}
else
{
$yesterday = $day-1;
echo "<form action='$RKP/kernel/lib/php_lib/action/AC_Appeals_Add.php?op=add_appeal&id=$UserID' method='post'>";
MODW_Buttons_Select(Normal,UAdminSelUser,RCO_users,completename,id,completename,False,False,$UserID,$do,$RKP);
echo "<select name='event'>";
while($row=mysql_fetch_row($compcheck))
{
$comp = "$row[0]";
$complabel = mysql_query("SELECT competition FROM DCO_competitions WHERE id='$comp'");
while($row=mysql_fetch_row($complabel))
{
$compname = "$row[0]";
$calendarlist = mysql_query("SELECT id, event, category FROM DCO_calendar WHERE category='$comp' AND (day='$day' OR day='$yesterday') AND month=$month AND year=$year");
while($row=mysql_fetch_row($calendarlist))
{
$event_id = "$row[0]";
$event_name = "$row[1]";
echo "<option value='$event_id'>$compname $event_name</option>";
}
}
echo "</select>";
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //lap
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //timestamp
MODW_Buttons_Input(Normal,Normal,UPerRegTeamWeb,$lang,$link,False,$UserID); //textarea
MODW_Buttons_Button(Normal,Normal,Normal,Normal,None,$RKP,$id,BGenSu,$intern,$intcont);
echo "</form>";
}
Upvotes: 1
Reputation: 32681
if($numrows = 0)
You have a missing equals-sign here.
Additionally you should not put variables into a string to reassign them. Simply use $comp = $row[0]
When you want to insert Variables into a string you should concatenate them with a dot ("abc".$comp."def")
), it is easier to read and less error-prone.
Normal
I don´t think you have a constant called Normal, you probably wanted a string.
Correcting these errors will help to find the problem (when it does not solve it). For developing always use error_reporting(E_ALL)
to see all the errors and notices.
Edit: In HTML you should double quotes around your attributes, single quotes are a bad style.
Upvotes: 4