Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    One Result while looping

    Hello

    In this code , it Should Print out all the titles where cid=$cid..

    But for Some reason it only Prints One Result ( One title) . when i'm sure i have More than One Title in my Mysql ..

    The Funy thing is it all ok if i do Not use Smarty ..

    this the php

    PHP Code:
    <?php
      $cid 
    $_GET['cid'];
    $data mysql_query("SELECT * FROM ".$DB->prefix("gallery")." WHERE category='$cid' ") or die(mysql_error());

     while(
    $info mysql_fetch_array$data ))
    {
        
    $mytest= array();
          
      
    $mytest['title'] = $myts->htmlSpecialChars($info['title']);
      
    $mytest['name'] = $myts->htmlSpecialChars($info['name']);

            
    $smarty->assign('title'$mytest['title']);
           
    $smarty->assign('name'$mytest['name']);
     }
    ?>
    tmplate

    PHP Code:
     <table cellpadding="5" cellspacing="5" class="outer"
        <
    tr>
    <
    td class="even">
    <{
    $name}></td>
    </
    tr>


        <
    tr>
    <
    td class="even">
    <{
    $title}></td>
    </
    tr>

    </
    table
    Last edited by ajloun; 02-16-2010 at 07:30 PM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,135
    Thanks
    12
    Thanked 332 Times in 328 Posts
    judging from the template (ok, never have used smarty), you can’t have more than one output, plus, in the smarty assignment, it looks like you overwrite the previous value in every cycle.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Dormilich is correct.

    1. Your php file will have to create an array containing your titles and names (and any other info you want to display) and then assign that array to a smarty variable.

    2. In your template file, you need to use a {foreach} loop to display the data in the array.
    John

  • Users who have thanked PappaJohn for this post:

    ajloun (02-16-2010)

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    @PappaJohn thx

    i edited my php to use arry .But i'm new with Smarty .. How to loop?

  • #5
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    John

  • Users who have thanked PappaJohn for this post:

    ajloun (02-16-2010)

  • #6
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    @PappaJohn

    Thank you Man .. Got it Right this Time A+

  • #7
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    you're welcome, glad you got it.
    John


  •  

    Posting Permissions

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