ess14 Posted November 27, 2006 Share Posted November 27, 2006 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 7is 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 Could you tell us the actual situation you want to apply this too? The example on its own doesn't make much sense :) Quote Link to comment Share on other sites More sharing options...
ess14 Posted November 27, 2006 Author Share Posted November 27, 2006 why doesnt the example make sense?if you cant move the $val = 7, how do you make $val2 = $val?? Quote Link to comment Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 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] Quote Link to comment Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 Or is it sessions you are looking for? That lets you keep values of variables between script calls. Quote Link to comment Share on other sites More sharing options...
ess14 Posted November 27, 2006 Author Share Posted November 27, 2006 $val2 = &$val;$val = 7;echo $val2; // Shows 7doesnt 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.... Quote Link to comment Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 No, I don't see what you're getting at. Can you post your actual code and tell me what you're trying to do with it? Quote Link to comment Share on other sites More sharing options...
ess14 Posted November 27, 2006 Author Share Posted November 27, 2006 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 belowecho $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. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 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? Quote Link to comment Share on other sites More sharing options...
ess14 Posted November 27, 2006 Author Share Posted November 27, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.