Jump to content

[SOLVED] i need a logic algorithm 4 extracting multiple rows from a file based on a $var


Recommended Posts

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!

 

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

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?

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

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.