Jump to content

lukep11a

Members
  • Posts

    202
  • Joined

  • Last visited

Everything posted by lukep11a

  1. Thankyou for your help, it is now working
  2. Hi, I have a table currently called 'test' with 3 columns, 'teamname', 'points' and 'date'. Every time a team plays they earn points based on their performances, the points they have earned are then inserted into the table so each team wil have many entries in the table, for example: Man Utd 50 2011-08-14 15:00:00 Arsenal 80 2011-08-14 15:00:00 Liverpool 100 2011-08-14 15:00:00 Man Utd 80 2011-08-21 15:00:00 Arsenal 20 2011-08-21 15:00:00 Liverpool 50 2011-08-21 15:00:00 What I am trying to do is display each team name once with the total points they have scored. This is the code I currently have that displays every entry in the table, does anybody know how I can ammend this to display each team once?? <table width="390" border="0" cellpadding="0" cellspacing="0"> <tr class="title"> <td width="65">Group</td> <td width="260">Team Name</td> <td width="65">Points</td> </tr> <?php $query = "SELECT * FROM test"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <tr class="teams"> <td width="65"></td> <td width="260"><?php echo $row['teamname']; ?></td> <td width="65"><?php echo $row['points']; ?></td> </tr> <?php } ?> <?php $query = "SELECT SUM(test.points) FROM test"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); ?> <tr class="total"> <td width="65"> </td> <td width="260">Total Points</td> <td width="65"><?php echo $row['SUM(test.points)']; ?></td> </tr> </table>
  3. Hi, this is the code I have above the head tag for myaccount.php which is where each user is directed when they log in. Does anybody know how I can modify the code to direct to teamselections.php if 'firstlogin' = 0 or to myaccount.php if 'firstlogin' = 1. I think I need to change the "if(isset($_SESSION['firsttime']))" part but not sure. 'firstlogin' is in the 'login' table and the 'userid' from the 'login' table is set as a session variable when they login if that helps. Any help you can give me would be very much appreciated. Thanks in advance. <?php session_start(); // the default page, if it's not their first time $redirect="teamselections.php"; if(isset($_SESSION['firsttime'])){ // the session is set, so it must be their first time. // let's send them to their "first time" page ... $redirect="myaccount.php"; } // redirect them header ("location: $redirect"); ?>
  4. Hi, I wonder if anyone can help me. I am running a fantasy football league, when a user logs in I want them to be directed to teamselections.php which is where they make their team selections, once they click submit their choices have been set and they will not need to do it again. So I thought at this point I could update the column 'firstlogin' in my 'login' table with a '1'. So technically, it may not be just the first time they login (if for example they do not submit their team selections right away, or their pc crashes etc.), but until they have submitted their team selections 'firstlogin' value will be '0' so they will be directed to teamselections.php. Once they have submitted them 'firstlogin' value will be '1' and they will be directed to myaccount.php. Hope that makes sense. So, what I am asking is how do I apply that to the code I already have. Sorry I am still relatively new to php! I would be so grateful if anyone can help me I have been tearing my hair out over this for days. These are my login functions: <?php #### Login Functions ##### function isLoggedIn() { if (session_is_registered('userid') && session_is_registered('email')) { return true; // the user is loged in } else { return false; // not logged in } return false; } function checkLogin($u, $p) { global $seed; // global because $seed is declared in the header.php file if (!valid_email($u) || !valid_password($p) || !user_exists($u)) { return false; // the name was not valid, or the password, or the email did not exist } //Now let us look for the user in the database. $query = sprintf(" SELECT userid FROM login WHERE email = '%s' AND password = '%s' AND disabled = 0 AND activated = 1 LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed))); $result = mysql_query($query); // If the database returns a 0 as result we know the login information is incorrect. // If the database returns a 1 as result we know the login was correct and we proceed. // If the database returns a result > 1 there are multple users // with the same email and password, so the login will fail. if (mysql_num_rows($result) != 1) { return false; } else { // Login was successfull $row = mysql_fetch_array($result); // Save the user ID for use later $_SESSION['userid'] = $row['userid']; // Save the email for use later $_SESSION['email'] = $u; // Now we show the userbox return true; } return false; } ?> This is my login script: <?php if (!isLoggedIn()) { // user is not logged in. if (isset($_POST['cmdlogin'])) { // retrieve the email and password sent from login form & check the login. if (checkLogin($_POST['email'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { // User is not logged in and has not pressed the login button // so we show him the loginform show_loginform(); } } else { // The user is already loggedin, so we show the userbox. show_userbox(); } ?> I apologise for their being so much to read, I hope somebody can help.
  5. I have read that and it was helpful, thanks, but it is slightly different to what I am trying to do. I have now included a variable in my code to count the rows, but do you know how I would display the number of the row for the current user (i.e where the session userid = login.userid)? It is currently displaying the number '1' <?php $query = "SELECT SUM(teams.points) FROM login, selections, teams WHERE login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC"; $result = mysql_query($query) or die(mysql_error()); $counter = 1; // set a counter value $row = mysql_fetch_assoc($result); ?> <p class="scoring"><?php echo $counter; //output the counter ?></p>
  6. could you show me how to write this please?
  7. This is the code that grabs all rows and orders by sum of the points, do you know how I can print what number row the current user is?? <?php $query = "SELECT SUM(teams.points) FROM login, selections, teams WHERE login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { } ?>
  8. Hi, I am running a fantasy football league and on a users account page I want to display what rank that user currently is overall, does anybody know how I can modify the code below to display the rank of the current user? <?php $query = "SELECT SUM(teams.points) FROM selections, teams WHERE selections.userid = '{$_SESSION['userid']}' AND (selections.groups = teams.groups)"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); ?> <p class="scoring"><?php echo $row['SUM(teams.points)']; ?></p>
  9. No I am not receiving any errors, and it doesn't seem to be redirecting, it just fails to reload index.php fully. This is the function that calls checkLogin(): <?php if (!isLoggedIn()) { // user is not logged in. if (isset($_POST['cmdlogin'])) { // retrieve the email and password sent from login form & check the login. if (checkLogin($_POST['email'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { // User is not logged in and has not pressed the login button // so we show him the loginform show_loginform(); } } else { // The user is already loggedin, so we show the userbox. show_userbox(); } ?> And also the isLoggedIn function: function isLoggedIn() { if (session_is_registered('userid') && session_is_registered('email')) { return true; // the user is loged in } else { return false; // not logged in } return false; } Do you think either of these two need amending aswell?
  10. Thanks for your reply, that doesn't seem to be working though, these are the functions that it is also linking to, do you think it could be something to do with them? function user_exists($email) { if (!valid_email($email)) { return false; } $query = sprintf("SELECT userid FROM login WHERE email = '%s' LIMIT 1", mysql_real_escape_string($email)); $result = mysql_query($query); if (mysql_num_rows($result) > 0) { return true; } else { return false; } return false; } function valid_password($pass, $minlength = 6, $maxlength = 15) { $pass = trim($pass); if (empty($pass)) { return false; } if (strlen($pass) < $minlength) { return false; } if (strlen($pass) > $maxlength) { return false; } $result = ereg("^[A-Za-z0-9_\-]+$", $pass); if ($result) { return true; } else { return false; } return false; } function valid_email($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; }
  11. Hi, I wonder if anyone can help me, I have the following login code, and I want to apply to it a page redirect on login, there is an extra column in my login table called 'first_login', it will hold either a 0 or a 1, and I want users to be redirected to 'myaccount.php' if it equals 1 and 'teamselections.php' if it equals 0. I know that it uses the header function but not really sure how to apply it to this code. Does anybody know how I would do this? Any help would be much appreciated. <?php function checkLogin($u, $p) { global $seed; // global because $seed is declared in the header.php file if (!valid_email($u) || !valid_password($p) || !user_exists($u)) { return false; // the name was not valid, or the password, or the email did not exist } //Now let us look for the user in the database. $query = sprintf(" SELECT userid FROM login WHERE email = '%s' AND password = '%s' AND disabled = 0 AND activated = 1 LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed))); $result = mysql_query($query); // If the database returns a 0 as result we know the login information is incorrect. // If the database returns a 1 as result we know the login was correct and we proceed. // If the database returns a result > 1 there are multple users // with the same email and password, so the login will fail. if (mysql_num_rows($result) != 1) { return false; } else { // Login was successfull $row = mysql_fetch_array($result); // Save the user ID for use later $_SESSION['userid'] = $row['userid']; // Save the email for use later $_SESSION['email'] = $u; // Now we show the userbox return true; } return false; } ?>
  12. Sorry for not explaining 'position' properly, it was the rank I was refering to though, and that code works perfectly, thankyou
  13. But the position isn't stored within the mysql tables, shouldn't it be generated automatically depending on which teams have the most points? Or am I mis-understanding what you're saying?
  14. Hi, I have a working league table where each persons name, team name and number of points is displayed, it also sorts them in order of points, does anybody know how would I get the position number each person is in to be displayed in the place of <td width="50">'team position here'</td> ? Any help would be much apreciated. <table width="350" border="0" cellpadding="0" cellspacing="0" class="myteams"> <tr class="title"> <td width="50">Position</td> <td width="250">Name</td> <td width="250">Team Name</td> <td width="50">Points</td> </tr> <?php $query = "SELECT privateleague.privateleagueid, privateleague.privateleaguename, user_leagues.privateleagueid, user_leagues.userid, login.userid, login.forename, login.surname, login.teamname, selections.userid, SUM(teams.points) FROM privateleague, user_leagues, login, selections, teams WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid AND login.userid = selections.userid AND selections.groups = teams.groups GROUP by login.userid ORDER by SUM(teams.points) DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <tr class="teams"> <td width="50">'team position here'</td> <td width="250"><?php echo $row['forename']; ?> <?php echo $row['surname']; ?></td> <td width="250"><?php echo $row['teamname']; ?></td> <td width="50"><?php echo $row['SUM(teams.points)']; ?></td> </tr> <?php } ?> </table>
  15. thanks to you both, it wasn't showing any teamnames to start with but then I changed echo $row['login.teamname']; to echo $row['teamname']; and now it works, don't really understand why that is though to be honest
  16. Sorry, but what do you mean by that?
  17. Thanks for your reply, that sounds good but then how would I get all the users teamnames who are in each league to be displayed on the resulting page. I have put some code together, but it's not working, I don't know if it's something to do with bringing the variable $league_name through from the previous page? <?php $query = "SELECT * FROM privateleague, user_leagues, login WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['login.teamname']; echo "<br />"; } ?>
  18. Hi, on my site each user has their own account page, and on there is a section where private leagues are listed, the code below shows how I pick up which private leagues they are currently a member of. What I am trying to do now is place a link around the part echo $row['privateleaguename']; so that when they click it they go to a new page where all the users that are also a member of that league are listed. I think it would maybe require a dynamic link creating around but not sure. If anyone can tell me how this can be done or point me in the right direction it would be very much appreciated. <?php $query = "SELECT privateleague.privateleaguename, privateleague.privateleagueid, user_leagues.userid, user_leagues.privateleagueid FROM privateleague, user_leagues WHERE user_leagues.userid = '{$_SESSION['userid']}' AND privateleague.privateleagueid = user_leagues.privateleagueid"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo $row['privateleaguename']; echo "<br />"; } ?>
  19. It was to do with the cache memory on my computer, alt + f5 did the trick, now the link works fine
  20. Ok thanks, I'm with godaddy, will drop them an email
  21. the code is not in any of my files, I have never seen it before, that's why I presumed it was some sort of error, it just appears whenever I click on a link that should go to index.php
  22. The code i posted is the error I'm referring to. That code is displayed instead of my homepage
  23. Does anybody know why I would be getting this error? If i just type in the web address the homepage is displayed, but if I type in the web address/index.php it appears, it also appears when I click on any link on the website that would take you to the homepage?? <?php // pageok // managed by puppet - hostingcms02 header("Content-type: text/plain"); // Total size of directory $totalSize = 0; // List of files in cwd $dir = opendir('.'); while (($filename = readdir($dir)) ==! false) { $files[] = $filename; } // The results of filesize are cached, clear that cache clearstatcache(); // Total file sizes foreach ($files as $file) { // Add file to total size $totalSize += filesize($file); } echo "pageok\n\n"; echo "Directory Size: $totalSize\n\n"; ?>
  24. Thanks so much, that works brilliantly, and you right it is so much more efficient to have an extra table and to have a variable with the number of leagues they can join!
  25. I am really sorry about that, I am just trying to build my site up one step at a time, and every time I get over one hurdle I feel like it is an acheivement, you shouldn't feel disheartened because I was over the moon last night when that code you provided worked with no problems whatsoever. Originally that is all I had wanted that form to do but then I thought in an ideal world it would be good if each user could sign up to more than one private league. Thankyou so much for your help I really do appreciate it, I will give the code you most recently provided a go tonight when I get chance to work on it some more.
×
×
  • 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.