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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

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

    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

    Code:
    	$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";
      $result = mysql_query($sql)	or die("could not execute find TUTORIALS query". mysql_error());  
    
    
    while($row = mysql_fetch_assoc($result)){
    	  extract($row);
    	  $Rctr =$row_ctr+1;
    		$scn = strtolower(trim($sc_name));
    	  $link1 = "something.html";
    		$link2 = "something_else.html";
    		
    		 $tute_list[] = array('num' => $Rctr, 't_head' => $tute_head, 'scn' => $scn, 'link1' => $link1, 'link2' => $link2, 's_nm' => $sc_name);       
    
    		 $row_ctr = $row_ctr + 1;
    	   $ad_ctr = $ad_ctr + 1;			
    		}  // end while
    	}  // end else
    Later on in the same script I print these out:

    Code:
    print_r($tute_list);  // test print
    
    for($i = 0; $i < 10; $i++){
    		echo <<<EOD
    <div class="listerdiv">
     <h2>{$tute_list[$i]['num']}) <a href="{$tute_list[$i]['link1']}">{$tute_list[$i]['t_head']}</a></h2>
     <h3>By  <a href="{$tute_list[$i]['link2']}">{$tute_list[$i]['s_nm']}</a></h3>
     </div>
    EOD;
    	}  // end for loop
    echo "</div>";

    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_l ist); 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 ?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      additionally, (for debugging) you should check if all 3 variables of your SQL statement are set correctly.

      Comment

      • jeddiki
        Contributor
        • Jan 2009
        • 290

        #4
        Thank you for your advice.

        I checked out the variables and located the problem :)

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Glad we could help.

          Comment

          Working...