English 中文(简体)
PHP和MySQL:将各行各起来,并表达看法,以确定行文来源
原标题:PHP and MySQL: Arranging rows from separate tables together and expression to determine row origin

我需要从两个单独的表格中接手,并安排在日期之前按排位顺序排列。 各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各行各有关系。

这些表格都包含一个网站的最新信息,一个表格载有文字、链接、日期、标题等。 另一部有图像的题目、链接、规格等。 我想在该网站主要网页的更新部分安排一些基本信息(标题、日期、小描述),并按日期安排。

将这些表格合并成一个表格,并对其进行修改,以适应我在此所希望的两种类型:博客表格是:WordPress 标准 wp_posts,而且我不感到安慰地增加一栏,使之适合图像表。 恐怕它会与后来的升级相冲突,它似乎像是一种奇妙的解决办法(但如果这里的人告诉我,那就意味着我反对)。

The DESCRIBES of each table:

mysql> describe images;
+---------+--------------+------+-----+-------------------+----------------+
| Field   | Type         | Null | Key | Default           | Extra          |
+---------+--------------+------+-----+-------------------+----------------+
| id      | int(11)      | NO   | PRI | NULL              | auto_increment |
| project | varchar(255) | NO   |     | NULL              |                |
| title   | varchar(255) | NO   |     | NULL              |                |
| time    | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
| img_url | varchar(255) | NO   |     | NULL              |                |
| alt_txt | varchar(255) | YES  |     | NULL              |                |
| text    | text         | YES  |     | NULL              |                |
| text_id | int(11)      | YES  |     | NULL              |                |
+---------+--------------+------+-----+-------------------+----------------+

mysql> DESCRIBE wp_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field                 | Type                | Null | Key | Default             | Extra          |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID                    | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
| post_author           | bigint(20) unsigned | NO   |     | 0                   |                |
| post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content          | longtext            | NO   |     | NULL                |                |
| post_title            | text                | NO   |     | NULL                |                |
| post_excerpt          | text                | NO   |     | NULL                |                |
| post_status           | varchar(20)         | NO   |     | publish             |                |
| comment_status        | varchar(20)         | NO   |     | open                |                |
| ping_status           | varchar(20)         | NO   |     | open                |                |
| post_password         | varchar(20)         | NO   |     |                     |                |
| post_name             | varchar(200)        | NO   | MUL |                     |                |
| to_ping               | text                | NO   |     | NULL                |                |
| pinged                | text                | NO   |     | NULL                |                |
| post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content_filtered | text                | NO   |     | NULL                |                |
| post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| guid                  | varchar(255)        | NO   |     |                     |                |
| menu_order            | int(11)             | NO   |     | 0                   |                |
| post_type             | varchar(20)         | NO   | MUL | post                |                |
| post_mime_type        | varchar(100)        | NO   |     |                     |                |
| comment_count         | bigint(20)          | NO   |     | 0                   |                |
+-----------------------+---------------------+------+-----+---------------------+----------------+

我可以轻而易举地这样做(我在此包括使用超脱射方法的Im,而不知道):

$content = mysql_query("SELECT post_title, post_text, post_date FROM posts ORDER BY post_date DESC");
while($row = mysql_fetch_array($content))
{
    echo $row[ post_date ], $row[ post_title ], $row[ post_text ];
}

但是,如何将两个表格放在同一个阵列中,以正确安排它们?

我正确地说,他们将根据日期来总结他们重复的成果。 Maybe 我从错误的角度来看待这一点,把他们放在一个阵列上是答案吗?

此外,我还需要一种办法,以他们提出的表格为基础,形成一种有条件的表述,以便表1的行文与表2的行文不同地重复使用?

我想对表1的结果作不同的回应(我指的是,在表2中,有不同的描述)。 反之亦然。

我知道一份<代码>如果......else的声明将在此发挥作用,但我不知道我如何写明如何确定哪一个排位的表述。

最佳回答

基于购买力平价的分类办法并不总是最佳的想法,因为你可能想放弃你们的成果,此时你会遇到困难。

上文描述的基于“远景”的询问会更好,但你需要加以压缩,以便各表有不同的图表:

(
  Select  Image  as data_type, id, title, time as date_posted, ....
  From images
)
UNION
(
  Select  Post , ID as id, post_title as title, post_date as date_posted, ...
  From wd_posts
)
Order By date_posted Desc Limit $foo, $bar

关键是,你应从两个表格中删除相同的栏目。 该栏名不必照样工作,但我是这样。

我还认为,你应将图像索引。 时间和员额。 员额——日期。

在时间(时间)和时间(时间)领域(时间)进行混合定时,我将在我的SQL5上工作,我刚刚尝试过。

问题回答

或许联合国论坛是有益的

SELECT * FROM (
    SELECT post_title, post_text, post_date,  posts1  AS is_from FROM posts1
    UNION
    SELECT post_title, post_text, post_date,  posts2  AS is_from FROM posts2 
) AS posts1_posts2 ORDER BY post_date DESC

使用:

while($row = mysql_fetch_array($content)) 
{ 
    $key = $row[ post_date ]. - .$row[ id ];
    $array[$key] = array("table"=>1, "row"=$row);
} 

英文/法文





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签