Jump to content


Photo

Listing results in a template system


  • Please log in to reply
4 replies to this topic

#1 Infected-Waffle

Infected-Waffle
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 August 2006 - 11:49 PM

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:

<?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;
}

?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 August 2006 - 11:54 PM

You'll need to be alot more specific. Were not mind readers.

#3 Infected-Waffle

Infected-Waffle
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 August 2006 - 11:57 PM

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. ^^;

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 August 2006 - 12:03 AM

How do you want to join each record? You could simply concatinate them...

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

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


if ($result) {
  while( $row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
    $content[] = $row['content'];
  }
}

Hard to see what it is you need really.

#5 Infected-Waffle

Infected-Waffle
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 August 2006 - 02:57 AM

Thanks I'll try those.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users