菜鸟 问下PHP取出MYSQL数据,然后倒置顺序
mysql数据
php代码:
$res_ip = mysql_query("select * from ip order by id DESC limit 0,5");<br />while($row_ip = mysql_fetch_array($res_ip)){<br /> $ip_ip[] = intval($row_ip['ip']);<br /> $time_ip[] = date($row_ip['time']);<br />}<br />$data_ip = array(array("name"=>"IP流量","data"=>$ip_ip));<br />$data_ip = json_encode($data_ip);<br />$times_ip = json_encode($time_ip);<br />$times_ip = str_replace('2015-', '', $times_ip);
结果:
["01-25","01-25","01-24","01-23","01-22"]
[{"name":"IP\u6d41\u91cf","data":[12632220,12735020,127350,2213488,2348888]}]
想要的效果:
["01-22","01-23","01-24","01-25","01-26"]
[{"name":"IP\u6d41\u91cf","data":[2348888,2213488,127350,12735020,12632220]}]
说明: 就是相当于 把取出的最新5条数据,倒置过来。正常的取出来的5条最新数据是:5 4 3 2 1. 想要的是 1 2 3 4 5。 5 是最新的数据。
致谢!
------解决思路----------------------
id desc 改成 id asc 是不行的!
id desc 的本意是取最新数据,而 id asc 是取最旧的数据
要用 array_reverse 转置数组
$data_ip = array(array("name"=>"IP流量","data"=> array_reverse($ip_ip)));<br />$data_ip = json_encode($data_ip);<br />$times_ip = json_encode(array_reverse($time_ip));<br />$times_ip = str_replace('2015-', '', $times_ip);<br />

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

WebStorm Mac版
好用的JavaScript开发工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Linux新版
SublimeText3 Linux最新版

Dreamweaver CS6
视觉化网页开发工具