I would like to ask if your writing method is the same as mine?
Suppose I want to use loop to retrieve data
<code>while ($row=mysql_fetch_array($sql)){ 資料顯示... } </code>
But suppose I need to loop the $row[id] in the data to do other things
I have to put mysql_query into the while so that I can know the $row[id] of each transaction
Like this
<code>while ($row=mysql_fetch_array($gettimeline)){ $sql2 = mysql_query("SELECT * FROM `xxx` WHERE `id` = '".$row['id']."' "); } </code>
Then after each piece of data is retrieved
won’t he repeat the $sql2 query for each piece of data?
Is this the right way to write it? The same goes for ajax. Suppose I want to delete an article. In order to get the article id, I still have to put it into a while loop
<code>while ($row=mysql_fetch_array($gettimeline)){ $sql2 = mysql_query("SELECT * FROM `xxx` WHERE `id` = '".$row['id']."' "); <script> $("#remove_timeline_<? echo $row['timeline_id'];?>").click(function(){ $.ajax({ type: "POST", url:"remove?to=<? echo $row['timeline_id'];?>", cache: false, success: function(){ } }); } }); </script> } </code>
<code>while ($row=mysql_fetch_array($sql)){ 資料顯示... } </code>
Like this
<code>while ($row=mysql_fetch_array($gettimeline)){ $sql2 = mysql_query("SELECT * FROM `xxx` WHERE `id` = '".$row['id']."' "); } </code>
Is this the right way to write it? The same goes for ajax. Suppose I want to delete an article. In order to get the article id, I still have to put it into a while loop
<code>while ($row=mysql_fetch_array($gettimeline)){ $sql2 = mysql_query("SELECT * FROM `xxx` WHERE `id` = '".$row['id']."' "); <script> $("#remove_timeline_<? echo $row['timeline_id'];?>").click(function(){ $.ajax({ type: "POST", url:"remove?to=<? echo $row['timeline_id'];?>", cache: false, success: function(){ } }); } }); </script> } </code>
"Cycle" means "circulation", right?
When the number of data items increases, the number of requests will also increase. Generally, such repeated and similar external IO will be considered for merging.
For example:
<code class="sql">SELECT * FROM `xxx` WHERE id in (1,2,3,4,5)</code>