Jump to content

Recommended Posts

I am trying to debug a script that provides a download link from a shopping cart.
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 prints the link(s) and 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 code is:

//call the functions
$dl_link=display_dl_link2($_SESSION['cart'],'product_id');result (links) are returned to $dl_link

display_dl_link($dl_link);//print the links.

function display_dl_link2($cart,$product_id)
{

foreach ($cart as $product_id => $qty){
echo "The value of $product_id is $qty<br />";//de-bug code: This gives values
}
// query database for the relevant file references book

  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 {
while ($row = mysql_fetch_assoc($result)){
  echo $row['dl_link'];
$dl_link = $row['dl_link'];


   
$result = db_result_to_array($result);
   
  return $result;
  }
}
}

function db_result_to_array($result)
{
  $res_array = array();

  for ($count=0; $row = mysql_fetch_assoc($result); $count++)
    $res_array[$count] = $row;

  return $res_array;
}
function display_dl_link($dl_link)
{
if (!is_array($dl_link))
  {
    echo 'No dl links currently available<br/>';
    return;

  }
 
foreach ($dl_link as $row)
  {
  $link = $row['dl_link'];
  echo "this is the reference $link";
}
}
What I get is the no array message - No dl links currently available.

Can anyone suggest how I can find out what is going wrong?
Link to comment
https://forums.phpfreaks.com/topic/32115-problem-with-array/
Share on other sites

Thanks for the help.
I am not getting an error message.
The function display_dl_link2 seems not to return an array back to function display_dl_link.
I have checked that dl_link is populated before the db_results_to array function is called.
How would I check that display_dl_link has been populated?
Thanks for your help.
lassie
Link to comment
https://forums.phpfreaks.com/topic/32115-problem-with-array/#findComment-149398
Share on other sites

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.