Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by davidcriniti

  1. I have a table where I'm storing my marathon and other race results. One column ( race_time_total - TIME format) and another column ( race_distance_numeric - decimal(65,3) format) are being used here.



    Assuming the race_distance_numeric is the distance of the race in either km or miles (Eg: marathon being 42.195km), how to I calculate the pace?


    I've used:

    $pace_per_k = $row_content['race_time_total'] / $row_content['race_distance_numeric']  

    .... but am not getting expected results when I echo $pace_per_k


    Any tips?


  2. I'm making an amendment to my login page so that when a user logs in, the date_last_login field in the members table is updated to NOW(). Well, that's the idea.


    The login works fine. Always has. It's just this update that isn't happening. No error message appears, but date_last_login remains 0000-00-00 00:00:00 . Any tips?

    $sql_date_last_login = $pdo->exec("update members set date_last_login = now() where member_id = '".$SESSION['member_id']."'");



  3. Hi all,


    I have a search page where I'd like members to be able to search for races that they and their friends have entered into a database. When entering the data, users put the race date into the race_date field (Which is a DATETIME field) in the table.


    I've set up the search and display pages, so users can search by a number of other criteria (first name, last name, race distance, time, etc), but am having trouble with searching by year. On my search form, is a field called race_year.


    So, obviously I need some change in the code below, specifically in relation to the line $where .= " AND race_date='$race_year'"; because I want to extract the year part of the race_date column from the table and see if it matches $race_year .


    Any advice would be appreciated.





    $race_year = $_POST['race_year'];
    if ($race_year != '')
    { // A year is selected
      $where .= " AND race_date='$race_year'";


  4. Hi everyone,


    My googling seems to have found an way to add x days to the current date, and I'm sure that finding x days from a date pulled from my database must be pretty similar, but I just can't seem to get it working.


    My task involves teachers setting notifications which are displayed for a number of days designated by the teacher.


    So when the teacher creates the notiication, the `notificatin_date` field is updated with the timestamp.  The `notification_duration` field is an integer between 1 and 21.


    I can get this info out of the database without problem:

    $notification_set  = date('Y-m-d', strtotime($notification['notification_date']));
    			   $notification_duration = $notification['notification_duration'];
    			   echo $notification_duration . "<br/>";
    			     echo  $notification_set . "<br/>";

    However, when I try and add the duration to the date when the notification was set, to echo the expiry date, I run in to problems. This is what I've got at the current time, but I'm obviously not 'adding' $notification_duration and $notification_set correctly in the first line below, which is causing all my problems. Any help is much appreciated.

    	$expiration_date = $notification_set + strtotime($notification_duration . "days");
    			   if ($expiration_date> date)
    				echo "Your notification will expire on ";   
    			   else if ($expiration_date < date)
    				echo "Your notification expired on ";   
    			   else echo "Your notification expires today ";
    			   echo   date('jS', strtotime($expiration_date));
    			echo " of ";
    	echo date('F', strtotime($expiration_date));
    				echo ", ";
    	echo date('Y', strtotime($expiration_date));   

    Thanks for your time,







  5. Thank you both for your responses.


    The time column was always formatted as TIME, so that wasn't a problem. Adding the `backticks` seemed to make all the difference fastsol, so thanks for that tip!

    $time_stated = $_POST['time_stated']; 
    if ($time_stated != '' ) 
      $where .= " AND `time` < '$time_stated'"; 



  6. Hi everyone,


    I've got a simple script that is searching for the results of running races in a database.


    Searching for a finisher's position works perfectly with this script:

    $position = $_POST['position'];
    $pos_operator = $_POST['pos_operator'];
    if ($pos_operator == '=' && $position != '' ) 
      $where .= " AND position='$position'";
    if ($pos_operator == '<' && $position != '' ) 
      $where .= " AND position<'$position'";

    $position refers to a text field in the form where the user can type in a digit.

    $pos_operator refers to a text field in the form where a user can select = or <


    However, when I try to do a similar thing with time, I'm not getting the expected results.

    $time_stated = strtotime($_POST['time_stated']); 
    if ($time_stated != '' ) { 
      $where .= " AND time < '$time_stated'"; }

    $time_stated refers to a text field where the user is asked to look for a time less than the time they input in xx:xx:xx format.


    I tried this with and without the strtotime


    Any tips?







  7. Hi everyone,


    On our school website, we've got a page where students can do a quiz, and get feedback given to them, as to whether their answers are correct or incorrect.


    The code echos the student response for each question, and the feedback, tick / cross is displayed in the adjacent column.


    However, I've just changed the input box from a text field to a text area, and I've noticed a little quirk.


    The student answer, after pressing submit, now displays in lower case. Is their any way I can echo their answer, exactly as they input it.


    Here is the relevant code:

    <textarea name="user_answer_<?=$row_counter?>" cols="40" rows="2" /><?=$userAnswer?></textarea>

    Thanks for your time,


  8. Hi,


    I'm trying to develop an online merit award system for our school at the moment.


    I've got a table that notes the different types of awards that students can get, in various columns, with the last column providing a total points.  Some awards are worth different points, which is why $total is calculated as:

    $total['total']  = $row_recipients['pb4l'] + $row_recipients['pb4l'] + $row_recipients['sports_award'] + $row_recipients['offline_sports_award'] + (5 *  $row_recipients['welfare_award']) + (5 *  $row_recipients['offline_welfare_award']) + (10 *  $row_recipients['senior_executive_award']) + (10 *  $row_recipients['offline_senior_executive_award'])  ;

    That works fine, and I've calculated each student's total accurately. The next part is what I'm struggling with.  Students attain certain levels ($level) based on their total 50 - Bronze, 100 - Silver, 150 - Gold etc.


    The code for calculating this is:


    if ($total >= 50 && $total< 100)
    $level = "Bronze";	
    if ($total >= 100 && $total< 150)
    $level = "Silver";	
    if ($total>= 150 && $total< 200)
    $level = "Gold";	
    if ($total >= 200 && $total < 350)
    $level = "School Trophy";	
    if ($total >= 350 && $total< 500)
    $level = "Platinum";	
    if ($total >= 500)
    $level = "Diamond";	
    echo $level ;

    The level is accurate for the first few rows displayed, where $total has a value greater than 0. But for rows below that, where students have been given no awards, The $level value is the same as the last row with a $total value greater than 0.


    Please tell me where I'm going wrong.




  9. Hi Q695,


    That is telling me the total number of rows, which my query already does.


    The part I'm needing help with iis to find the user's rank by comparing the amount of uploads a user has to the amount of uploads all other users have. Ie: User with most uploads would be ranked #1, user with second most uploads would be ranked #2 and so on.




  10. Hi,


    I've got a site where teachers can upload resources to share amongst staff and students. In order to motivate staff to share resources, I'm doing things like introducing badges and ranks etc.


    My latest bit of script counts the amount of uploads a staff member has.


    I can also find the total number of staff who've uploaded, but how I'm not sure how to find the current user's ( ie: Where members.member_id = ". $_SESSION['member_id']  )   rank out of that total in terms of the amount of uploads they have.


    Any advice would be appreciated. Script so far is :

     $total_uploads = mysql_query("SELECT members.member_id, members.member_firstname, members.member_lastname, COUNT(*)  
    FROM uploads    
    JOIN members
    ON uploads.member_id = members.member_id
    GROUP BY uploads.member_id 	 ");
    $total_uploads_count	= @mysql_num_rows($total_uploads);
    $upload_count = mysql_query("SELECT members.member_id, members.member_firstname, members.member_lastname, COUNT(*)  
    FROM uploads    
    JOIN members
    ON uploads.member_id = members.member_id AND members.member_id = ". $_SESSION['member_id']  . "
    GROUP BY uploads.member_id 	 ");
    echo "<tr>";  
    echo "<td align='right'> Your upload count: </td>";  
    echo "<td align='left'>" . $row_count['COUNT(*)'] . " (Your rank is __ out of $total_uploads_count </td>";  
    echo "</tr>";  
    echo "</table>";  	 
  11. Hi,


    I'm just after someone to point me in the right direction on this one, because I'm not sure how to go about it at all.


    Let's say I've got a table called "tbl_badges" with data regarding badges that will be given to students based on their scores in a quiz.


    Is it possible to pull the data from the 'badge_name' field and superimpose it on an image.


    Ie: So badges would essentially look the same, but with different text on the same image.


    The reason I'm after this solution is to enable non-tech saavy teachers to be able to create a badge by simply filling in a form which asks for a badge name.


    To give you a visual on what I mean, see the image below.




    While I've obviously created this myself, I'd like this to be created by "Roman Numerals Badge" being pulled from the badge_name field in the tbl_badges.


    Anyway, just after some basic direction on what methods I need to investigate to achieve this.







  12. Thanks,


    I fiddled around with the my_profile_updateinformation.php page, which processes the avatar upload, and inserted the following code:


    	////Reset session
    		$sql="SELECT * FROM members WHERE member_id=" . $_SESSION['member_id'] ;
    $row = mysql_fetch_array( $result );
    		$_SESSION['member_avatar'] = $row['member_avatar'];


    which seemed to do the trick. Thanks Requinix.




  13. Hi,


    I have a page where students in my school can update an avatar.  (my_profile.php)


    On this page, they see their avatar nice and large in the middle of the page. However, on this page, as well as all other pages in the site, the avatar is also displayed in a smaller version on the top-right corner, according to session data.


    	if (!empty($_SESSION['userName']) && $_SESSION['member_avatar'] != "") {
    	       echo "<img src=\"images/member_avatars/" . $_SESSION['member_avatar'] .  "\"  width='40px' height='40px' alt=\"Avatar\" tyle=\"float: left; padding: 3px 3px 3px 3px;\"   /></td>";
    		 if (!empty($_SESSION['userName']) && $_SESSION['member_avatar'] == "") 
    		   echo "<img src=\"images/member_avatars/default_avatar_50.gif\" width=\"40\" height=\"40\" alt=\"Your Avatar Here\" />";


    When the member uploads a new file, the large version can be seen immediately on the my_profile.php page where the code is echoing  the row in the database.


        echo "<img src=\"images/member_avatars/" . $my_profile["member_avatar"] . "\" height='250' width='250' alt=\"Avatar\" /></td>";




    However, the aforementioned smaller avatar  (  $_Session['member_avatar']  )  does not update on this or any other page on the site. To update this, the user has to log out, and then log in again.


    How can I fresh the $_Session['member_avatar'] as soon as the new image is uploaded?


    Thanks in advance,









  14. Thankyou all. That worked perfectly Barand!


    Might print out the finaly solution from Barand, as well as the echoing in case it is of use to any newbies.


      $query = "SELECT m.member_firstname, m.member_lastname, SUM(points) as total_points
    FROM tbl_points as p
        INNER JOIN members as m ON p.point_member_id = m.member_id
    GROUP BY p.point_member_id
    ORDER BY total_points DESC";	 
    $result = mysql_query($query) or die(mysql_error());
    // Print out result
    while($row = mysql_fetch_array($result)){
    	echo  $row['member_firstname']. " " . $row['member_lastname'] . " : "  . $row['total_points'];
    	echo "<br />";


    ps: Red arrow, you were VERY generous saying that I was close! :-)  I think there's a very big gap between the simple examples on sites such as that one and the solution provided here. I am very appreciative of the help! 




  15. Hi everyone,


    I'm trying to give my students points for doing various things on my website. Eg: Completing a quiz, getting a certain score, all result in points, which are thrown into a table called points.


    Now I'm trying to extract a leaderboard for the table.


    I'm halfway there, and have a list of scores ranked from highest to lowest, next to the member's id.


    See code below:


    $query = "SELECT point_member_id, SUM(points) FROM tbl_points GROUP BY point_member_id ORDER BY SUM(points) DESC"; 
    $result = mysql_query($query) or die(mysql_error());
    // Print out result
    while($row = mysql_fetch_array($result)){
    	echo  $row['point_member_id']. " : ". $row['SUM(points)'];
    	echo "<br />";


    However, I really don't want point_member_id displaying. I'd like the student's firstname and lastname displaying.


    firstname and lastname are the fields 'member_firstname' and 'member_lastname' in the table 'members'.


    So what I need to do is extract this information where members.member_id = points.point_member_id


    I've tried a bunch of variations to the query and searched ad nauseum, but nothing is helping.


    Any advice would be greatly appreciated.








  16. Thank you. I've made great progress on this page.


    I've altered my $select statement as per your advice AyKay47. The page loads perfectly the first time.


    However, when I click on the link:



    ...I get a message which says :


    echo "<a href=\"course_display.php?link=2&course_id=". $course_id. "&course_password=" . $course_password . " \">Instructions</a><br />";



    .. I still get an error which says:


    Query: SELECT * FROM tbl_course_titles WHERE course_id = AND course_password = ''

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND course_password = ''' at line 1


    Any ideas?


    Thanks again,



    ps: Edit - mistake when pasting in code.

  17. Hi,


    I've added mysql escape string and put the query together in a manner you suggested.


    include "mysql_connect.php";
    $course_id =    mysql_real_escape_string ($_POST["course_id"]);
    $course_password = mysql_real_escape_string ($_POST['course_password']);
       // The basic SELECT statement
    $select = 'SELECT * FROM tbl_course_titles WHERE course_id =' . $course_id  . ' AND course_password = ' . $course_password . '';
    $result1 = mysql_query($select)
    or die("Query: " . $select . "<br>Error: " . mysql_error());


    When I input correct details into the searchcourses.php form, I now get:


    Query: SELECT * FROM tbl_course_titles WHERE course_id =1 AND course_password = secret

    Error: Unknown column 'secret' in 'where clause'


    My course id is 1 and passowrd is secret.


    For some reason it seems to think 'secret' is a column.


    I've tried a bunch of different variants and googling and I am feeling quite silly right now, but any advice would be much welcome.




  18. Hi everyone,


    I was given some great advice by Denno020 on how to display content in the main area of my table based on a link clicked on the side.


    <a href="course_display.php?link=1">Link 1</a>
    if(isset($_GET['link']) && $_GET['link'] == '1'){
    echo "Show if and when Link 1 is Clicked.....";



    It works perfectly under normal circumstances. However, I'm trying to apply it to a page (course_display.php) which is reached by a form (course_search.php) which asks users to supply an id (course_id) and password (course_password)


    - The course_display.php page loads great the first time when reached via course_search.php

    - If I hit the refresh button in my browser, it refreshes perfectly.


    However, when I click on the link (as in the code above), I get an error which says:


    Error retrieving info from database!

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND course_password=''' at line 1


    I'm not sure why if there was an SQL syntax error it wouldn't show the first time the page is loaded?


    I suspect the problem is either solved by:


    - Fixing mysql syntax


    - passing the variables $course_id and $course_password through the hyperlink in addition to the variable 'link=1'


    - both of the above.


    The mysql syntax is:


    include "mysql_connect.php";
      $course_id = $_POST['course_id'];
       // The basic SELECT statement
    $select = 'SELECT *';
    $from   = ' FROM tbl_course_titles';
    $where  = ' WHERE course_id =' . $course_id . '';
    $order = 'ORDER BY id ASC';
    $course_password = $_POST['course_password'];
     $where .= " AND course_password='$course_password'";
    $result1 = @mysql_query($select . $from . $where);
    if (!$result1) {
     exit('<p>Error retrieving info from database!<br />'.
         'Error: ' . mysql_error() . '</p>');
    $num_rows = mysql_num_rows($result1);
    if ($num_rows == 0){
     echo "Sorry, your Course ID / Password combination is incorrect, go back and try again";




    ...I've tried 2 ways to pass multiple variables through the hyperlink. Not sure if either of these are correct?


      echo   "<a href=\"course_display.php?link=2?course_id= ". $course_id. "?course_password = " . $course_password . " \">Instructions</a><br />";
    echo  "<a href=\"course_display.php?link=1?course_id=$course_id?course_password=$course_password \">Instructions2</a><br/>"; 



    Any advice on how to solve this problem is greatly appreciated.





  19. I have been trying to find a way to use php to display content in the main area of my page, based on a link clicked on the side of my page.


    The closest thing to what I'm after is done with jquery: http://jsfiddle.net/5NEu3/3/


    Was wondering how it would be done with php. Ie: What would I do with the table below, which has 3 links in the left column, and 3 sentences is the right. Each only to be displayed when their link is clicked, and hidden again if any of the others are clicked.


    Any advice would be greatly appreciated.






    <table width="100%" cellpadding="3">
       <a href="???">Link 1 </a><br />
       <a href="???">Link 2 </a><br />
     <a href="???">Link 3 </a><br />
       Show if and when Link 1 is Clicked. Hide if anything else is clicked.
       Show if and when Link 1 is Clicked. Hide if anything else is clicked.
       Show if and when Link 1 is Clicked. Hide if anything else is clicked.

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