PHP + MySQL Slow results using while loop -


I have created a fast MESQL based news feed on my website where I am writing the last four news stories from the database whereas function + Fetch_arry .. As I recall when I used a script like this, but with it I get very slow results from my code for 18-20 seconds which is not the best thing for my followers .. What is the problem Causes or I may include how you can speed to draw?

$ e = mysql_query (Select 'Date Decec LIMIT 4' from Rental Order); If (! $ E) {dead (mysql_error ()); $ Count = 0; } $ Get_hir = mysql_num_rows (mysql_query ("select * rental order from date DESC LIMIT 4"); If ($ get_hir> & lt; = 0) {echo '& lt; Div class = "lil-box lil-box-tl" & gt; & Lt; Div & gt; & Lt; Center & gt; & Lt; H4 & gt; Nixennek Hieroc! & Lt; / H4 & gt; & Lt; / Center & gt; & Lt; / Div & gt; & Lt; / Div & gt; '; } And {while ($ line = mysql_fetch_array ($ e)) {echo & lt; Div class = "lil-box lil-box-tl" & gt; '; Echo '& lt; H4 & gt; $ Line ['cim'] '& Lt; / H4 & gt; '; If ($ line ['cap'] == 0) {echo ' & gt; ';} and if ($ line [' cap '] == 1) { Echo '& lt; div class = "icon" & gt; & lt; img alt = "src =" image / icon-up .png "width =" 24 "/ & gt; & Lt; / Div & gt; '; } And if ($ line ['cap'] == 2] {echo '

(' tores' is a strlen function.)

Create an index for the field you are sorting (one time query)

  ALTER TABLE` hirek` ADD INDEX` date` (`date  

Your query should be slightly faster on this index.

Also re-enter your code:

 < Code> $ E = mysql_query (select 'wired from hire order) $ (= $) = $ (= $ Mysql_fetch_array ($ e)); $ (if $!); $ D = $ Line; if (count ($ rows) == 0) {echo 
& # 39; & # 39; & # 39; & # 39; & # 39; (& quot;); Else {foreach ($ line As $ rows) {echo & lt; Div class = "lil-box lil-box-tl" & gt; '; Echo '& lt; H4 & gt; $ Line ['cim'] '& Lt; / H4 & gt; '; If ($ line ['cap'] == 0) {echo ' & gt; ';} and if ($ line [' cap '] == 1) { Echo '& lt; div class = "icon" & gt; & lt; img alt = "src =" image / icon-up .png "width =" 24 "/ & gt; & Lt; / Div & gt; '; } And if ($ line ['cap'] == 2] {echo '

These are one (many ways) ways that execute questions twice, in addition to switching to mysqli / pdo Because mysql_ * is excluded.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -