SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: eval

  1. #1
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    eval

    Hi,

    I hope someone can help.

    I am using the following code to select the ID of a moderator from the table qb_mods and then get their username from qb_members. This works fine and prints all the moderators correctly, even if there is more than one.

    PHP Code:
      $msql mysql_query("SELECT m.MemID, mem.UserName FROM qb_mods m, qb_members mem WHERE Forum = '$forums[FID]' AND m.MemID = mem.MID") or die(mysql_error());

        
    $num_rows mysql_num_rows($msql);
            if (
    $num_rows == 0)
            {
                echo 
    " ";
            } else {

      while ( 
    $mods mysql_fetch_array($msql) ) {
      echo 
    "<a href=\"profile.php?user=$mods[UserName]\">$mods[UserName]</a> \n";
      }
      echo 
    "        </font></td>\n";
      echo 
    "      </tr>\n";


    Now the problem, I want to use a template system using eval. How can I change this code so that I can replace a variable ($moderators) in the template with all of the moderators, even if there is more than one ?

    Sean

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use

    PHP Code:
      while ( $mods mysql_fetch_array($msql) ) {
     
    $tmp .= "<a href=\"profile.php?user=$mods[UserName]\">$mods[UserName]</a> \n";
      }
    str_replace($moderators$tmp$templatestring); 

    Is that what you are after?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, thanks for the quick reply.

    Ok, I tried that but I get the following error : Warning: The length of the needle must not be 0 in c:\apache\htdocs\qboard\in2.php on line 56

    This might have something to do with how I am using your code. Right, what I did was open the template like this :

    PHP Code:
    $m template("$tpath/forumsbar.htm"); 
    This implodes the file. I then used your code and replaced the $moderators variable like this :

    PHP Code:
    str_replace($moderators$tmp$m); 
    Then I used eval to replace the rest of the template variables :

    PHP Code:
    eval("echo stripslashes(\"$m\");"); 
    Any thoughts ?

    Sean


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
  •