Announcement

Collapse
No announcement yet.

anybody tried to display a little table in a field? using foreach or i++?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • anybody tried to display a little table in a field? using foreach or i++?

    Hello, i have control form, i'm using few fields as label... fields are set in events onLoad e.g.:

    {field1}= $var1
    {field2}= $var2
    {field3}= "textHere"

    Well, that works ok for single value text or number...

    I want to display a table with about 10 rows and 4 columns, don't know how to use foreach here

    my code

    Code:
    sc_lookup(rs, "SELECT name, class, number, section FROM students_table");
    
    {field4} = "<table><tr><th>Name</th><th>Class</th><th>Number</th><th>Section</th></tr><tr><td>".{rs[0][0]}."</td><td>".{rs[0][1]}."</td><td>".{rs[0][2]}."</td><td>".{rs[0][3]}."</td></tr></table>";
    That works okay..

    But i want to display all 10 rows without adding them one by one !! something like using foreach or $i++ but couldn't figure it out

    There must be a way to display this array nicely even without table!? just brain stops grrrrrrrrrrrr


    anybody tried it?

  • #2
    If you want to display the table with all results from your select, you should loop the recordset.
    Something like this (didn't test it so likely it will be full of errors)

    Code:
    $tbl_header = "<tr><th>Name</th><th>Class</th><th>Number</th><th>Section</th></tr>";
    
    $tbl_data = "";
    
    $sql = "SELECT name, class, number, section FROM students_table";
    sc_select(rs, $sql);
    if (!(false == {rs} || {rs}->EOF))
    {
        {rs}->MoveFirst();
        do
        {
            $tbl_data .= "<tr><td>" . {rs}->Fields('name')    . "</td>"
                           . "<td>" . {rs}->Fields('class')   . "</td>"
                           . "<td>" . {rs}->Fields('number')  . "</td>"
                           . "<td>" . {rs}->Fields('section') . "</td></tr>";
            {rs}->MoveNext();
        } while (!({rs}->EOF));
    }
    
    {field4} = "<table> $tbl_header $tbl_data </table>";
    Last edited by robydago; 01-30-2016, 08:33 PM.

    Comment


    • #3
      thanks robydago, it works but only shows one row of the table!!

      any hint?

      Comment


      • #4
        Are you sure your query returns more than one record?


        edit - Also, make sure you have a dot+equal here:

        Code:
        do
            {
                $tbl_data .= "<..........
        Last edited by robydago; 01-31-2016, 02:57 PM.

        Comment


        • #5
          Originally posted by robydago View Post
          Are you sure your query returns more than one record?


          edit - Also, make sure you have a dot+equal here:

          Code:
          do
          {
          $tbl_data .= "<..........
          Ooops you are right! there was where clause that limits my query result to one row

          Thanks dude, it works as expected.

          Another related Q, can I format this table? it looks primitive? any chance to make it look like the grid colors? or at least align it nicely?

          Comment


          • #6
            Mike sorry but I'm not good at that.

            Comment


            • #7
              Originally posted by robydago View Post
              Mike sorry but I'm not good at that.
              thanks roby you were so helpful already

              Just wanted to the css tags that we can use for such occasion, ofcourse we can format using html in the event itself, but thought might be better way and include more modern table style same time

              cheers dude

              Comment

              Working...
              X