3

I need to create the rows columns like this:

enter image description here

This is testing code im just implementing the logic for snapshot.

source code

    $data = array('early','early','comment1','comment2','20','30');


   function create_table($data)
   {
   $res = '<table width="200" cellpadding="1" cellspacing="1" border="1">';
   $max_data = sizeof($data);
   $ctr = 1;
      foreach ($data as $db_data)
      {
            if ($ctr % 2 == 0) $res .= '<td>' . $db_data. '</td></tr>';
              else
              {
              if ($ctr < $max_data) $res .= '<tr><td>' . $db_data. '</td>';
               else $res .= '<tr><td colspan="2">' . $db_data. '</td></tr>';
              }
            $ctr++;
      }
      return $res . '</table>';
   }

 echo create_table($data);

html

          <h2>Entry Fee</h2>

        <table border="0" class="tb not-mobile">
        <tr>
        <td width="30%" rowspan="3">Early (Payment received by 1/4/15) </td>
        <td width="58%">MD/DO</td>
        <td width="12%" class="aligncenter">$23</td>
        </tr>
        <tr>

        <td>CRNA/PA</td>
        <td class="aligncenter">$37</td>
        </tr>
        <tr>
        <td>RESIDENT/RN/OTHERS</td>
        <td class="aligncenter">$49</td>
        </tr>
        <tr>
        <td rowspan="3">Early (Payment received by 1/4/15) </td>
        <td>MD/DO</td>
        <td class="aligncenter">$23</td>
        </tr>
        <tr>

        <td>CRNA/PA</td>
        <td class="aligncenter">$37</td>
        </tr>
        <tr>
        <td>RESIDENT/RN/OTHERS</td>
        <td class="aligncenter">$49</td>
        </tr>
        </table>
  • this raw html that snapshot shows.
  • i trying build same logic similar as snapshot.

array structure

        Array
        (
        [0] => Array(
        [type] => General Public Tickets Adult
        [metadata] => Array(
        [0] => Array(
        [amount] => 50
        [comment] => (Working Days)
        )
        [1] => Array(
        [amount] => 80
        [comment] => (Saturday/ Sunday/ Holiday)
        )
        )
        )

        [1] => Array(
        [type] => Special Tickets Children
        [metadata] => Array(
        [0] => Array(
        [amount] => 300
        [comment] => (Saturday/ Sunday/ Holiday)
        )
        [1] => Array(
        [amount] => 10000
        [comment] => (Monday afternoon)
        )
        )
        )
        )
6
  • stackoverflow.com/questions/9821103/… Commented Oct 13, 2014 at 12:20
  • yup but i refer link to but unable to make logic some like snapshot Commented Oct 13, 2014 at 12:21
  • If by "dynamic" you means to make the programm display the information when they arrives (in this case, paiements which come if I correctly understood), you can't do this by using only php and html because those 2 langages are not dynamic, which means each of those lines are "read" by the webrowser, and cannot be read twice or more. You can do so by implementing javascript. Commented Oct 13, 2014 at 12:23
  • i just need to create similar logic as same as snapshot Commented Oct 13, 2014 at 12:27
  • case 1 . when type =is greater then 1 or comment >1 Commented Oct 13, 2014 at 12:28

1 Answer 1

2

It is not possible the way you want it to be done. You have to create a 2D array and get the data from that. Here is an example:

<?php
// On the line below, create your own associative array:
$myArray = array (  'Early (Payment received by 1/4/15)' => array('MD/DO', '$23','RNA/PA', '$37','RESIDENT/RN/OTHERS', '$49'),
                    'Early (Payment received by 1/4/15) ' => array('MD/DO', '$23','RNA/PA', '$37','RESIDENT/RN/OTHERS', '$49'));

// On the line below, loop through the array and output
// *all* of the values to the page:
print '<table width="800" cellpadding="1" cellspacing="1" border="1">';
foreach ($myArray as $place => $task) 
{
    print "<tr><td rowspan='4'>".$place."</td></tr>";
    $i = 0;
    print "<tr>";
    foreach ($task as $thingToDo)
    {
        $i++;
        if ($i == 2)
        {
            print "<td>".$thingToDo."</td>";
            print "</tr>";
            $i = 0;
        }
        else
        {
            print "<td>".$thingToDo."</td>";
        }
    }
}
print " </table>";
?>

Output: enter image description here

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

can you help when array structure that i have updated what changes should i have t do according updated array structure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.