-1

Trying to view individual row from the relational table according to id like as if I click a button then I want to view this row in an iframe modal with the new tab. It's working as expected also parent table data, but the issue is child table data it's always showing one for all id.In the below I added screenshot also my code.

In the below screenshot date column is working as expected when I click view button the problem is other columns those coming from the child table.

enter image description here

This is the modal screenshot which will open by clicking on the view button

enter image description here

Code:

<?php 

  $id= $_GET['id'];                    
  $qry = mysql_query("select t.*, u.zip AS zip, u.acct_type AS acct_type from transport as t,users as u WHERE t.id=$id ");


  if($qry === FALSE) {

     die(mysql_error()); // TODO: better error handling

   }

     $data = mysql_fetch_array($qry);    

   ?> 


      <tr role="row" class="even">
          <td style="display:none;"><?php echo $data['id'];?></td>    
          <td class="sorting_1">
            <?php
             $datess = $data['create_date'];
             $old_date_timestamp = strtotime($datess);
             echo date('m-d-Y', $old_date_timestamp);
                         ?>                                                                                          </td>                                                                  <td>                                                             <?php                                   
           $acct_type = $data['acct_type'];

            if($acct_type == 0)
             {
              echo "Admin";
             }

             elseif($acct_type == 3)
             {
               echo "User";
             }

             elseif($acct_type == 4)
             {
               echo "Guest User";
             }

             elseif($acct_type == 5)
             {
               echo "Administrator";
             }

             else
              {
                echo "Trial User";
               }    
              ?>

           </td>
           <td><?php echo $data['zip'];?></td>                                     

        </tr>       

There users table is child table

Anyone can help me please where the bug?

Fameless
  • 345
  • 3
  • 17

1 Answers1

0

Debugging code helps when its more readable, try using better methods where they should go like replacing your if statement with a switch since you know its outcome:

switch ( $data['acct_type'] )
{
    case 0:
        echo 'Admin';
        break;
    case 3:
        echo 'User';
        break;
    default:
        echo 'Unknown';
        break;
}

More-over, mysql is depreciated in most PHP versions - you should move away from any usage of the protocol unless you're using PDO - this could be one of the reasons you're not getting your expected behavior.

Without any errors, you're basically asking us to debug your program which is pretty much impossible without your data or representation of your tables.

You can read these sources to learn further about readability and debugging your code:

Both of which link into one another.

Edit: I'd suggest using some var_dumps() around your queries.

Community
  • 1
  • 1
Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • I know mysql is deprecated, but the site owner is not interested to update. Thanks for the researchable answer. – Fameless Apr 12 '16 at 11:47
  • It shouldn't be hard to update anything if you've written it OOP. I can only suggest that you debug bit by bit, enable error logging and in the future make it more readable so you understand whats doing what simply. – Jaquarh Apr 12 '16 at 11:48
  • I think anyone didn't ask any question before trying all possible ways. – Fameless Apr 12 '16 at 11:54