Lassie Posted December 28, 2006 Share Posted December 28, 2006 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 thedownload 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? Quote Link to comment https://forums.phpfreaks.com/topic/32115-problem-with-array/ Share on other sites More sharing options...
Psycho Posted December 28, 2006 Share Posted December 28, 2006 What is the exact error message and what line is throwing the error?EDIT: Also, please edit your post to put the code within CODE tags. Quote Link to comment https://forums.phpfreaks.com/topic/32115-problem-with-array/#findComment-149031 Share on other sites More sharing options...
sasa Posted December 28, 2006 Share Posted December 28, 2006 [code]try to close this if block [if (!$result){ mysql_error(); return false;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32115-problem-with-array/#findComment-149043 Share on other sites More sharing options...
Lassie Posted December 29, 2006 Author Share Posted December 29, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/32115-problem-with-array/#findComment-149398 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.