Display User Data??

jparr021 15 Nov, 2007
Hey again,
I have yet another question! I was wondering if it would be possible for a user that is registered at our site to view previous data that was entered by them? What we are trying to accomplish is to create a Continuing Education Tracker for a group of Veterinarians that are associated with a particular organization. So what they need is to enter the total number of hours that they have for CE, and then be able to retrieve those hours, so as to know how many they need for their particular month/year. So I guess, is this at all possible with ChronoForms and php/javascript? I know creating the form will not be a big deal, but displaying the info/data might be another problem?

Thanks again,
Jeff
GreyHead 15 Nov, 2007
Hi Jeff,

The good news is that it's all possible. With PHP and the database you can do 'almost' anything.

The bad news is that coding like this, whilst not difficult, is not trivial either.

A rough outline of the app will be something like: [list]
  • Register the members in Joomla so they have a unique ID
  • Set up a database table (possibly tables) to record the data - this needs some design thought
  • Set up forms to capture initial data (?) and to show status and allow additions
  • Set up an admin page to manage the data[?]
  • [/list]I'd start this kind of project by looking around for Joomla extensions (or php scripts) that do something similar and seeing if they could easily be adapted. (Changing some text and a few field names is simple, if you're into extensive code functionality changes then probably better start from scratch.

    This is probably more than you want to hear, best next step for you is to sit down with pencil and paper and walk through the online process sketching out forms and where the data comes from and goes to.

    Bob<br><br>Post edited by: GreyHead, at: 2007/11/15 10:22
    jparr021 16 Nov, 2007
    Well we already have the Users in the database, and have used the Joomla extension Community Builder, so that we have the ability to search users in the Association. I think we will be able to use a variation of the form that I used for the RSVP,but with slightly different fields of course. Also, I was wondering what the Chrono Mambot does? I downloaded and installed it, but am not 100% sure what it does. I have it unpublished as of right now, but is there any documentation I could look at, or would it even help us with developing this CE Tracker?

    Here is what I have so far as kind of a starting point:
    http://nwvma.org/index.php?option=com_chronocontact&chronoformname=ContinuingEdTracker

    Again, thank you for all of your help! I know a few other groups in our class have been using your component, and they absolutely love it. So thanks again!

    Jeff<br><br>Post edited by: jparr021, at: 2007/11/15 21:14
    GreyHead 16 Nov, 2007
    Hi Jeff,

    A quick reply now, it's late here. The mambot allows you to insert a ChronoForms form into a normal Joomla content page (but not a module). It can go in any page that allows mambots - from memory the syntax is {chronoforms}formname{/chronoform} I think you'll find the correct version in the mambot install help.

    I'll look at the other code in the morning.

    Bob
    GreyHead 16 Nov, 2007
    Hi Jeff,

    That link is for registered members only - please approve my application even though I'm not a fully qualified vetinarian.

    Bob
    jparr021 16 Nov, 2007
    Hi Bob,
    You are now a registered member! Here is the form again:

    Thanks,
    Jeff

    Edited to add url tags.<br><br>Post edited by: GreyHead, at: 2007/11/16 18:56
    GreyHead 17 Nov, 2007
    Hi Jeff,

    Sure, it looks very possible. At the least you'd need a little bit of code that recognised the member (there's some of that in the forums here); then looked up their ID in the database table and displays the results. You'd need to validate that hours field as a number to avoid some problems.

    Bob
    jparr021 21 Nov, 2007
    Hi Bob,
    Well I successfully connected to my database, and can display user data. Unfortunately I am only able to display ALL User data! IS there some piece of code I may be missing in my form thats not recording the User ID. We thought we would put it as a hidden field and have it record their User ID without them knowing it. Is there a post on here that has that info? I will be searching throughout the night here, so I will respond if I solve it!
    Thanks Bob,
    Jeff

    Here is the page that I can display user info:
    http://nwvma.org/index.php?option=com_chronocontact&chronoformname=GetmethodTest<br><br>Post edited by: jparr021, at: 2007/11/21 02:57
    GreyHead 21 Nov, 2007
    Hi Jeff,

    Can you post the form html please, I can't see what's happening just from the results - though you clearly have got the database access!

    Bob
    jparr021 27 Nov, 2007
    Hey Bob,
    Sorry for the time in replying! Here is the form html code!

    <?php 
    //---------------------------------------------------------------------------------
    //Set the database access information as constants for localhost connection.
    //---------------------------------------------------------------------------------
    /*
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_USER', 'root');
    DEFINE ('DB_PASSWORD', '');
    DEFINE ('DB_NAME', 'sitename');
    */
    //---------------------------------------------------------------------------------
    //Set the database access information as constants for cissrv2 connection.
    //---------------------------------------------------------------------------------
    
    DEFINE ('DB_HOST', '***************');
    DEFINE ('DB_USER', '************');
    DEFINE ('DB_PASSWORD', '*******');
    DEFINE ('DB_NAME', '**********');
    
    
    //---------------------------------------------------------------------------------
    // Make the connection to MySQL Database Server.
    // If the connection fails, the die() message will be displayed.
    //Comment out print statement when done testing
    //---------------------------------------------------------------------------------
    $dbcon = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not select the database: ' . mysql_error() );
    //print "<p> Successful DB Connection!! $dbcon </p>";
    
    //---------------------------------------------------------------------------------
    // Select the database
    // If the database selection fails, the die() message will be displayed
    //Comment out print statement when done testing
    //---------------------------------------------------------------------------------
    
    $dbname =@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error () );
    //print "<p> DB Name was found!! $dbname</p>";
    ?>
    
    
    <!-- ----------------------------------------------------------------------------
    -->
    
    
    <?php
    //-------------------------------------------
    //Include DB Connection code.
    //------------------------------------------
    //include ('mysql_connect.php');
    
    //--------------------------------------------------------------------------------
    // Select some records from a table
    // The mysql_query() returns a resource link to the results of the query
    // 	or FALSE if no records were found.  The resource link is stored in $results
    // SQL references: pg 142-152, 160-163
    //--------------------------------------------------------------------------------
    $sql = "SELECT username, recordtime,  evnt_title, lecture, location, date, hours, comments FROM jos_chronoforms_10";
    //$sql = "SELECT * FROM 301users Where last_name ='Lennon'";
    //$sql = "SELECT * From 301users where last_name LIKE 'Len%'"
    //$sql ="SELECT * FROM 301users Where user_id>3"
    //$sql = "SELECT * FROM 301users";
    //print "sql <br>";
    
    $result = mysql_query($sql) or die ('Query failed: ' . mysql_error());
    //print "<br><br>Query Resource Link is: $result";
    
    //--------------------------------------------------------------------------------
    //count the number of rows and store the count in $numRows
    //--------------------------------------------------------------------------------
    $numRows = mysql_num_rows($result); 
    //print "<br><br>Number of rows in table 'jos_chronoforms_10' = $numRows <br><br>";
    
    //--------------------------------------------------------------------------------
    // Fetch rows one-at-atime and store the fields in array named $RowArray	
    // Continue this process while there are rows.
    //---------------------------------------------------------------------------------
    
    if ($numRows > 0)
    {
    	while ($RowArray = mysql_fetch_array($result))
    	{
    		$username = $RowArray[0];
    		$recordtime = $RowArray ["recordtime"];
    		$evnt_title = $RowArray ["evnt_title"];
    		$lecture = $RowArray ['lecture'];
    		$location = $RowArray ['location'];
    		$date = $RowArray ['date'];
    		$hours = $RowArray ['hours'];
    		$comments = $RowArray ['comments'];
    
    		print "$username $recordtime $evnt_title $lecture $location $date $hours $comments $RowArray[5] <br>";
    	}
    }
    
    ?>
    edited to add code tags<br><br>Post edited by: GreyHead, at: 2007/11/27 19:25
    GreyHead 28 Nov, 2007
    Hi Jeff,

    No problem with the delay, you were on holiday last weekend and I was on the road.

    I think we can simplify this code a lot and hopefully make it easier to manage in the process. A couple of things to check first though:[list]
  • It looks like you are pulling out rows and just printing them here?
  • You refer to the chronoforms form database table 'jos_chronoforms_10' and another table called 310users (though I think all the sql is commented out). Are they both in the same database set here - DEFINE ('DB_NAME', '**********');?
  • How do you want to filter the data? By user ID, or name - like 'Len'?
  • [/list]Bob
    jparr021 28 Nov, 2007
    Hey Bob,
    That is pretty much what we want to do is just print their records. We want to filter the data so that individual users can only see their own data. I guess the best way to do it is filter it through their user id. We do have a hidden field when they submit the form.
    <input type="hidden" name="username" value="$my->username">

    As far as the 301Users table, we did comment that out because we just pulled the code from an old code that we had used for our 301 class. Do you think we should get rid of that code?

    In essence, we want the users to enter in the hours of continuing education hours that they have completed on the Form we had made, and then we would like to have another page that displays the number of hours, and also where they were completed, but only for that specific user. Right now, I can get every record to display, but would like to have each user who submitted a form, to view their own stuff.<br><br>Post edited by: jparr021, at: 2007/11/27 23:29
    GreyHead 28 Nov, 2007
    Hi Jeff,

    Thanks for that, it helps me see the wood for the trees. It's late here, I'll have a look at the code in the morning.

    One question I forget, are you on J1.0.x or J1.5 ? Just makes a little difference to the code.

    Bob
    jparr021 28 Nov, 2007
    Hey Bob,
    We are in J1.0.x.

    Thanks,
    Jeff
    GreyHead 28 Nov, 2007
    Hi Jeff,

    Here's a basic version that works.
    <?php
    global $database, $my; // probably already declared but just in case
    $username = $my->username;
    
    // select records from the table
    $sql = "
        SELECT evnt_title, hours
        FROM #__chronoforms_10
        WHERE username = '$username'";
    $database->setQuery( $sql);
    if ( !$database->query() ) {
      echo $database->stderr();
    }
    
    // If there are some results then process them
    if ( $database->getNumRows() > 0 ) {
      echo "<table><tr><td>Event</td><td>Hours</td></tr>";
      $results = $database->loadObjectList();
      // keep a running total of hours
      $total_hours = 0;
      // out put this row
      foreach ( $results as $row ) {
        echo "<tr><td>$row->evnt_title</td><td style='text-align:right;'>$row->hours</td></tr>";
        $total_hours += $row->hours;
      }
      // output total row
      echo "<tr><td>Total hours</td><td style='text-align:right; font-weight:bold;'>$total_hours</td></tr></table>";
    }
    ?>
    This uses the Joomla database classes which are a bit tricky to start with but much simpler and more powerful than building the code from scratch.

    If you post this code at the end of the Form HTML then it shows a little table like this:Display User Data?? image 1

    Bob

    PS spotted a little bug in your form code, the hidden field needs php tags ('global $my' added for safety)
    <input type="hidden" name="username" value="<?php global $my; echo $my->username; ?>">
    jparr021 29 Nov, 2007
    Hey Bob,
    Okay, so I plugged the code in and it works great! Thank you so much! However, I dont know if it is the template that we have, or something happening the the html or what, but when I enter hours it makes our template go haywire! Here is the code that I entered into the Form HTML, right under the code for the form. I also tried it on a separate page, and it seems to do the same thing. Here is the code:
    <TD ALIGN=LEFT VALIGN=TOP WIDTH=535>
    
      <b>Continuing Education Tracker for <?php
    global $my;
    
    echo $my->username;
    ?></b></font>
    
          <FONT SIZE=3 COLOR="#000000" FACE="HELVETICA">
          <P><FONT SIZE=2 COLOR="#000000" FACE="HELVETICA">
          <P>Please fill in the fields below to record your Continuing Education Hours. Only one meeting can be recorded at a time; if you'd like to record two or more meetings, please submit information for the first and return to this page to record any additional meetings.</p>
    
    <input type="hidden" name="username" value="<?php global $my; echo $my->username; ?>">
    
    <table>
    <!--<tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event Date</b> (mm/dd/yy)</TD>
    <TD WIDTH=125  ALIGN=LEFT VALIGN=TOP><input type="text" name=date maxlength="500" size="50"></td>
    </tr>
    -->
    <!--TEST ROW-->
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event:</b></TD>
    <TD WIDTH=325  ALIGN=LEFT VALIGN=TOP>
    
    <input type="radio" name="evnt_title" value="November 15, 2007 - Digital Radiography">  Digital Radiography; (November 15th, 2007)
    <br></br>
    <input type="radio" name="evnt_title" value="January 17th, 2008 - Test Meeting">  TBA; (January 17th, 2008)
    <br></br>
    <input type="radio" name="evnt_title" value="March 20th, 2008 - Test Meeting">  TBA; (March 20th, 2008)
    <br></br>
    <input type="radio" name="evnt_title" value="May 15th, 2008 - Test Meeting">  TBA; (May 15th, 2008)
    
    <tr><td> </td></tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Lecture/Event Title:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="lecture" maxlength=1000 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event Location:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="location" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Date:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="date" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>CE Hours:</b><br /></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="hours" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Notes/Comments:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><textarea name="comments" cols="40" rows="5"></textarea></TD>
    </tr>
    
    </table>
    
    <table>
    
    <tr><td> </td><td></td></tr>
    
    <tr><TD COLSPAN=2 WIDTH=535 ALIGN=LEFT VALIGN=TOP>
    
    
        <tr><td colspan=2 ALIGN=LEFT><input type="submit" value="Submit"></td></tr>
      </table>
    
    <!--END-->
     <?php
    global $database, $my; // probably already declared but just in case
    $username = $my->username;
    
    // select records from the table
    $sql = "
        SELECT evnt_title, hours
        FROM #__chronoforms_10
        WHERE username = '$username'";
    $database->setQuery( $sql);
    if ( !$database->query() ) {
      echo $database->stderr();
    }
    
    // If there are some results then process them
    if ( $database->getNumRows() > 0 ) {
      echo "<table><tr><td>Event</td><td>Hours</td></tr>";
      $results = $database->loadObjectList();
      // keep a running total of hours
      $total_hours = 0;
      // out put this row
      foreach ( $results as $row ) {
        echo "<tr><td>$row->evnt_title</td><td style='text-align:right;'>$row->hours</td></tr>";
        $total_hours += $row->hours;
      }
      // output total row
      echo "<tr><td>Total hours</td><td style='text-align:right; font-weight:bold;'>$total_hours</td></tr></
    table>";
    }
    ?>


    Please let me know what you think might be causing this?
    Thank you so much once again!
    Jeff
    GreyHead 29 Nov, 2007
    Hi Jeff,

    Just pasted that in a new copy of your form and it works OK. Are you saving the hours field in the database as an integer or a text field? I have it as an integer. I think that PHP should convert automatically but that's my first thought about the cause of your bug.

    Bob
    jparr021 29 Nov, 2007
    Hey Bob,
    Well I went into the database and changed the hours field to an integer. Do you think I should just paste the code into a new form and save it as an integer when I create a table for it? I did create a new form and pasted it in there, but still linked it to the same database where I changed the hours field to an integer, and it still returned the same thing. Making the template look broken.
    Thanks again,
    Jeff
    Here is a picture of what it is doing to the template:
    http://students.uwsp.edu/jparr021/CEtracker.jpg
    Post edited by: jparr021, at: 2007/11/29 17:02<br><br>Post edited by: jparr021, at: 2007/11/29 17:07
    jparr021 29 Nov, 2007
    Hey Bob,
    We found out why the table was doing what it was doing! We had an extra space in between the </ and the table for the closing tag!
    Once again, thank you so much Bob!

    Jeff

    Here is the completed code, if anyone would like to Display User Data here is some sample code for that:
    <TD ALIGN=LEFT VALIGN=TOP WIDTH=535>
    
      <b>Continuing Education Tracker for <?php
    global $my;
    
    echo $my->username;
    ?></b></font>
    
          <FONT SIZE=3 COLOR="#000000" FACE="HELVETICA">
          <P><FONT SIZE=2 COLOR="#000000" FACE="HELVETICA">
          <P>Please fill in the fields below to record your Continuing Education Hours. Only one meeting can be recorded at a time; if you'd like to record two or more meetings, please submit information for the first and return to this page to record any additional meetings.</p>
    
    <input type="hidden" name="username" value="<?php global $my; echo $my->username; ?>">
    
    <table>
    <!--<tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event Date</b> (mm/dd/yy)</TD>
    <TD WIDTH=125  ALIGN=LEFT VALIGN=TOP><input type="text" name=date maxlength="500" size="50"></td>
    </tr>
    -->
    <!--TEST ROW-->
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event:</b></TD>
    <TD WIDTH=325  ALIGN=LEFT VALIGN=TOP>
    
    <input type="radio" name="evnt_title" value="November 15, 2007 - Digital Radiography">  Digital Radiography; (November 15th, 2007)
    <br></br>
    <input type="radio" name="evnt_title" value="January 17th, 2008 - Test Meeting">  TBA; (January 17th, 2008)
    <br></br>
    <input type="radio" name="evnt_title" value="March 20th, 2008 - Test Meeting">  TBA; (March 20th, 2008)
    <br></br>
    <input type="radio" name="evnt_title" value="May 15th, 2008 - Test Meeting">  TBA; (May 15th, 2008)
    
    <tr><td> </td></tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Lecture/Event Title:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="lecture" maxlength=1000 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Event Location:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="location" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Date:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="date" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>CE Hours:</b><br /></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><input type="text" name="hours" maxlength=500 size=50></TD>
    </tr>
    
    <tr>
    <TD WIDTH=175 ALIGN=LEFT VALIGN=TOP><b>Notes/Comments:</b></TD>
    <TD WIDTH=125 ALIGN=LEFT VALIGN=TOP><textarea name="comments" cols="40" rows="5"></textarea></TD>
    </tr>
    
    </table>
    
    <table>
    
    <tr><td> </td><td></td></tr>
    
    <tr><TD COLSPAN=2 WIDTH=535 ALIGN=LEFT VALIGN=TOP>
    
    
        <tr><td colspan=2 ALIGN=LEFT><input type="submit" value="Submit"></td></tr>
      </table>
    
    <!--END-->
    <?php
    global $database, $my; // probably already declared but just in case
    $username = $my->username;
    
    // select records from the table
    $sql = "
        SELECT evnt_title, hours
        FROM #__chronoforms_10
        WHERE username = '$username'";
    $database->setQuery( $sql);
    if ( !$database->query() ) {
      echo $database->stderr();
    }
    
    // If there are some results then process them
    if ( $database->getNumRows() > 0 ) {
      echo "<table><tr><td>Event</td><td>Hours</td></tr>";
      $results = $database->loadObjectList();
      // keep a running total of hours
      $total_hours = 0;
      // out put this row
      foreach ( $results as $row ) {
        echo "<tr><td>$row->evnt_title</td><td style='text-align:right;'>$row->hours</td></tr>";
        $total_hours += $row->hours;
      }
      // output total row
      echo "<tr><td>Total hours</td><td style='text-align:right; font-weight:bold;'>$total_hours</td></tr></
    table>";
    }
    ?>
    GreyHead 29 Nov, 2007
    Hi Jeff,

    Well spotted, it's so easy to get those little bugs in, especially when you cut and paste code - and so **** difficult to track them down.

    Bob
    This topic is locked and no more replies can be posted.