English 中文(简体)
如何在我方位的基础上先选择第二个记录
原标题:How to select second record after first from mysql base
  • 时间:2011-10-24 18:40:21
  •  标签:
  • php
  • mysql
1. p1 | cat   | mause
2. p2 | mause | cat

Hello, I d like to select 2 records form database with condition. My query:

SELECT * FROM mytable 
WHERE (p1 LIKE cat OR p2 LIKE cat) AND (p1 LIKE mause OR p2 LIKE mause)

面对这一困难,它将选择两行,选择每一行“目录”和“用途”,这是一个问题,因为我只想选择第一行,因为首先我选择“目录”,然后在第3页是“用途”。

在第二行“用途”为第1栏,因此选择这一行次,因为“散射”为“用途”。

<>>>>>>>>>> >>>>> >> >> > > >_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_ SOME UPDATES to MY <>>>>>_ _ <>_>_>_>_>_>_>_>_>_>_>_>_>

如下: 我在数据库中表格的例子。 所有记录都作为VARCHAR被淡化。 我必须写上链接,因为我对 st流的声望很低,我可以在这里打下形象。

与数据库链接

我想选择从拉斯维加斯到芝加哥的路线。 但是,当我这样问:

    SELECT * FROM mytable 
WHERE (station1 LIKE Las Vegas OR station2 LIKE Las Vegas OR station3 LIKE Las Vegas) AND (station1 LIKE Chicago OR station2 LIKE Chicago OR station3 LIKE Chicago)

它将选择所有包含Las Vegas和芝加哥的行文,但我不想选择芝加哥首先在数据库中的位置。 我只想选择Las Vegas在坐桌前在芝加哥的这条路线。 因此,这只是第一行“第一行”。

在“Las Vegas”号站(Las Vegas号站,第3号,芝加哥站2号)之后,我不想,第3行也是如此。

我认为,现在大家都很清楚。

最佳回答

我不敢理解你的含义,但我猜想! 这是否是:

SELECT * 
  FROM myTable
    WHERE (station1 LIKE  %Las Vegas%  AND (
               station2 LIKE  %Chicago%  OR
               station3 LIKE  %Chicago%  OR
               station4 LIKE  %Chicago%  OR
               station5 LIKE  %Chicago% )
          ) OR
          (station2 LIKE  %Las Vegas%  AND (
               station3 LIKE  %Chicago%  OR
               station4 LIKE  %Chicago%  OR
               station5 LIKE  %Chicago% )
          ) OR
          (station3 LIKE  %Las Vegas%  AND (
               station4 LIKE  %Chicago%  OR
               station5 LIKE  %Chicago% )
          ) OR
          (station4 LIKE  %Las Vegas%  AND (
               station5 LIKE  %Chicago% )
          )

为了产生这种编号<代码>。 鉴于:

$arr_sta = array( station1 ,  station2 ,  station3 ,  station4 );
$nbstations = count($arr_sta);
$where =   ;
for($i=0; $i<$nbstations-1; $i++) {
    $where .= $where ?   OR (  :   WHERE ( ;
    $where .= $arr_sta[$i] . " LIKE  %Las Vegas% ";
    $where2 =   ;
    for($j=$i+1; $j<$nbstations; $j++) {
        $where2 .= $where2 ?   OR   :   AND ( ;
        $where2 .= $arr_sta[$j] . " LIKE  %Chicago% ";
    }
    if ($where2) $where .= $where2 .  ) ;
    $where .=  ) ;
}
问题回答

请在您的问询结束时增加LMIT 0,1。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...