选择带有单词mysql的url的preg_match_all id

时间:2016-08-12 03:04:40

标签: php mysql preg-match-all

想要使用select命令从sql获取新闻ID 我用php运行它

   //get the last part
$arrayUrl=explode("/",$url);
$finalPath=$arrayUrl[count($arrayUrl)-1];

preg_match("/\d+/",$finalPath,$matches);

示例网址格式:

http://www.xxxx.com/t1134133-0 
http://www.xxxx.com/t1134133-2 
http://www.xxxx.com/t1134133-3 
http://www.xxxx.com/t1134133-news-news-worlds 
http://www.xxxx.com/t1134133-mi%20&ffjfj

但我需要尝试获取像1134133这样的ID组并计算它 我试试

    <?                  $seleddcddddddtMaidfsdfgnwork =
"SELECT *  FROM  `online_site`  WHERE  `url` LIKE  '%http://www. xxxx.com/t%'  GROUP BY url ORDER BY COUNT( url )  desc LIMIT 20 "; $resddrdddddddddult3 = $DB->query($seleddcddddddtMaidfsdfgnwork);

        while ($rdddddodhhdw = mysql_fetch_assoc($resddrdddddddddult3))  { ?>



        <tr>


        <td class="text-center"> <a href="<? echo $rdddddodhhdw['url']; ?>" target="_blank"> <? $uu= $rdddddodhhdw['url']; 
                 $arrayUrl=explode("/",$uu); $finalPath=$arrayUrl[count($arrayUrl)-1];

        preg_match("/\d+/",$finalPath,$matches);


        $iiid= $matches['0'];   


                     $dddd34fdf ="select * from news where id ='$iiid'  "; $resddrddddddddddult3 = $DB->query($dddd34fdf);

        while ($rddddddodhhdw = mysql_fetch_assoc($resddrddddddddddult3))  {     echo $rddddddodhhdw['title'];    echo ' - ' ; 

        $dddd34fdf ="SELECT count(*) as total from online_site where  `url` LIKE  '%$iiid%'    "; $resddrddddddddddult3 = $DB->query($dddd34fdf); $data=mysql_fetch_assoc($resddrddddddddddult3); echo '( '.$data['total'].' )';

        }?>

1 个答案:

答案 0 :(得分:0)

select
 SUBSTRING_INDEX(SUBSTRING_INDEX( url , '/t', -1), '-', 1)  AS links  
from  online_site  
having     links<>'http://www.xxx'     order by id desc limit 100 ;