SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello again,

    i just got onto this PHPLib stuff and manage to get a simple template to work fine. I have a script or should i say file that prints data out from the database. I would like to include the results (the data) in a particular area on the template i made. How do i go about doing it? I read an article and belive the Blocks will enable me to do this. (Someone please correct me if i'm wrong)


    Here's My Template File

    <html>
    <head>
    <title>{title}</title>
    </head>

    <body>
    <center>
    {NAME}
    </CENTER><p>
    <!-- BEGIN AccessBlock -->
    <center>
    <table width="500">
    {DATA}
    </table>
    </center>
    <!-- END AccessBlock -->
    <center>
    {COPYRIGHT}
    </CENTER>
    </body>
    </html>


    The area i want my php script to show in the template is {DATA}. I did try messing around and was able to get the script to show the data on the template but it wasn't shown in the {DATA} part but at the top of the page. Can someone please help? Thanks
    Last edited by XploreR; May 13, 2001 at 06:56.

  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)
    It should be rather straightforward, but it will be hard to diagagnose the problem withou seeing the code you are trying to use.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's my code to call the template file. I merely copy the part to get the data from the table and paste it in as i have no means of writing good code still and have no idea how to use db_mysql.php of PHPLib.



    <?
    include("/home/xiccc/www/templates/template.inc");
    $t = new Template("/home/xiccc/www/templates/", "keep");

    $t->set_file('page', 'page.phtml');
    $t->set_block('page', 'AccessBlock', 'ABlock');
    $t->set_var('title', 'XPLODER');
    $t->set_var('NAME', 'JOWY'');
    $t->set_var('COPYRIGHT', 'All Contents Copyright XICCC');

    $hostname = "localhost";
    $usernamedb = "xiccc";
    $passworddb = "******";
    $dbName = "games";

    $connection = mysql_connect($hostname, $usernamedb, $passworddb)
    or die("Couldn't make connection.");

    $db = mysql_select_db("games", $connection)
    or die("Couldn't select database");

    $tables = array("action", "adventure");

    foreach ($tables AS $table) {

    $sql = "SELECT game, url FROM $table
    WHERE gamesystem='Playstation' and alpha='D'";

    $result = mysql_query($sql);

    while ($row = mysql_fetch_array($result)) {
    // for convenience I use the function extract() to place
    // each element (result set field) contained in $row
    // into its own variable; ie, $game, $url
    extract($row);

    // Now insert into the array $games the key/value pair
    // $game/$url
    $games["$game"] = $url;
    }

    }

    // now sort the array by its keys
    ksort($games);

    for ($i=0; $i<sizeof($games); $i++) {

    while (list ($key, $val) = each ($games)) {
    echo "<tr><td><a href='$val'>$key</a></td></tr>";
    }

    $t->set_var('DATA', $games[$i]);
    $t->parse('ABlock', 'AccessBlock', true);
    }

    $t->pparse('Output', 'page');
    ?>


    Hoping to have some help here
    Last edited by XploreR; May 13, 2001 at 23:30.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your problem is in this area.

    for ($i=0; $i<sizeof($games); $i++) {

    while (list ($key, $val) = each ($games)) {
    echo "<tr><td><a href='$val'>$key</a></td></tr>";
    }

    $t->set_var('DATA', $games[$i]);
    $t->parse('ABlock', 'AccessBlock', true);
    }

    $t->pparse('Output', 'page');

    You have an extra loop in there and you are echoing the results out instead of assigning them to a var. I assume what you are after is this.

    while (list ($key, $val) = each ($games)) {
    $tmp = "<tr><td><a href='$val'>$key</a></td></tr>";
    $t->set_var('DATA', $tmp);
    $t->parse('ABlock', 'AccessBlock', true);
    }

    $t->pparse('Output', 'page');
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    THANKS

    Thank you, freddydoesphp, it works . Now for some extras, if i were to include db_mysql.php from PHPLib, how would i go about writing it? I do need to use the $db->next_record() statement?

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you will need that function.

    $db->next_record() would return essentially two array elements for each field in the resultset, so you can use extract here, we can work on that later though. Here is how I would change your script to work with phplib and db_mysql.

    <?
    include("db_mysql.inc");
    $db = new DB;
    include("/home/xiccc/www/templates/template.inc");
    $t = new Template("/home/xiccc/www/templates/", "keep");

    $t->set_file('page', 'page.phtml');
    $t->set_block('page', 'AccessBlock', 'ABlock');
    $t->set_var('title', 'XPLODER');
    $t->set_var('NAME', 'JOWY'');
    $t->set_var('COPYRIGHT', 'All Contents Copyright XICCC');


    $tables = array("action", "adventure");

    foreach ($tables AS $table) {

    $sql = "SELECT game, url FROM $table
    WHERE gamesystem='Playstation' and alpha='D'";

    $db->query($sql);

    while ($db->next_record()) {

    // Now insert into the array $games the key/value pair
    // $game/$url
    $games[$db->f(game)] = $db->f(url);
    }

    }

    // now sort the array by its keys
    ksort($games);


    while (list ($key, $val) = each ($games)) {
    $tmp = "<tr><td><a href='$val'>$key</a></td></tr>";
    $t->set_var('DATA', $tmp);
    $t->parse('ABlock', 'AccessBlock', true);
    }


    $t->pparse('Output', 'page');
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddydoesphp, yea, got it to work. sweet. Thank you very much
    Last edited by XploreR; May 15, 2001 at 03:59.

  8. #8
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry...

    I just want to ask what is the major defferent between FastTemplate and PHPLib.

    I'm using FastTempalate now.. but I've heard a lot about PHPLib...

    Can someone give me some comments?
    Ngu I.P.
    Web Developer

  9. #9
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No probs,

    Well, i used it because PHPlib templates works better than FastTemplate with PHP and it's more faster. Is that a major difference? I don't know
    Last edited by XploreR; May 15, 2001 at 04:00.

  10. #10
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The main difference is that FastTemplate was a Perl template system ported over to PHP, while phpLib template was written from scratch with PHP in mind. As a result PHPlib templates are more efficient than FastTemplate.


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
  •