Welcome Guest, Not a member yet? Register   Sign In
My first question
#1

[eluser]Aimadj[/eluser]
hi all I'm new here and it's my first question .

i have 2 tables in data base one for videos and second for category .

In page I'm need to write the category where video .

My Table
Code:
1-Videos
---id
---title
---de
---photo
---catid

2-cats
---id
---catname

I'm create this query :
Code:
select catname from cats left outer join videos on cats.id = videos.catid where title='Here Video title''

but m problem where I'm insert this query for work with Co
-I'm use page in controllers videos.php with this code :
Code:
<?php

class Videos extends Controller

{
function videos() {

parent::Controller();
$this->load->database();
$this->load->helper('url');


}
function index()  {
$data['query']=$this->db->get('vi);
$data[']='Vi Pages Selection';
$data['cat_title']='tst cat name';
$this->load->view(' , $data);

}


function details($id)
{

$data['query']=$this->db->where('id',$id);
$data['query']=$this->db->get('vi);
$this->load->view(', $data);

}

}


?>

and second page in views views_vi.php with this code :
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $page_title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>Videos List :</h1>


<table border="1">
  <tr>
    <td>Photo</td>
    <td>Titre</td>
    <td>deeption de livre</td>
    <td>Categorie</td>
    <td>date d'ajoute</td>
  </tr>
  &lt;?php foreach ($query->result() as $row){ ?&gt;
  <tr>
    <td><img >photo?&gt;" alt="&lt;?=$row->title?&gt;" /></td>
    
    <td>&lt;?=anchor('videos/details/'.$row->id, ''.$row->title);?&gt;</td>
    
    <td>&lt;?=$row->de?&gt;</td>
    
    <td>i'm need insert the categor name here</td>
    <td>&nbsp;</td>
  </tr>
  &lt;?php } ?&gt;
</table>
<p><br />Page rendered in {elapsed_time} seconds</p>
&lt;/body&gt;
&lt;/html&gt;


tks very match for help me with this problem Smile
#2

[eluser]Rey Philip Regis[/eluser]
I dont understand the question? Can you elaborate more?
#3

[eluser]Aimadj[/eluser]
[quote author="Rey Philip Regis" date="1233116715"]I dont understand the question? Can you elaborate more?[/quote]

ok sorry because i'm new with this framwork . view this :

i'am create this file videos.php in controllers floder with this code :
Code:
&lt;?php

class Videos extends Controller

{
function videos() {

parent::Controller();
$this->load->database();
$this->load->helper('url');


}
function index()  {
$data['query']=$this->db->get('videos');
$data['page_title']='Videos Pages Selection';
$data['cat_title']='tst cat name';
$this->load->view('views_videos' , $data);

}


function details($id)
{

$data['query']=$this->db->where('id',$id);
$data['query']=$this->db->get('videos');
$this->load->view('detailview', $data);

}

}


?&gt;

and i'm create this file views_videos.php in views floder :
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $page_title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>Videos List :</h1>


<table border="1">
  <tr>
    <td>Photo</td>
    <td>Title</td>
    <td>desception video</td>
    <td>Category</td>
    <td>add time</td>
  </tr>
  &lt;?php foreach ($query->result() as $row){ ?&gt;
  <tr>
    <td><img >photo?&gt;" alt="&lt;?=$row->title?&gt;" /></td>
    
    <td>&lt;?=anchor('videos/details/'.$row->id, ''.$row->title);?&gt;</td>
    
    <td>&lt;?=$row->desc?&gt;</td>
    
    <td> HERE I NEED INSERT THE CATEGORY NAME </td>
    <td>&nbsp;</td>
  </tr>
  &lt;?php } ?&gt;
</table>
<p><br />Page rendered in {elapsed_time} seconds</p>
&lt;/body&gt;
&lt;/html&gt;

and in database i have this 2 table :

Code:
1-Videos
---id
---title
---de
---photo
---catid

2-cats
---id
---catname

will now i'am need to insert in this <td> HERE I NEED INSERT THE CATEGORY NAME </td> the category where video locate . and i'am insert in videos table catid field it's field is the id of this video category .

if you don't understand i'am send you example in page to view tks for your replay

and i'am sorry for my bad english :red:
#4

[eluser]umefarooq[/eluser]
hi you want to find videos from you database record for a specific category. if you want to do some thing like this let me know an other thing don't put your code in next post just put your problem in proper way.
#5

[eluser]Aimadj[/eluser]
[quote author="umefarooq" date="1233156059"]hi you want to find videos from you database record for a specific category. if you want to do some thing like this let me know an other thing don't put your code in next post just put your problem in proper way.[/quote]

ok tks for your replay .

i have this fonction :

Code:
function index()  {
$data['query']=$this->db->get('videos');
$data['page_title']='Videos Pages Selection';
$data['cat_title']='tst cat name';
$this->load->view('views_videos' , $data);

and i'am create this code in view page:

Code:
&lt;?php foreach ($query->result() as $row){ ?&gt;
  <tr>
    <td><img >photo?&gt;" alt="&lt;?=$row->title?&gt;" /></td>
    
    <td>&lt;?=anchor('videos/details/'.$row->id, ''.$row->title);?&gt;</td>
    
    <td>&lt;?=$row->desc?&gt;</td>
    
    <td>IN THIS FIELD I'AM NEED TO POST THE CATEGORIE NAME </td>
    <td>&nbsp;</td>
  </tr>
  &lt;?php } ?&gt;

i'am need to insert the category name with related video .

tks other time and sorry for my bad English :red:
#6

[eluser]umefarooq[/eluser]
if you want insert it in the database create a from in you view and make all fields hidden and than get all info from that form fields and put in the database.
#7

[eluser]obiron2[/eluser]
Hi,
and welcome to the boards.


firstly, it is not good practice to put your database calls in the controller. You should create a model for doing the database stuff, load the model and call functions in the model from the controller.

in the model:
Code:
function details($id)
{

$this->db->where('id',$id);
return $this->db->get('videos')->result;
}

in the controller:

Code:
function details($id)
{

$this->load->models('Video_model');
$data['videos'] = $this->video_model->details($this->url_segment(3));
$this->view->('Views_video', $data);
}

in your view:
Code:
foreach ($videos as $video)
print "<TR><TD>$video->title</TD><TD>$video->description</TD><TD>
<imgg src=\"$videox->photo.".jpg/></TD></TR>";


The controller should decide what it needs, the Model decides how to get it from the database and the view decides how it should be shown (along with CSS)

Good luck and post back if you have any more issues.

Obiron
#8

[eluser]Aimadj[/eluser]
tks obiron2 for your answer but . you don't understand my problem, i'am need to associeted video with categories of this video

example :

in video page visitor view : this video in category action

tks for help me




Theme © iAndrew 2016 - Forum software by © MyBB