想要使用 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/