Jump to content

Listing results in a template system


Infected-Waffle

Recommended Posts

Okay so I have this templating system and I want to retrieve all my new results but they allhave togo into one variable. I've brainstormed for a while but I can't think of anything. Here's the code:

[code]<?php

session_start();

if (isset($_SESSION['logged_in']) {
$nav = '&raquo; User CP';
} else {
$nav = '<form action="index.php?page=submit&mode=login" method="post" name="login">
Username:<br>
<input name="username" type="text" size="17" maxlength="15"><br>
Password:<br>
<input name="password" type="password" size="17" maxlength="16"><br>
<input name="Login"  value="Login" type="button">
</form>';
}

include("dbconnect.php");
include("templates/templatesys.php");

switch($_GET['page']) {
case 'templates' :
break;
default:
$query = 'SELECT * FROM news ORDER BY id DESC';
$result = mysql_query($query);

if ($result) {
while( $row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
}
}
$data = array('CONTENT' =>);

$tpl = new template;
$tpl->parseTemplate('templates/main.tpl', $data);
$tpl->display();

    break;
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/17449-listing-results-in-a-template-system/
Share on other sites

Sorry.

Alright basically when I didn't use this templating system I would put an echo in the while. But now I started using this template system and What I need to basically do is put all the entries the query returns into one variable which will then be placed in the $data array and parsed.

Hope that's  specific enough. ^^;
How do you want to join each record? You could simply concatinate them...

[code=php:0]
if ($result) {
  while( $row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
    $content .= $row['content'];
  }
}
[/code]

But I cant see that being much use to you. You could also put them into an array...


[code=php:0]
if ($result) {
  while( $row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
    $content[] = $row['content'];
  }
}
[/code]

Hard to see what it is you need really.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.