logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$25
Gravity form data to database to HTML table

I am a newbie so forgive me if this is simple but I'm lost:

Quick Overview: I have the need to gather data from a Gravity form and then input that data into a database. The database data then needs to be displayed in an HTML table.

Detailed: The Gravity form is to gather information (Name, address, email, day of week, time slot) for a repeating bi-hourly time slot calender. There are to be time slots for every 30min increment of every day of the week (48 slots a day, 336 a week). As stated above this calender/time slot table would repeat weekly so if someone signed up for Monday at 6:00am then they would have that time slot indefinitely (or until they cancel). The user would select a time slot (day/time) from the form (drop down boxes) or via a "sign-up" link in one of the tables time slot boxes that would take them to the form and auto populate the drop down input fields with the corresponding day of week and time of day. Only the name of the persons signed up for a time slot would need to be displayed in the HTML table. There could also be multiple people signed up for each time slot. I almost forgot.....If its not too much to ask....I would also like to give the user the option to choose the timezone they are in and thus the HTML table would update. Here is a link to an example:

I understand the process of grabbing the input fields from Gravity form by way of $_POST and assigning them to variables and then connecting to database:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$day = $_POST['day'];
$time = $_POST['time'];

$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO example_table (FirstName, LastName, Address, Day, Time)
VALUES ('$first_name', '$last_name', '$address' , 'day' ,'time')");

mysql_close($con);
?>

I'm just lost when it comes to pulling that info back out off the database and displaying it in an HTML table. I am also not positive on the best structure for the database table or tables to be in to pull this off.


****Not sure if I made this clear by the answers given so far but...... The data needs to be displayed in a table with a header of the days of the week (Sun-Sat) and the rows need to be broken down into the 48 half hour slots that make up each day. The cells that make up the table would display the people(s) that have signed up for the corresponding day & 1/2 hour slot. There WILL be multiple people per cell. Please look at the link that I attached above as this is exactly what I'm trying to achieve.****

This question has been answered.

BIG LIFE | 08/23/11 at 5:19pm Edit

Previous versions of this question: 08/23/11 at 6:20pm | 08/23/11 at 7:46pm | 08/23/11 at 7:47pm | 08/23/11 at 7:49pm | 08/24/11 at 8:26am

