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

标签 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);

URL 格式示例:

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'].' )';

        }?>

最佳答案

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 ;

关于php - 选择带有单词 mysql 的 url 的 preg_match_all id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38909193/

相关文章:

javascript - 使用 JavaScript 或 PHP 从网站启动 putty(带参数)

php - 如何从多个 $_POST 数组插入 MYSQL 行

php - 用于忽略可选逗号的正则表达式

php - 在 WordPress 中使用 preg_match_all 返回部分图像的 url

php - 编辑 Laravel Azure Blob 存储的 x-ms-version

php - 安全疑惑求助(PHP MYSQL APACHE Windows)

php - android 中的 Webview 能够运行 php

mysql - 如何格式化这种日期?

php - mysql left join or full join with fulltext search results

php - 在 PHP 中将数字序列转换为数组