Jump to content

Continuing aray problem.


Lassie

Recommended Posts

Mant thanks to those who have helped with this problem before. I have moved on but am still in trouble.
I am trying to build a download link for customers to pick_up their purchases.

The logic is:
1. pass the cart variables and the product id to a function which retrieves the
download file reference from the database.
2.make an array of the results which is returned to a function which will store them in a variable.
This will be used to copy the file to a pick up folder.

I am printing the links to establish that I have this part working correctly.

The problem is my array is only capturing the last prouct selection.
The code is:
//Call the function to retirieve the download link from the database.

$dl_link=display_dl_link2($_SESSION['cart'],'product_id');

//function display_dl_link2

function display_dl_link2($cart,$product_id)

{
foreach ($cart as $product_id => $qty)
{
echo "The value of $product_id is $qty<br />";//print products as debug check. All selected products show.
}
// capture the product ids

  if (!$product_id || $product_id=='')
  {
    return false;
    }
$connection = db_connect();   
  $query = "select dl_link from products where product_id='$product_id'";
  $result = mysql_query($query);
  if (!$result)
  {
mysql_error();
return false;
}

  if(mysql_num_rows($result)==0)
  {
  echo "there were no results";

}else {
$result = db_result_to_array($result);//array shows only the last product selection
  return $result;
{
}
}
}

This is the debug result I get

The value of 6 is 1
The value of 13 is 1

Array
(
    [0] => Array
        (
            [dl_link] => the download link
        )

)

Any help appreciated.
Note to Editior
You have previously asked me to enclose my code in code tags.Could you give me an example please.
lassie
Link to comment
https://forums.phpfreaks.com/topic/33454-continuing-aray-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.