conan318 Posted August 14, 2011 Share Posted August 14, 2011 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/244724-if-statment-and-joining-tables/ Share on other sites More sharing options...
conan318 Posted August 14, 2011 Author Share Posted August 14, 2011 opps i left that out lol while($info = mysql_fetch_array( $data )) { kk its now displaying the events but as if i have registered for every event and displaying the remove link Quote Link to comment https://forums.phpfreaks.com/topic/244724-if-statment-and-joining-tables/#findComment-1256990 Share on other sites More sharing options...
conan318 Posted August 14, 2011 Author Share Posted August 14, 2011 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/244724-if-statment-and-joining-tables/#findComment-1256991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.