简体   繁体   English

分页脚本-从两个表中获取数据

[英]Pagination script - getting data from two tables

I have a pagination script, which can be seen here: http://www.automotori6282.tk/phpsandbox/ 我有一个分页脚本,可以在这里查看: http : //www.automotori6282.tk/phpsandbox/

This is the source code: 这是源代码:

http://pastebin.com/raw.php?i=63dCvfxD (PmcPagination.php) http://pastebin.com/raw.php?i=63dCvfxD(PmcPagination.php

http://pastebin.com/raw.php?i=3k4nqwRB (demo.php, the page with the code in) http://pastebin.com/raw.php?i=3k4nqwRB(demo.php ,其中包含代码的页面)

and index.php for http://www.automotori6282.tk/phpsandbox/ simply uses PHP's include() function to show demo.php http://www.automotori6282.tk/phpsandbox/的 index.php只是使用PHP的include()函数显示demo.php

What I'm trying to do is extract from two tables for the pagination. 我想做的是从两个表中分页。

This is my current database structure: 这是我当前的数据库结构:


programme   varchar(255)    
channel     varchar(255)    
episode     varchar(255)
series  varchar(255)            
setreminder     varchar(255)    

However, I have the episodes stored in a separate table, and would like to make a query which extracts from both epdata167 and episodes table (the episodes table only has episode, seriesno, episodeno and description as its fields). 但是,我将情节存储在单独的表中,并且想进行查询,该查询从epdata167和情节表中提取(情节表仅具有情节,系列编号,情节编号和描述作为其字段)。

One error I made in my pagination script shows here: 我在分页脚本中犯的一个错误显示在这里:

TV Show showing on Channel 1 August 3rd - 12:30pm "" Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1" Set Reminder

and it still remains long after the event has happened. 事件发生后仍然很久。

This is how it should work: 这是应该如何工作的:

 TV Show showing on Channel 1 August 3rd - 12:30pm  
 TV Show showing on Channel 1 August 3rd - 2:45pm Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1" Set Reminder

Notice how the Set Reminder field doesn't show when the event happens, and there's no quotation marks if an episode isn't selected. 请注意,事件发生时“设置提醒”字段如何不显示,并且如果未选择剧集,则不会带引号。

(The setreminder field is basically a link that a user would click on to send a reminder to them saying "TV show is airing on Channel 1 August 3rd - 8:30pm Episode 1" or "TV show is airing today at 8:30pm Episode 1". However, it would not display for the show that is airing right now, it would display like this: (setreminder字段基本上是一个链接,用户可以单击该链接向用户发送提醒,说“电视节目在8月3日第1频道播出-第1集:8:30pm”或“电视节目今天在8:30 pm播出。 1“。但是,当前正在播放的节目不会显示,它将显示为:

    TV Show showing on Channel 1 August 3rd - 12:30pm 

)

This is the pagination code causing trouble: 这是导致麻烦的分页代码:

$result = mysql_query("SELECT programme, channel, airdate, expiration, episode, series, setreminder FROM epdata167 where airdate > curdate() GROUP by airdate"); $ result = mysql_query(“ SELECT程序,频道,广播,到期,情节,系列,setreminder from epdata167,其中airdate> curdate()GROUP by airdate”);

and here is the part of the pagination code I edited to try and use an ifelse statement but wasn't sure what to do: 这是我为尝试使用ifelse语句而编辑的分页代码的一部分,但不确定该怎么做:

class paginationData {
private $program;
private $channel;
private $airdate;
private $exiration;
private $episode;
private $series;
private $setReminder;

public function __construct($program, $channel, $airdate, $expiration, $episode, $setReminder)
{
    $this->program = $program;
    $this->channel = $channel;
  $this->airdate = strtotime($airdate);
    $this->expiration = $expiration;
    $this->episode = $episode;
    $this->setReminder = $setReminder;
}

//This function shows the data
public function display()
{
    if(date('Y-m-d') == date('Y-m-d', $this->airdate)) $dateFormat = 'g:ia';
    elseif(date('Y') == date('Y', $this->airdate)) $dateFormat = 'F jS - g:ia';
    else $dateFormat = 'F jS, Y - g:ia';

    echo '<tr>'."\n".
         '  <td><strong>'.$this->program.'</strong></td>'."\n".
         '  <td>showing on '.$this->channel.'</td>'."\n".
         '  <td>'.date($dateFormat, $this->airdate).'</td>'."\n".
         '  <td><b>"'.$this->episode.'"</b><br></td>'. "\n".
         '  <td>'.$this->setReminder.'</td>'."\n".
         '</tr>'."\n";
}

} }

Basically, I'm having trouble trying to get data as this in my project: 基本上,我在尝试在项目中尝试获取数据时遇到了麻烦:

     TV Show showing on Channel 1 August 3rd - 12:30pm  
 TV Show showing on Channel 1 August 3rd - 2:45pm Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1"
                                                  Series 1, episode 1 Set Reminder

(that's if the episode is part of a series with a series number) (如果情节是具有编号的系列的一部分)

Not sure what JOIN to use and where, all help is appreciated trying to get this to work since I've got the pagination working; 不确定使用什么JOIN以及在何处使用,因为我已使分页生效,因此为使此工作正常进行,我们将不胜感激; just trying to get the finer details working! 只是试图使更好的细节起作用!

I'm not asking for people to do it for me, I've been learning myself, and have done my research. 我不是在要求别人为我做,我一直在学习自己,并且已经完成了研究。

Sorry if this seems a bit long, but I hope I've explained it all. 抱歉,这似乎有点长,但是我希望我已经解释了所有这一切。

Thanks. 谢谢。

您需要使用UNION才能使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM