Forum Moderators: coopster & phranque

Message Too Old, No Replies

While statement

While statement with AndOr

         

Mitch888

7:08 pm on Apr 9, 2003 (gmt 0)

10+ Year Member



Hi,
I need the below code to list (in one table) the “Date”, “CC”, “PayPal” and “Total”. Keap in mind that on same date there are CC data in cc table and also (same date) there could be PayPal data.

I was successful into displaying the data one after each other by using [or] in the while statement.
(Date)********(PayPal)********(CC)********(Total)
(2003-4-21)*****(50)**********(0)**********(50)
(2003-4-21)*****(0)**********(20)**********(70)
(2003-4-22)*****(50)**********(0)**********(120)

Also, I was successful into displaying the data that have same date (CC & PayPal) by using [and] in the while statement.
(Date)********(PayPal)********(CC)********(Total)
(2003-4-21)*****(50)**********(20)**********(70)

What I need, is to display all data unique and similar dates.
Example what I want:

(Date)********(PayPal)********(CC)********(Total)
(2003-4-21)*****(50)**********(20)**********(70)
(2003-4-22)*****(50)**********(0)**********(120)

please help

<table width="55%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#FFCC99">
<td><div align="center"><font color="#000000">Date</font></div></td>
<td><div align="center"><font color="#000000">PayPal</font></div></td>
<td><div align="center"><font color="#000000">CC</font></div></td>
<td><div align="center"><font color="#000000">Total</font></div></td>
</tr>
<?

$sql="select *from cc";
$result = $db->EXECUTE($sql);

$sqlx="select *from paypal";
$resul = $db->EXECUTE($sqlx);

$o = 0;
$w = 0;

while ($i = mysql_fetch_array($result) and $dd = mysql_fetch_array($resul)){

$o = $i[lu_withdraw];
$w = $dd[amount];
if ($i[lu_date] && $dd[date]){
$sdate = $i[lu_date];
}elseif ($i[lu_date] XOR $dd[date]){
$sdate = $i[lu_date].$dd[date];
}
$bax += $o + $w;

<tr bgcolor="#FFFFCC">
<td><div align="center"><? echo "<font color='#000000'>$sdate</font>";?></div></td>
<td><div align="center"><? echo"<font color='#990000'>$w</font>";?></div></td>
<td><div align="center"><? echo"<font color='#660099'>$o</font>";?></div></td>
<td><div align="center"><? echo"<font color='#FF0000'>$bax</font>";?></div></td>
</tr>
<?
}
?>

jatar_k

3:21 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am not totally sure what the exact problem is. You mentioned "display all data unique and similar dates" then there is a bunch of code.
Does the code work?
Is it giving you a specific error?
Or is it not working at all?

Mitch888

3:48 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



code works, but I can't get it to do what I want. I have two tables one for CC and one for PayPal. both tables have a date field (date when transaction occured).

I can display the results of either CC or paypal table. However, I need to display the results of both tables at once and not one at a time.

the code above can do that with the exception of the date field.

example: on 2003-4-5 there was a transaction of $5 CC and on the same date, there was a transaction of $66 PayPal. I need to display the following:
(date)*******(PayPal)*******(CC)********(total)
(2003-4-5)*******(66)*******(5)*********(71)

how do I do that? how can I take results from two tables and display them at once keeping in mind that some results share same date and other results have different dates?

thank you

jatar_k

3:58 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well you could try it on the mysql side but it looks like there is nothing to join the tables on.

You may have to load them both into seperate arrays and then collate them. If you add an order by clause to both queries that should make it easier.

There seems to be no relationship between the two tables. That is what makes it difficult, there should be an easier way but I can't think of one at the moment.