NEED A BETTER WAY TO DO THIS

[php]$order1="{$ordera[1]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate1="{$duedatea[1]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc1="{$jobdesca[1]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc1="{$adddesca[1]}";
$pricea=unserialize($orders[‘price’]);
$price1="{$pricea[1]}";

$order2="{$ordera[2]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate2="{$duedatea[2]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc2="{$jobdesca[2]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc2="{$adddesca[2]}";
$pricea=unserialize($orders[‘price’]);
$price2="{$pricea[2]}";

$order3="{$ordera[3]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate3="{$duedatea[3]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc3="{$jobdesca[3]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc3="{$adddesca[3]}";
$pricea=unserialize($orders[‘price’]);
$price3="{$pricea[3]}";

$order4="{$ordera[4]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate4="{$duedatea[4]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc4="{$jobdesca[4]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc4="{$adddesca[4]}";
$pricea=unserialize($orders[‘price’]);
$price4="{$pricea[4]}";

$order5="{$ordera[5]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate5="{$duedatea[5]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc5="{$jobdesca[5]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc5="{$adddesca[5]}";
$pricea=unserialize($orders[‘price’]);
$price5="{$pricea[5]}";

$order6="{$ordera[6]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate6="{$duedatea[6]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc6="{$jobdesca[6]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc6="{$adddesca[6]}";
$pricea=unserialize($orders[‘price’]);
$price6="{$pricea[6]}";;[/php]
I need the number to go all the way down to 15 from 0 and I need it this way so I can split up the serialized information onto the correct lines as needed:

[php]
$order15="{$ordera[15]}";
$duedatea=unserialize($orders[‘duedate’]);
$duedate15="{$duedatea[15]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
$jobdesc15="{$jobdesca[15]}";
$adddesca=unserialize($orders[‘adddesc’]);
$adddesc15="{$adddesca[15]}";
$pricea=unserialize($orders[‘price’]);
$price15="{$pricea[15]}";[/php]

I tried to use a for statement $x=0;$x<16;$x++
then using the $x variable but it seems that $price$x just wont work :stuck_out_tongue: it works for:
[php] ="{$pricea[$x]}";[/php]
so if you know a better way to write this it sure would help!!!

Try this
[php]$x=0;
for($x=0;$x<16;$x++){
${order.$x}="{$ordera[$x]}";
$duedatea=unserialize($orders[‘duedate’]);
${$duedate.$x}="{$duedatea[$x]}";
$jobdesca=unserialize($orders[‘jobdesc’]);
${$jobdesc.$x}="{$jobdesca[$x]}";
$adddesca=unserialize($orders[‘adddesc’]);
${$adddesc.$x}="{$adddesca[$x]}";
$pricea=unserialize($orders[‘price’]);
${price.$x}="{$pricea[$x]}";;
}[/php]

What your after is a variable variable.
More information here http://php.net/manual/en/language.variables.variable.php

thanks that is saving me a ton of space on the page, you know I tried something similar:
[php]$x=0;
for($x=0;$x<16;$x++){
$order.$x="{$ordera[$x]}";[/php]

but I had no idea I had to put the variable variable in braces to make it work I am gonna go trip on this for a bit, this was a new one for me but it seems my queries and php have been having to get more tricky with this new site I am working on.
Thanks again!!

oh boy variable variables looks like it is going to be fun!!! :stuck_out_tongue: I never had the need or them but I think I am gonna start 8) there is a ton of good stuff in there!!

oh I forgot, I had to come back and give you a +1 karma 8)

Thankyou :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service