(6) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    08/23/11
    10:07pm
    akosipau says:

    need to put the mysql_query in a variable

    ex.

    $result = mysql_query(....);


    then outputing result in HTML table

    ex:

    <table>
    <tr>
    <td>First Name</td>
    <td>Last Name</td>
    </tr>
    while ($row = mysql_fetch_assoc($result)) { ?>
    <tr>
    <td><?php echo $row['firstname']; ?></td>
    <td><?php echo $row['lastname']; ?></td>
    </tr>
    <?php }
    </table>

    Previous versions of this answer: 08/23/11 at 10:07pm

  • avatar
    Last edited:
    08/24/11
    5:08am
    Klian says:

    Hi Big Life,

    To output the mysql data into a HTML table try with:

    $con = mysql_connect("localhost","user","password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("my_db", $con);

    $sql = "SELECT * FROM example_table";
    $fire = mysql_query($sql) or die("<br><b>Error</b>: ".mysql_error()."<br><br>SQL::".$sql);

    $output = '<table>
    <tr>
    <th>FirstName</th>
    <th>LastName</th>
    <th>Address</th>
    <th>Day</th>
    <th>Time</th>
    </tr>
    ';
    while($res = mysql_fetch_assoc($fire)){
    $output .= '
    <tr>
    <td>'.$res['FirstName'].'</td>
    <td>'.$res['LastName'].'</td>
    <td>'.$res['Address'].'</td>
    <td>'.$res['Day'].'</td>
    <td>'.$res['Time'].'</td>
    </tr>
    ';
    }
    $output .= '</table>';

    mysql_close($con);

  • avatar
    Last edited:
    08/24/11
    7:16am
    M. Daniel says:

    Hello Big Life,

    First, you can find some related answers here on WPQ, the link is:

    http://wpquestions.com/question/show/id/578

    Check this video tutorial, it will be helpfull:

    http://www.youtube.com/watch?v=VJQfZY0DeEQ

    Also, check the link bellow:

    http://www.seodenver.com/gravity-forms-addons/

  • avatar
    Last edited:
    08/26/11
    12:09am
    ej_emman says:

    Hello,

    Base on the data you have given I created a query to make you more comfortable.
    Name, address, email, day of week, time slot


    <?php
    var $con;
    function connection($server,$user,$pass)
    {
    Global $con;
    $con = mysql_connect($server,$user,$pass) or die('connection failed');
    return mysql_select_db("my_db", $con);
    }

    function my_query($sql)

    {
    $result = mysql_query($sql);
    $arr =array();
    while(mysql_fetch_array($result))
    {
    $arr[] = mysql_fetch_array($result);
    }
    return $arr;
    }


    connection("localhost","user","password");
    $data = my_query("SELECT * FROM example_table");

    //result table sample

    $the_result = "<table>
    <tr>
    <th>Name</th>
    <th>Address</th>
    <th>Email</th>
    <th>Days of Week</th>
    <th>Time slot</th>
    </tr>";
    foreach($data as $table_result)
    {
    $the_result .= "<tr>
    <td>$table_result['Name']</td>
    <td>$table_result['Address']</td>
    <td>$table_result['Email']</td>
    <td>$table_result['DaysofWeek']</td>
    <td>$table_result['Timeslot']</td>

    </tr>";
    }
    $the_result .= "</table>";

    echo $the_result;

    mysql_close($con);
    ?>

    Previous versions of this answer: 08/25/11 at 5:25am | 08/25/11 at 8:32pm | 08/26/11 at 12:09am

    • 08/25/11 12:16pm

      BIG LIFE says:

      I appreciate everyone's responses thus far, but I don't think my notes are being read thoroughly. Please read the details about posting data from the database in a table where the header consists of Sunday-Saturday and the row Titles consist of the 48 half hour increments that make up each day. Please disregard the info about address and email....I think that just confused everyone. I just need the names of the people who signed up for a particular time slot on a particular day to show up in that corresponding cell on the table. I have posted a link to a site with the very item that I am trying to recreate. Please take a look at this to see what I'm going for exactly. Thanks again

    • 08/25/11 9:18pm

      ej_emman says:

      try this tell me if it helps..


      <?php

      var $con;

      function connection($server,$user,$pass)

      {
      Global $con;
      $con = mysql_connect($server,$user,$pass) or die('connection failed');
      return mysql_select_db("my_db", $con);
      }



      function my_query($sql)

      {
      $result = mysql_query($sql);
      return mysql_fetch_array($result);
      }



      connection("localhost","user","password");
      $data = my_query("SELECT * FROM example_table ORDER BY time ASC");



      //result table sample
      $the_result = "<table>
      <tr>
      <th>Time</th>
      <th>Sunday</th>
      <th>Monday</th>
      <th>Tuesday</th>
      <th>Wednesday</th>
      <th>Thursday</th>
      <th>Friday</th>
      <th>Saturday</th>
      </tr>";
      foreach($data as $result)
      {
      $the_result .= "<tr>".$result['time']."<td>";

      $the_result .= "</td> <td>";
      if($result['day'] == 'sunday')
      {
      $the_result .= $result['name'];
      }

      $the_result .= "</td> <td>";
      if($result['day'] == 'monday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td> <td>";
      if($result['day'] == 'tuesday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td> <td>";
      if($result['day'] == 'wednesday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td> <td>";
      if($result['day'] == 'thursday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td> <td>";
      if($result['day'] == 'friday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td> <td>";
      if($result['day'] == 'saturday')
      {
      $the_result .= $result['name'];
      }


      $the_result .= "</td></tr>";

      }

      $the_result .= "</table>";



      echo $the_result;




      mysql_close($con);

      ?>

  • avatar
    Last edited:
    08/25/11
    2:59pm
    Aneesh Joseph says:

    i think you forgot to post the example link :)

    • 08/25/11 3:07pm

      BIG LIFE says:

      Oops my bad:

    • 08/25/11 3:07pm

      BIG LIFE says:

      http://biglifeonline.org/prayerwall_view

  • avatar
    Last edited:
    08/27/11
    11:41am
    Jurre Hanema says:

    Why bother with saving the data to the database manually? Gravity Forms already saves every form entry to the DB, so it seems to me you are needlessy complicating things.

    If you want to display the data later (say, in a HTML table), simply pull the data from Gravity Forms using either one of GF's (internal) functions or a custom DB query.

This question has expired.



BIG LIFE voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.