I have data
Name, Year, Month, Amount
==
A, 2012, nov, 14
A, 2012, dec, 48
A, 2012, jan, 8
B, 2011, feb, 17
B, 2011, aug, 10
(...)
How is it possible to group the names, so the output will be
Name, Feb2011, Aug2011, Jan2012, Nov2012, Dec2012
==
A, 0, 0, 8, 14, 48
B, 17, 10, 0, 0, 0
I have really no idea what function to look for.
I am trying to build a simple business intelligence tool. I have a lot of mysql tables with data I want to retrieve in a user friendly way.
I want the user to select elements and when the elements is selected, the system will join the right tables. How is this possible? I need a hint to be guided in the right direction. I can simply not come up with an idea to a database structure in which I can collect the right table relations. Does anyone have any ideas?
Thank you.
Thanks for the answers.
Now I use the code below. It works just fine - do you have any suggestions for improvements?
Now my problem is to make a design around each template file. How is that possible with the code I use?
thread.html
====
<div>
<h1><?php echo $title; ?></h1>
<p><?php echo $text; ?></p>
</div>
<div>
<ul>
<li><a href="/forum/comment/<?php echo $thread_id; ?>">Comment</a></li>
</ul>
</div>
<div>
<h1>Comments</h1>
<?php
foreach($posts as $data) {
?>
<div>
<h2><?php echo $data['name']; ?></h2>
<p><?php echo $data['text']; ?></p>
</div>
<?php
}
?>
</div>
view.php
====
<?php
final class View {
public function render($filename, $variables = array()) {
extract($variables);
require $filename;
}
}
?>
forum_controller.php
====
class Forum {
public function thread($id = null) {
if(is_numeric($id)) {
$sql = sprintf("SELECT title, text FROM forum_threads WHERE id = %d LIMIT 1", $id);
$result = MySQL::query($sql);
if(mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$sql = sprintf("SELECT text FROM thread_comments WHERE thread_id = %d", $id);
$result = MySQL::query($sql);
$posts = array();
while($foo = mysql_fetch_assoc($result)) {
$posts[] = $foo;
}
$variables = array(
'title' => $row['title'],
'text' => $row['text'],
'posts' => $posts
);
View::render("thread.php", $variables);
}
} else {
View::render("error.php");
}
}
}
I don't care whether it is php or HTML files. What would the code look like? I was thinking of a php file that included forum.html and forum_post.html many times
I have the two files below and want to separate php and html. How do I output forum.html with forum_post.html in it? I want to post as many forum_post.html as mysql_num_rows() says.
forum.html
======
<div>
<form method="post">
<textarea name="text"></textarea>
<input type="submit" />
</form>
</div>
<div>
[b]???[/b]
</div>
forum_post.html
======
<div>
<h1>Title</h1>
<p>Text</p>
</div>
I've made a template system, but the way I've chosed to do it doesn't give me the ability to choose a design. I've posted the code below with a bad solution for my design problem. Does anyone have any suggestions how to make a very simple and smart templatesystem? I don't have any problems coding. I just need ideas :-)
<?php
final class View implements IView {
protected $filename, $variables = array();
public function __construct($filename = null, $variables = array()) {
$this->filename = $filename;
$this->variables = $variables;
}
public function __toString() {
if(!file_exists($this->filename)) {
throw new Exception("View does not exists.");
}
$content = file_get_contents($this->filename);
foreach($this->variables as $variable => $value) {
$content = str_replace("#{{$variable}}", $value, $content);
}
return str_replace("#{content}", $content, file_get_contents("design.html"));
}
}
?>
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.