SitePoint Sponsor

User Tag List

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

    Arrow Where is this codes belong?

    Hello

    I saw this codes below,

    Code:
    <?php
      $search_condition = "where name like '$foo%' ";
      $sql = 'select contact_id, name, nick from contacts '.$search_condition.' order by name';
      $smarty->assign('results', $db->getAssoc($sql) );
    ?>
    I got it from one of sample in the manual,
    http://www.smarty.net/manual/en/lang...on.foreach.php

    And i'm curious this particular codes below
    Code:
    $db->getAssoc($sql)
    Now where is that codes belong?

    I reviewed the smaty class and i don't see the getAssoc() method?

    Anyone would give shed to this problem of mine?

    thanks in advance.

  2. #2
    SitePoint Enthusiast mithra62's Avatar
    Join Date
    Nov 2004
    Location
    Van Nuys
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solid,

    It's just mock code to highlight the need for an array. If you place an actual array there you can access it inside smarty templates.

    For example the code could have been written like so:

    PHP Code:
    <?php
    $search_condition 
    "where name like '$foo%' ";
    $sql 'select contact_id, name, nick from contacts '.$search_condition.' order by name';
    $result mysql_query($sql);
    if(
    $result){
         
    $smarty->assign('results'mysql_fetch_array($result));
    }
    ?>
    Hope that helps
    Last edited by mithra62; Aug 18, 2009 at 00:54. Reason: hope that helps

  3. #3
    SitePoint Zealot jimmy85's Avatar
    Join Date
    Aug 2009
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I remember it right it's not on either PHP or Smarty, but a DB addon/library for making DB queries simpler. Try ADOdb if that helps.

  4. #4
    Non-Member
    Join Date
    Jul 2009
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way this code is vulnerable to sql injection. Make sure you stripslash the
    $foo variable.


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
  •