Jump to content

Help with order of code


herghost

Recommended Posts

Evening everyone

 

I wonder if you can help me with the below code

<table width="823" cellspacing="0" id="mytable" summary="User Transactions Summary"> 
<caption>Transaction Summary</caption> 


  <tr> 
    <th width="136" class="nobg" scope="col" abbr="Merchant Name">Merchant Name</th> 
    <th width="154" scope="col" abbr="Order Value">Order Value</th> 
    <th width="145" scope="col" abbr="Comm">Cash Back</th> 
<th width="278" scope="col" abbr="Status">Status</th> 
  </tr> 
<?php 
$result = mysql_query("SELECT * FROM transactions WHERE u_id = '$u_id' ORDER BY order_date DESC LIMIT 10 "); 
echo mysql_error() ;

while($row = mysql_fetch_assoc($result)){

$m_name = $row['m_name'];
$orderval = $row['order_val'];
$status = $row['order_status'];
$m_affid = $row['m_affid'];

$query = mysql_query(" SELECT percent FROM merchants WHERE m_affid = '$m_affid' LIMIT 1");
$num = mysql_num_rows($query);
$i=0;
while ($i < $num) {

$per=mysql_result($query,$i,"percent");

$i++;
}

$com1 = $orderval / 100;
$com2 = $com1 * $per;

$u_comm = round($com2,2);

?>
    

    

  <tr> 
    <th scope="row" abbr="<?php echo $m_name;?>" class="spec"><?php echo $m_name;?></th> 
    <td class="alt">&pound<?php echo $orderval ;?></td> 
    <td class="alt">&pound<?php echo $u_comm ;?></td> 
    <td class="alt"><?php echo $status ;?></td> 
    
  </tr> 
  <?php
}?>  

</table> 

 

Basically it is meant to simply show fields from a database in a table.

 

If there is only 1 entry for  a u_id it works fine, however if their is more than one then the $u_comm value shows the same for all results, which is for the last result/row found.

 

Hope this makes sense!

 

Link to comment
Share on other sites

Let me know if it doesn't work, please specify any problems fully.

<table width="823" cellspacing="0" id="mytable" summary="User Transactions Summary"> 
<caption>Transaction Summary</caption> 
  <tr> 
    <th width="136" class="nobg" scope="col" abbr="Merchant Name">Merchant Name</th> 
    <th width="154" scope="col" abbr="Order Value">Order Value</th> 
    <th width="145" scope="col" abbr="Comm">Cash Back</th> 
<th width="278" scope="col" abbr="Status">Status</th> 
  </tr> 
<?php 
$result = mysql_query("SELECT t.*, m.percent FROM transactions JOIN merchants ON t.m_affid = m.m_affid WHERE u_id = '$u_id' ORDER BY t.order_date DESC LIMIT 10 "); 
echo mysql_error() ;
while($row = mysql_fetch_assoc($result)){	

$m_name = $row['m_name'];
$orderval = $row['order_val'];
$status = $row['order_status'];
$per = $row['percent'];


$com1 = $orderval / 100;
$com2 = $com1 * $per;
$u_comm = round($com2,2);
?>
  <tr> 
    <th scope="row" abbr="<?php echo $m_name;?>" class="spec"><?php echo $m_name;?></th> 
    <td class="alt">&pound<?php echo $orderval ;?></td> 
    <td class="alt">&pound<?php echo $u_comm ;?></td> 
    <td class="alt"><?php echo $status ;?></td> 
    
  </tr> 
  <?php
}?>  

</table> 

Link to comment
Share on other sites

$result = mysql_query("SELECT t.*, m.percent FROM transactions AS t JOIN merchants AS m ON merchants ON t.m_affid = m.m_affid WHERE u_id = '$u_id' ORDER BY t.order_date DESC LIMIT 10 "); 

 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON t.m_affid = m.m_affid WHERE u_id = '23' ORDER BY t.order_date DESC LIMIT 10' at line 1

 

I think I have a lot to learn.........

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.