SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, heres the problem

    here is some code i have to get a bunch of html code from a mysql database
    Code:
    function template ($name) {
    $query = mysql_query("SELECT code FROM templates WHERE tempname='$name'") or die(mysql_error());
    $template = mysql_fetch_array($query);
    return $template;
    }
    which is called like this
    Code:
    $html = template("header");
    and to print the data to the screen i use
    Code:
    eval("echo stripslashes(\"$html\");");
    now look what the produces http://www.jellyman.net/dd/ it just prints array where its meant to put in all the html.

    whats wrong with my php/mysql coding? got any ideas?

    thanks

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $template = mysql_fetch_array($query);

    returns an array, so after calling the function, you get an array, not a string, when you print it, PHP will print "Array"

    use this:

    $template = mysql_fetch_array($query);
    $template = $template['code']; // I believe you want to get the field "code"
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks!

    i'm a php newbie

    thanks again

  4. #4
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, more problems but with a different thing.
    here we go again
    Code:
    $querytop = mysql_query("SELECT * FROM threads WHERE fid=$fid ORDER BY lastpost DESC LIMIT $start_limit, $topicperpage") or die(mysql_error());
    
    while($thread = mysql_fetch_array($querytop)) {
    
    $lastreplydate = date("n/j/y",$thread[lastpost] + ($timeoffset * 3600));
    $lastreplytime = date("h:i A",$thread[lastpost] + ($timeoffset * 3600));
    
    $lastpost = "$lastreplydate at $lastreplytime";
    
    if($thread[icon] != "") {
    $thread[icon] = "<img src=\"images/icons/$thread[icon]\" alt=\"Icon depicting mood of thread\">";
    }
    else {
    $thread[icon] = "&nbsp;";
    }
    
    $querypost = mysql_query("SELECT COUNT(*) FROM posts WHERE tid='$thread[tid]'") or die(mysql_error());   //## Grabbing forum count in this forum
    $replynum = mysql_result($querypost, 0);
    
    if($replynum >= $hottopic) {
    $folder = "<img src=\"images/hot_folder.gif\">";
    } else {
    $folder = "<img src=\"images/folder.gif\">";
    }
    
    eval("\$threads .= \"".template('threadlist')."\";");
    
    }
    pulls the topics from the forum $fid
    now to print it i use
    Code:
    eval("\$forumdisplay = \"".template('forumdisplay')."\";");
    echo $forumdisplay;
    the template forumdisplay contains the variable $threads which in my book should print the list of threads. BUT it doesn't. all i get is http://jellyman.net/dd/forumdisplay.php?fid=1 which uses the template forumdisplay but doesn't print out the list of threads.

    do you understand that?
    any ideas?

    thanks again

  5. #5
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

    i need this urgently.

    thanks

  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand since your provided code doesn't cover what is threadlist

    Also, eval("\$threads .= "".template('threadlist')."";");
    while $threads was already an array (mysql_fetch_array)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  7. #7
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no ones $thread and the other is $threads,

    the template threadlist is just html. it contains
    Code:
    <tr class=\"tablerow\">
    <td bgcolor=\"\$altbg1\">\$folder</td>
    <td bgcolor=\"\$altbg2\">\$thread[icon]</td>
    <td bgcolor=\"\$altbg1\"><a href=\"viewthread.php?fid=$fid&tid=\$thread[tid]\">\$thread[subject]</a></td>
    <td bgcolor=\"\$altbg2\"><a href=\"member.php?action=viewpro&member=\$thread[author]\">\$thread[author]</a></td>
    <td bgcolor=\"\$altbg1\">\$replynum</td>
    <td bgcolor=\"\$altbg2\">\$thread[views]</td>
    <td bgcolor=\"\$altbg1\">\$lastpost</td>
    </tr>

  8. #8
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, my bad, the "s" went unnoticed. However, it's still very confusing to me where the problem is since I don't know what is "template", a functions? if so, what is the code?
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  9. #9
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function template ($name) {
    $query = mysql_query("SELECT code FROM templates WHERE tempname='$name'") or die(mysql_error());
    $template = mysql_fetch_array($query);
    $template = $template['code'];
    return $template;
    }
    is what the function template contains

  10. #10
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would also like to see what is the contain of forumdisplay in

    eval("\$forumdisplay = "".template('forumdisplay')."";");
    echo $forumdisplay;

    Since I believe that is where the eval replace the thread list by real value.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  11. #11
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i fixed it, i forgot to include $threads in the forumdisplay template, stupid me!

  12. #12
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was getting close to the root
    The reason it took quite long because there are small pieces of code everywhere, have to linked them together. Glad you solved.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •