Jump to content

if statment and joining tables


conan318

Recommended Posts

Hi i need a little help with this if statement. i have a event calender when you change the month it displays each  event for that month and link to register for that event but if you are already registerd i want to display the remove me from the is event link.

i am not getting any errors but only displaying // and the remove me link

thanks


$data = mysql_query("SELECT * from main.mbadmin WHERE  mbadmin.month=$cMonth AND  mbadmin.year=$cYear  ORDER BY day  LIMIT 10;") or die(mysql_error());
    $queryuser=mysql_query("SELECT * FROM main.attending join main.mbadmin WHERE username='$myusername' and main.attending.id2=main.attending.username ");
//$result=mysql_query($sql);
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)


while($info = mysql_fetch_array( $data )) 
{ 


Echo "<table>";


Echo "<tr>";
echo"<td>";
Echo $info['day']."/" .$info['month']."/". $info['year'];
echo "</td>";
echo "</tr>";
Echo "<tr>";
echo"<td colspan='2'>";
Echo $info['nextride'] ; 

echo "</td>";
echo "</tr>";
echo "<tr>";
echo '<td><a href="attend.php?id=' . $info[0] . '" onClick=\'alert("you are now registerd for this event")\';>Register</a></td>';
echo "<hr colspan='2'>";
echo '<td><a href="" onClick=\'window.open("wattend.php?id=' . $info[0] . '", "window_name", "width=500, height=500")\';>Attening this event</a>';

echo "</td>";
echo "</tr>";

echo "</table>";
}else{
  $data = mysql_query("SELECT * from main.mbadmin WHERE  mbadmin.month=$cMonth AND  mbadmin.year=$cYear  ORDER BY day  LIMIT 10;") or die(mysql_error());
Echo "<table>";


Echo "<tr>";
echo"<td>";
Echo $info['day']."/" .$info['month']."/". $info['year'];
echo "</td>";
echo "</tr>";
Echo "<tr>";
echo"<td colspan='2'>";
Echo $info['nextride'] ; 

echo "</td>";
echo "</tr>";
echo "<tr>";
echo '<td><a href="attend.php?id=' . $info[0] . '" onClick=\'alert("you are now registerd for this event")\';>Remove me</a></td>';
echo "<hr colspan='2'>";
echo '<td><a href="" onClick=\'window.open("wattend.php?id=' . $info[0] . '", "window_name", "width=500, height=500")\';>Attening this event</a>';

echo "</td>";
echo "</tr>";

echo "</table>";

}

Link to comment
Share on other sites

ok ignore the first bit of code i posted it was totally wrong

in the attending table i have id, id2,username

 

when some registers for the event it puts the auto increment id from mbadmin table into attending.id2 along with the username

so i need to check weather my session username $myusername and attending id2 exist in the attending table if so echo the remove link if not echo the register link.  hope that make more sense lol

$data = mysql_query("SELECT * from main.mbadmin WHERE  mbadmin.month=$cMonth AND  mbadmin.year=$cYear  ORDER BY day  LIMIT 10;") or die(mysql_error());
    $queryuser=mysql_query("SELECT * FROM main.attending join main.mbadmin WHERE main.attending.username='$myusername' and main.attending.id2=main.attending.username ");
//$result=mysql_query($sql);
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)


while($info = mysql_fetch_array( $data )) 
{ 


Echo "<table>";


Echo "<tr>";
echo"<td>";
Echo $info['day']."/" .$info['month']."/". $info['year'];
echo "</td>";
echo "</tr>";
Echo "<tr>";
echo"<td colspan='2'>";
Echo $info['nextride'] ; 

echo "</td>";
echo "</tr>";
echo "<tr>";
echo '<td><a href="attend.php?id=' . $info[0] . '" onClick=\'alert("you are now registerd for this event")\';>Register</a></td>';
echo "<hr colspan='2'>";
echo '<td><a href="" onClick=\'window.open("wattend.php?id=' . $info[0] . '", "window_name", "width=500, height=500")\';>Attening this event</a>';

echo "</td>";
echo "</tr>";

echo "</table>";
}else{
  $data = mysql_query("SELECT * from main.mbadmin WHERE  mbadmin.month=$cMonth AND  mbadmin.year=$cYear  ORDER BY day  LIMIT 10;") or die(mysql_error());
while($info = mysql_fetch_array( $data )) 
{ 
Echo "<table>";


Echo "<tr>";
echo"<td>";
Echo $info['day']."/" .$info['month']."/". $info['year'];
echo "</td>";
echo "</tr>";
Echo "<tr>";
echo"<td colspan='2'>";
Echo $info['nextride'] ; 

echo "</td>";
echo "</tr>";
echo "<tr>";
echo '<td><a href="attend.php?id=' . $info[0] . '" onClick=\'alert("you are now registerd for this event")\';>Remove me</a></td>';
echo "<hr colspan='2'>";
echo '<td><a href="" onClick=\'window.open("wattend.php?id=' . $info[0] . '", "window_name", "width=500, height=500")\';>Attening this event</a>';

echo "</td>";
echo "</tr>";

echo "</table>";

}}
echo "<br>";
?>
</div>


<?php
$data = mysql_query("SELECT * from main.last  ORDER BY id DESC LIMIT 1;") or die(mysql_error());

while($info = mysql_fetch_array( $data )) 
{ 
Echo "<div class='last_ride'>";

Echo "Last Ride Report Updated On ";
Echo "<br>";
echo $info['date'] ;
echo "<hr>";
echo "<br>";
Echo $info['rr'] ; 
Echo "<hr>";
Echo "</div>";	

}


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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