使锚加载页面包含数据库中引用行的数据

发布于 2024-09-04 06:57:07 字数 749 浏览 10 评论 0原文

我正在尝试总体学习代码点火器库和面向对象的 PHP,并且有一个问题。

我已经制作了一个从数据库加载所有行的页面,在其中,我回显了一个锚标记,该标记是指向以下结构的链接。

echo anchor("videos/video/$row->video_id", $row->video_title);

所以,我有一个名为 Videos 的类,它扩展了控制器,在该类中有索引和视频,它们被正确调用(当您单击视频标题时,它会将您发送到视频/视频/5,例如,5 是我正在使用的表的主键。

所以基本上我要做的就是将 5 传递回控制器,然后让特定的视频页面从视频表中输出特定的行数据。我的视频控制器看起来像这样:

function video()
{
    $data['main_content'] = 'video';
    $data['video_title'] = 'test';
    $this->load->view('includes/template', $data);      
}

所以,基本上 test 应该是 test 而不是 test,它是一个查询的返回值,它表示获取表“videos”,即带有 video_id 的行>“5”,并使$data['video_title']等于数据库中video_title的值...

现在应该已经弄清楚了,但是不要,任何帮助将不胜感激!

I'm trying to learn the code igniter library and object oriented PHP in general and have a question.

I've gotten as far as making a page which loads all of the rows from my database and in there, I'm echoing an anchor tag which is a link to the following structure.

echo anchor("videos/video/$row->video_id", $row->video_title);

So, I have a class called Videos which extends the controller, within that class there is index and video, which is being called correctly (when you click on the video title, it sends you to videos/video/5 for example, 5 being the primary key of the table I'm working with.

So basically all I'm trying to do is pass that 5 back to the controller, and then have the particular video page output the particular rows data from the videos table. My function in my controller for video looks like this:

function video()
{
    $data['main_content'] = 'video';
    $data['video_title'] = 'test';
    $this->load->view('includes/template', $data);      
}

So ya, basically test should be instead of test, a returned value of a query which says get in the table "videos", the row with the video_id of "5", and make $data['video_title'] equal to value of video_title in database...

Should have this figured out by now but don't, any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云柯 2024-09-11 06:57:07

我不知道我是否太晚了,但这也许可以解决你的问题......
将其放入您的 video() 函数中

data[$query] = $this->db->query("SELECT * FROM videos WHERE video_id = 5");

,然后放入您的 video_view 文件中...

if ($query->num_rows() > 0)
{
   $row = $query->row_array(); 

   echo $row['title'];
   echo $row['something'];
   echo $row['somethingElse'];
}

这是一个很好的资源: http://codeigniter.com/user_guide/database/index.html

希望有帮助...

请有人编辑这个问题,因为它太难读了......

I don't know if I'm too late but maybe this can solve your problem...
put this in your video() function

data[$query] = $this->db->query("SELECT * FROM videos WHERE video_id = 5");

and then that in your video_view file...

if ($query->num_rows() > 0)
{
   $row = $query->row_array(); 

   echo $row['title'];
   echo $row['something'];
   echo $row['somethingElse'];
}

this is a good resource: http://codeigniter.com/user_guide/database/index.html

hope that helps...

and please someone edit the question because it's too hard to read...

凉城凉梦凉人心 2024-09-11 06:57:07

您需要的是了解 URI 类 的工作原理

基本上:

$default_url_args = array('video');
$url_args = $this->uri->uri_to_assoc(3,$default_url_args);
$video_UID = $url_args['video'];

然后是类似的内容

$the_video = $this->videos_model->get_video_by_UID($video_UID);

What you need is to understand how the URI Class works

Basically:

$default_url_args = array('video');
$url_args = $this->uri->uri_to_assoc(3,$default_url_args);
$video_UID = $url_args['video'];

and then something like

$the_video = $this->videos_model->get_video_by_UID($video_UID);
丢了幸福的猪 2024-09-11 06:57:07

您可以使用 URI 类,也可以执行以下操作:

function video($video_id)
{
  $data['main_content'] = $this->videoprovider->get_video( $video_id );
  $data['video_title'] = 'test';
  $this->load->view('includes/template', $data);
} 

换句话说,使用扩展 Controller 的类内的函数,您可以向这些函数添加参数,CI 将自动传入 URI 项以传递给这些参数。

function generic_function_in_controller($item1, $item2, ...)
{
  // would receive as: http://example.com/controller/generic_function_in_controller/item1/item2
}

You could use the URI Class, or you can do the following:

function video($video_id)
{
  $data['main_content'] = $this->videoprovider->get_video( $video_id );
  $data['video_title'] = 'test';
  $this->load->view('includes/template', $data);
} 

In other words, with functions inside classes that extend Controller, you can add parameters to those functions and CI will automatically pass in the URI items in order to those parameters.

function generic_function_in_controller($item1, $item2, ...)
{
  // would receive as: http://example.com/controller/generic_function_in_controller/item1/item2
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文