Forum Moderators: coopster
Some background: $useraccount is the currently logged in user. I basically want to see if a user logged in has said they are attending a particular event. Depending on this, I want to show different code with my if statement. This is only working for one entry, basically the value of $userpar, never changes so the if argument end up being the same and all events below this one show the same chunk of code.
Is there anyway to pull a record without a while statement? I think this might help. I want to see if a user has a record with a particular ID. If I can keep checking this against different ID's I would be able to do what I am trying to accomplish. Any help is appreciated.
$result3 = mysql_query("SELECT DISTINCT gp_event_user FROM gp_event_users WHERE gp_event_id='" . $row['gp_id'] . "' AND gp_event_user='$useraccount'");while($check_row = mysql_fetch_array($result3))
{
$userpar = $check_row['gp_event_user'];
}
if ($userpar==$useraccount)
echo "<td class='events'><center><img src='stop.gif' onmousedown='ajaxRemovePar(" . $row['gp_id'] . ")' /></center></td>";
else
echo "<td class='events'><center><img src='go.gif' onmousedown='ajaxPar(" . $row['gp_id'] . ")' /></center></td>";
In the query, you are getting the distinct events of a user account. Your if condition will always be true, so I don't see the reason of having it. If you want to list the events by a certain user, you might need to select the events from the table. You seem to be doing what is already true in the sql statement again by the if and the loop.
Habtom
As far as the logic... With
gp_event_id='" . $row['gp_id'] . "' In this portion of the code $row['gp_id'] is an array within the body of a parent while statement, all the code I posted is in an while loop. The code checks if a users name is in a record for each $row['gp_id'], which is different for each row.
The below is an outline, don't need to check syntax of this, I'm just trying to give an idea of whats going on.
while($row = mysql_fetch_array($result))
{ --------------- ------------------ ---------------
¦....event ID....¦....event title....¦...participate?....¦
--------------- ------------------ ---------------
¦ $row['gp_id'] ¦ $row['gp_title'] ¦code in 1st post ¦
¦ $row['gp_id'] ¦ $row['gp_title'] ¦code in 1st post ¦
}
[edited by: JohnPorier at 12:51 pm (utc) on July 17, 2007]
If you're getting all the records from the database that are associated with this user wouldn't all the records you get meet the if condition? You're already filtering your results via SQL... no need to re-filter them with an if statement. Unless, of course, you're doing something we don't see here.
As for your original problem, the while statement you have as it is will never return more than one $userpar. The $userpar variable is overwritten with each loop of the while, and you're not doing anything with it before it gets overwritten. That's why the suggestion was made to put your if statement within the while... that way you're doing something with each new $userpar value before it is overwritten.
while($check_row = mysql_fetch_array($result3))
{
$userpar = $check_row['gp_event_user'];
// You need to do something with $userpar here.
}
If the query you've got is only supposed to return one result, you should do this:
$check_row = mysql_fetch_array($result3);
if(mysql_num_rows($check_row) < 1)
$userpar = '0'; // Or whatever you want for no participation
else
$userpar = $check_row['gp_event_user'];
Then your if statement will evaluate correctly (providing none of your accounts are number 0).