Forums

[SOLVED] Query Multiple fields in a single row in table

jollyjollyjolly 16 Jun, 2011
Hello again!

Wonderful tool and so capable yet I hit a snag again. I am trying to query each row in my forms table to return results matched off the logged in userID.

Here is the code body ...
<table style="text-align: left; width: 100%;" border="0"
cellpadding="2" cellspacing="0">
  <tbody>
    <tr <?php if ($i % 2) echo ' style="background-color: #aaa;"';?> >
      <td style="font-weight: bold; width: 3%;">
        <?php if($MyRow->l1_user_id == $user->id){ ?>{l1_quantity} <?php } ?>
      </td>
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{salesperson} <?php } ?>
	  </td>
	  <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{l1_description} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{l1_special} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{l1_price} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{l1_total} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{date} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 10%;">
		<?php if($MyRow->l1_user_id == $user->id){ ?>{invoice_method} <?php } ?>
	  </td>
    </tr>
  </tbody>
  <tbody>
    <tr <?php if ($i % 2) echo ' style="background-color: #aaa;"';?> >
      <td style="font-weight: bold; width: 3%;">
        <?php if($MyRow->l2_user_id == $user->id){ ?>{l2_quantity} <?php } ?>
      </td>
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{salesperson} <?php } ?>
	  </td>
	  <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{l2_description} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{l2_special} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{l2_price} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{l2_total} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{date} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 10%;">
		<?php if($MyRow->l2_user_id == $user->id){ ?>{invoice_method} <?php } ?>
	  </td>
    </tr>
  </tbody>
  <tbody>
    <tr <?php if ($i % 2) echo ' style="background-color: #aaa;"';?> >
      <td style="font-weight: bold; width: 3%;">
        <?php if($MyRow->l3_user_id == $user->id){ ?>{l3_quantity} <?php } ?>
      </td>
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{salesperson} <?php } ?>
	  </td>
	  <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{l3_description} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{l3_special} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{l3_price} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{l3_total} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 15%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{date} <?php } ?>
	  </td>	  
      <td style="font-weight: bold; width: 10%;">
		<?php if($MyRow->l3_user_id == $user->id){ ?>{invoice_method} <?php } ?>
	  </td>
    </tr>
  </tbody>
</table>
<?php $i++ ?>
<br>


This returns the results for every item, EXCEPT the one fieldset it should. Basically if User is logged in as admin and id is 64, and sale is recorded for 64 it should display that users fields.

On a sidenote I have 110 fields in each row, should I be using some sort of array or is my data structure going to hinder me later?

-J
jollyjollyjolly 16 Jun, 2011
And I figured it out, but this is what happens when you spread the Karma and buy the resident expert a preemptive beer🙂

I needed to have a global like

$user =& JFactory::getUser();


actually in the body and not loitering around in the WHERE, Globals and data structures in PHP. I learn a lot every day and still feel like I know nothing, but its thrilling when ya catch the smarts for that moment!
GreyHead 21 Jun, 2011
Hi jollyjollyjolly ,

It looks as though every item in the row is conditional on the User ID - in that case it might be easier to filter the data by putting something like this in the WHERE box
<?php
$user =& JFactory::getUser();
echo "WHERE `li_user_id` = '{$user->id}' ";
?>

Bob
jollyjollyjolly 21 Jun, 2011
That definitely would have saved me some time lol
This topic is locked and no more replies can be posted.