johnwayne77 Posted September 22, 2008 Share Posted September 22, 2008 i have this code: $result = mysql_query("SELECT products_id FROM orders_products WHERE orders_id = $order_no ") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $var = file("var" . $row['products_id'] . ".txt"); $first_var = array_shift($var); $var= array_map('trim', $var); file_put_contents("var" . $row['products_id'] . ".txt", implode(PHP_EOL, $var)); echo $first_var; } so, in a few words: i have a table with orders. for order number $order_no there is the $products_id ordered . for each product ordered i want to extract a code from that var.txt file. the problem is that i may have more than 1 unit of $products_id ordered. therefore, i have another field in the table: $order_qty (e.g. $order_qty = '3'; ) the problem is that i don't know how to extract 3 codes (or whatever the $order_qty is) for the $products_id i don't have any algorithm in my head, please help.. cheers! Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/ Share on other sites More sharing options...
FVxSF Posted September 22, 2008 Share Posted September 22, 2008 I don't fully understand what you're asking. But maybe GROUP BY could help? Or are you asking to also get the quantity ordered from the table? Which would be easy just add order_qty (or what ever you named the table) after products_id: SELECT products_id, order_qty FROM Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-647909 Share on other sites More sharing options...
johnwayne77 Posted September 22, 2008 Author Share Posted September 22, 2008 yes, i extract order_qty by the SELECT command..but i'm stuck when i'm extracting the $first_var from the var.txt i mean, based on my earlier code, i extract only the first line (1 line) from that .txt but if the quantity is 2 units let's say, i need to extract first two lines ... are you with me? Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-647930 Share on other sites More sharing options...
sasa Posted September 22, 2008 Share Posted September 22, 2008 $first_var = array(); for($i = 0; $i < $order_qty; $i++) $first_var[] = array_shift($var); print_r($first_var); Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-647943 Share on other sites More sharing options...
johnwayne77 Posted September 22, 2008 Author Share Posted September 22, 2008 i'm not sure how to adapt this to my code.. Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-647982 Share on other sites More sharing options...
johnwayne77 Posted September 22, 2008 Author Share Posted September 22, 2008 any idea? Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-648047 Share on other sites More sharing options...
johnwayne77 Posted September 22, 2008 Author Share Posted September 22, 2008 nevermind, i was misleaded coz i've replaced a var with another and it didnt worked... so here is the result i get: Array ( [0] => 44444444444444444444444 [1] => 555555555555555555 [2] => 666666666666666666666 [3] => [4] => ) any idea how i can get each array in its variable to use? coz in $first_var i have all 5 arrays... but i would need a loop to echo each array .. like $first_var[] or something.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-648090 Share on other sites More sharing options...
johnwayne77 Posted September 22, 2008 Author Share Posted September 22, 2008 foreach is the answer thanks for the help dudez! Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-648171 Share on other sites More sharing options...
sasa Posted September 23, 2008 Share Posted September 23, 2008 is it solved Quote Link to comment https://forums.phpfreaks.com/topic/125347-solved-i-need-a-logic-algorithm-4-extracting-multiple-rows-from-a-file-based-on-a-var/#findComment-648411 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.