By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,172 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,172 IT Pros & Developers. It's quick & easy.

Do I need to empty or delete thişs array somewhere ?

100+
P: 290
Hi,

I have written a script that is listing articles from my article table
and displaying the titles ten on each page.

As I need to calculate and print other stuff in between the extracting
and the displaying of article titles, I use an array to catchj the data.

The mysql query just grabs the first ten

thats because $start = 0 and #last = 9

Expand|Select|Wrap|Line Numbers
  1.     $sql = "SELECT tute_id,tute_head,tutes.user_id,clients.sc_name FROM tutes,clients WHERE cat_cd = '$N_cat_cd' AND live = 'y' AND tutes.user_id = clients.user_id LIMIT $start,$last";
  2.   $result = mysql_query($sql)    or die("could not execute find TUTORIALS query". mysql_error());  
  3.  
  4.  
  5. while($row = mysql_fetch_assoc($result)){
  6.       extract($row);
  7.       $Rctr =$row_ctr+1;
  8.         $scn = strtolower(trim($sc_name));
  9.       $link1 = "something.html";
  10.         $link2 = "something_else.html";
  11.  
  12.          $tute_list[] = array('num' => $Rctr, 't_head' => $tute_head, 'scn' => $scn, 'link1' => $link1, 'link2' => $link2, 's_nm' => $sc_name);       
  13.  
  14.          $row_ctr = $row_ctr + 1;
  15.        $ad_ctr = $ad_ctr + 1;            
  16.         }  // end while
  17.     }  // end else
  18.  
Later on in the same script I print these out:

Expand|Select|Wrap|Line Numbers
  1. print_r($tute_list);  // test print
  2.  
  3. for($i = 0; $i < 10; $i++){
  4.         echo <<<EOD
  5. <div class="listerdiv">
  6.  <h2>{$tute_list[$i]['num']}) <a href="{$tute_list[$i]['link1']}">{$tute_list[$i]['t_head']}</a></h2>
  7.  <h3>By  <a href="{$tute_list[$i]['link2']}">{$tute_list[$i]['s_nm']}</a></h3>
  8.  </div>
  9. EOD;
  10.     }  // end for loop
  11. echo "</div>";
  12.  

This is fine, except that when I hit my "next page" link
and come back to the same script with new values for start and last,
my array is causing problems !

Maybe I need to delete it or empty it before filling it up again ?
This a multi-dimension array

As I don't pass the array with the href link, I thought that it would be
deleted anyway, but I get these errors on the second page:


Notice: Undefined variable: tute_list in /home/chosy/public_html/mem_tutes.php on line 205

Notice: Undefined variable: tute_list in /home/chosy/public_html/mem_tutes.php on line 210

Notice: Undefined variable: tute_list in /home/chosy/public_html/mem_tutes.php on line 210

Notice: Undefined variable: tute_list in /home/chosy/public_html/mem_tutes.php on line 210

These lines of code are the array display section

My test print print_r($tute_list); shows a good array on the first page, but nothing on
the second page, i.e. when I re-run the script with the "next page" href link



Can anyone see what I've done wrong ?
Jan 27 '09 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
You define your array inside that while loop on line 5. I would believe that your while loop is returning false before the array is defined and, therefore, you are never getting that array. Are you sure there are enough records in your database? You should check that $tute_list exists (isset()) before printing it out.
Jan 27 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
additionally, (for debugging) you should check if all 3 variables of your SQL statement are set correctly.
Jan 27 '09 #3

100+
P: 290
Thank you for your advice.

I checked out the variables and located the problem :)
Jan 27 '09 #4

Markus
Expert 5K+
P: 6,050
Glad we could help.
Jan 27 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.