Jump to content

mental blank - how do i...


ess14

Recommended Posts

i think there is an easier way to do what i want, but maybe not... but im just totally drawing a blank. maybe ive been awake for too long. here is an [u]example:[/u]

$val2 = $val;
echo $val2;  // shows nothing
$val = 7;
echo $val;  //shows 7

is there any way, after the script has been output, to give $val2 the value of $val?

see, i dont want to move "$val = 7" around.... ideally i want $val to be given the value, and once that is done basically run the "$val2 = $val" again. what am i supposed to do? argh, im lost.

Link to comment
Share on other sites

It doesn't make sense becuase you said "After the script has been output".  Once a script has run, no variables have any values.  That's how I interpret it anyway :)

This might be what you want:

[code=php:0]$val2 = &$val;
$val = 7;
echo $val2; // Shows 7[/code]
Link to comment
Share on other sites

$val2 = &$val;
$val = 7;
echo $val2; // Shows 7
doesnt work.....

its because i have to lay the script out like this:
$val2 = &$val;
echo $val2;
$val = 7;

with that layout, i need val2 to = val.
see what im gettign at? or should i just have a break and work it out for myself? lol theres probably no real easy way to do it....


Link to comment
Share on other sites

ok, here is the code. i have had to cut out all the html and other bits of crap that i dont THINK have anything to do with what i want.

[code=php:0]
<?php
$sql=" SELECT s.artist_name,od.artist_id,o.*, u.user_name, u.email,
sum((od.product_price-(od.product_price*product_discount/100)) * od.product_quantity)
as total,od.artist_payment_status FROM ".$tableprefix."orders o
INNER JOIN " . $tableprefix . "users u ON o.user_id = u.user_id
INNER JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id
INNER JOIN " . $tableprefix . "artists s ON od.artist_id = s.artist_id
WHERE od.item_status > '0'
AND od.artist_payment_status <= 1 AND (od.artist_id = '".addslashes($artist)."') AND (o.order_id IN (".addslashes($orderlist)."))
GROUP BY od.artist_id, o.order_id ORDER BY od.artist_id    ";

$res = mysql_query($sql);

//TRYING TO GIVE THIS THE SAME VALUE AS THE other $totalcommission below
echo $totalcommission;
$i=$begin+1;
$totalamount = 0;
$totalcommission = 0;
$totalaftercommission = 0;
while($row = mysql_fetch_array($res)){
$link = "<a class=links href='vieworder.php?orderid=".$row["order_id"]."' target='_blank'>";
$check = "<input class=checkbox type='checkbox' name='chkorders[]' value='" . $row["order_id"]."`".$row["artist_id"] . "' > ";
$amount = $row["total"];
$totalamount  += $amount;
$commission = (($amount*$artistcommission)/100);
$totalcommission += $commission;
$amountaftercommission = $amount - $commission;
$totalaftercommission += $amountaftercommission;
//THIS IS THE BOTTOM $totalcommission.
echo $totalcommission;
$i++; }
?>
[/code]

i have tried copying the WHILE statement up top... but when i do that.. i only get the top $totalcommission and the bottom $totalcommission comes up as 0....
i was under the impression i could call the $sql statement as many times as i like? it seems like it calls it only once and then loses the data? if that makes sense. maybe its just stuffing the while.. i dunno. argh. help. lol. sorry im kinda confusing.
Link to comment
Share on other sites

Ok.. I think that there is no way to DIRECTLY do what you want to do.  You simply can't print out a variable before it's set.

But you can do something equivalent.  You can collect all the results from your database query and store them rather than printing them out.  Then you can print $totalcommission, and then after that you can print your database results.  Like this:

[code=php:0]$output = '';
while($row = mysql_fetch_array($res)){
  $link = "<a class=links href='vieworder.php?orderid=".$row["order_id"]."' target='_blank'>";
  $check = "<input class=checkbox type='checkbox' name='chkorders[]' value='" . $row["order_id"]."`".$row["artist_id"] . "' > ";
  $amount = $row["total"];
  $totalamount  += $amount;
  $commission = (($amount*$artistcommission)/100);
  $totalcommission += $commission;
  $amountaftercommission = $amount - $commission;
  $totalaftercommission += $amountaftercommission;
//THIS IS THE BOTTOM $totalcommission.
  echo $totalcommission;
  // Here is the important line
  $output .= $link . $check . "whatever else you want to print out ... ";
  $i++;
}[/code]


Now, after all that:

[code=php:0]print $totalcommission;
print $output[/code]


Does that makes sense?
Link to comment
Share on other sites

mmm, no sorry that doesnt make sense to me.
drop $link and $check. their not really needed for this example.

if i put the while loop above my first $totalcommision.... how come when i run the same while loop later down the page it comes back with 0 results?



thanks for helping too. i know im being a bit confusing.
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.