mysql - PHP: mysql_fetch_array() in a while-loop takes too long -


I am creating an online calendar for the client using PHP / MySQL.

I received a & lt; Table & gt; and & lt; Tr & gt; , and after that there is a loop that is new for each new & lt; Td> creates

& lt; Td> After the line, PHP searches for any MySQL database for any event that is comparing the value of that day to the value of formatted Unix timestamp within that line of the database for $ i (counter) Only when a match is made, to increase the inner line counter, I have created another loop, which brings a new array for the result. This loading time is significantly slowed down

$ qry = "select * from events where author = \" $ author \ ""; $ Result = mysql_query ($ qry) or die (mysql_error ()); $ Line = mysql_fetch_array ($ result); For {$ I = 1; $ i & lt; = $ max_days; $ i ++} {resonance "& lt; td class = \" day \ "& gt;"; $ Rowunixdate_number = Date ("J", $ line ['UnixDate']); If ($ rowunixdate_number == $ i) {while ($ rowunixdate_number == $ i) {$ rowtitle = $ row ['title']; Alo $ line title; $ Line = mysql_fetch_array ($ result); $ Rowunixdate_number = Date ("J", $ line ['UnixDate']); }} Echo "& lt; / td>"; If (neweek ($ day_count)) {resonant " ; tr & gt;"; } $ Day_count ++; }

The probability of being slow is most likely because you have 31 questions instead of 1 As you are asking NAL L. Shawwa - you create HTML table, if you are trying to achieve upcoming upcoming events for a given author for the month, then you have a single SQL query, and then the result Repeat on the set, in fact, to generate the table e.g.

  $ sql = "SELECT * from events where author = '$ author' ORDER by xdate ASC"; $ $Events = mysql_query ($ sql); Echo ("& lt; table & gt; & lt; tr & gt;"); While ($ Event = mysql_fetch_array ($ rsEvents)) {echo (" [Event info goes here in the event] "); } Echo (" & lt; / table & gt;"); In addition, this is usually a bad idea to differentiate between SQL queries and HTML generation. Your external data should be collected in one place, the output data that is generated in the other my example immediately closes the SQL before the HTML generation, but it is still better than an HTML block in which SQL queries It is placed right in the middle. 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -