За последние 24 часа нас посетили 27543 программиста и 1815 роботов. Сейчас ищут 1927 программистов ...

помогите разобратся в Smarty

Тема в разделе "PHP для новичков", создана пользователем Lexx, 31 июл 2008.

  1. Lexx

    Lexx Активный пользователь

    С нами с:
    31 июл 2008
    Сообщения:
    35
    Симпатии:
    0
    На чал изучать Smarty и столкнулся вот с какой проблемой:
    Имеется файл который выводит из база банных MySql таблицу (с выводом все нормально), проблеме заключается в том что мне надо чтобы smarty передал эту таблицу в HTML файл собственно он и передает но только первую запись в таблице.
    Вот собственно что я написал:

    PHP файл - subjects.php

    <?
    $namehost = "localhost";
    $nameuser = "root";
    $nemedatabase = "forum";
    $nametablesubjects = "subjects";
    mysql_connect($namehost, $nameuser);

    $res=mysql_query("SELECT * FROM subjects");
    while($row=mysql_fetch_array($res))
    {

    $name = $row['name'];
    $text = $row['text'];
    }

    require ('/WEB_Server/Host/Children.com/setup.php');
    $smarty = new Smarty_GuestBook;
    $smarty->force_compile = TRUE;
    $smarty->assign('name', $name);
    $smarty ->assign('text', $text);
    $smarty->display('subjects.html');
    ?>
    *****************************************************************


    HTML файл - subjects.html

    <body background='/piktyrs/4567.jpg'>
    <table width='100%' border='2' cellspacing='2' cellpadding='2'>
    <tr>
    <td width='20%'><div align='center'>Имя</div></td>
    <td><div align='center'>Сообщени</div></td>
    </tr>
    <tr>
    <td width='20%'>{$name}</td>
    <td>{$text}</td>
    </tr>
    <tr>

    </tr>
    </table>



    :?:
     
  2. nimistar

    nimistar Активный пользователь

    С нами с:
    30 май 2007
    Сообщения:
    919
    Симпатии:
    0
    PHP:
    1. <?
    2. ...
    3. $res=mysql_query("SELECT * FROM subjects");
    4. while($row=mysql_fetch_assoc($res))
    5. {
    6. $rows[]= $row;
    7. }
    8.  
    9. ...
    10. $smarty->assign('rows', $rows);
    11. ...
    12. ?>
    13.  

    HTML файл - subjects.html
    HTML:
    1.  
    2. <body background='/piktyrs/4567.jpg'>
    3. <table width='100%' border='2' cellspacing='2' cellpadding='2'>
    4. <tr>
    5. <td width='20%'><div align='center'>Имя</div></td>
    6. <td><div align='center'>Сообщени</div></td>
    7. </tr>
    8. {foreach item=row from=$rows name=list_rows}
    9.     <tr>
    10.      <td width='20%'>{$row.name}</td>
    11.      <td>{$row.text}</td>
    12.     </tr>
    13. {/foreach}
     
  3. Lexx

    Lexx Активный пользователь

    С нами с:
    31 июл 2008
    Сообщения:
    35
    Симпатии:
    0
    большое спасибо все заработала!!!!!!!!!!!!!!!!!!!!!!!!!!!