Skip to main content
Topic: I want to show like this... (Read 1736 times) previous topic - next topic

I want to show like this...

How to ?
I want show multiple table fields in a single page (such a content management system)

For example:
In the info/help - page, i want to fetch few fields from two tables.

Like this: <?php echo $table_one[field_name]; ?> and <?php echo $table_two[field_name]; ?> or more

How to do that?


Re: I want to show like this...

Reply #2
I did this in info/help page:
Code: [Select]
<div class="container">
<h4>Help And Frequently Asked Questions</h4>
<hr />
<div>
Put page content here
</div>
<?php
$cmtc = new ContentController;
$db = $cmtc->GetModel();
$sql = "SELECT * FROM content WHERE id = 1";
$allcontent = $db->rawQuery($sql);

?>
<h2><?php echo $allcontent['page_title']; ?> <br>
<?php echo $allcontent['page_note']; ?></h2>


</div>

but still not working...

I don't need loops I just only need fields data.

Re: I want to show like this...

Reply #3
Please use rawQueryOne as it returns object while rawQuery returns array.

Also i will advice against putting sql statements in the view page as it goes against mvc pattern. You can create a new function in ContentController that returns the db result then call the function in the view page.

Re: I want to show like this...

Reply #4
Thanks a lot.

now created a function in ContentController
Code: [Select]
function cont(){
$db = $this->GetModel();
$sql = "SELECT * FROM content WHERE id = 1";
$allcontent = $db->rawQueryOne($sql);
return $allcontent;
}

and in view page I've call:
Code: [Select]
 <?php cont(); ?>
<?php echo $allcontent['page_title']; ?>
 
but now not working...

have some example...?

Thnx.


 

Re: I want to show like this...

Reply #6
it works.
Thnx a lot.

One more thing: If I put the query in SharedController and call with this
Code: [Select]
<?php 
$comp_model = new SharedController;
$allcontent = $comp_model->cont();
?>
hence will it be secured the front-end?