SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow Smarty question: Array don't print, why?

    Hello i have these codes below,

    PHP codes;
    Code:
       $cid = array();
       $title = array();
       $email = array();
       $add_date = array();
       $i = 0;
    
       #$result=mysql_query("SELECT * FROM your table LIMIT $limit1, $limit2");
       $query = "SELECT * FROM castingcall LIMIT $limit1, $limit2";
       $result=mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
    
    
       while($row = mysql_fetch_array($result)) {
          $cid[$i] = $row['castingid'];
          $title[$i] = $row['title'];
          $email[$i] = $row['email'];
          $add_date[$i] = $row['date_posted'];      
    
          echo "<b>". $cid[$i] ."</b>  ";
          echo " ". $title[$i];
          echo "<br>";
    
          
          $smarty->assign('cid', $cid);
          $smarty->assign('title', $title);
          $smarty->assign('email', $email);
          $smarty->assign('add_date', $add_date);      
       
          $i++;
       }   
    
    $adminsmarty -> display( "modules/admin/viewparsingcalls.tpl" );
    Smarty codes;
    Code:
    <ul> {foreach from=$cid item=foo} <li>{$foo}</li> {/foreach} </ul>
    
    <ul> {foreach from=$title item=foo} <li>{$foo}</li> {/foreach} </ul>
    Question: Why is it i did not print the value of the array?
    What is the problem with my array & foreach?


    Any help please...

    Thank you in advance

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Location
    Bavaria, Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you overwrite the variables in your while loop, so cid never is an array in smarty but an integer or a string or whatever. try:

    PHP Code:
    while($row mysql_fetch_array($result)) {
        
    $cid[$i] = $row['castingid'];
        
    $title[$i] = $row['title'];
        
    $email[$i] = $row['email'];
        
    $add_date[$i] = $row['date_posted'];      

        echo 
    "<b>"$cid[$i] ."</b>  ";
        echo 
    " "$title[$i];
        echo 
    "<br>";
        
    $i++;
    }
    $smarty->assign('cid'$cid);
    $smarty->assign('title'$title);
    $smarty->assign('email'$email);
    $smarty->assign('add_date'$add_date); 

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thanks but i already solve this problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •