ok Posted December 8, 2008 Share Posted December 8, 2008 thank you in advance. these codes below took tooooo long to load, <?php //0000-00-00 00:00:00 //Fill invited_by column in USERS table. include 'opendb.php'; //get all unique invited_by $query = "SELECT DISTINCT invited_by FROM users WHERE invited_by!='' ORDER BY invited_by ASC"; $result=mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $i=0; while($row = mysql_fetch_array($result)) { $referer[$i] = $row['invited_by']; #echo "<b>referer: </b>". $referer[$i]; #echo "<br>"; $i++; } if(!empty($referer)) { $i=0; $j++; $c=count($referer); while($i<$c) { $query = "SELECT * FROM users WHERE user_name='$referer[$j]' ORDER BY user_name ASC"; $result=mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $i=0; while($row = mysql_fetch_array($result)) { $user_name = $row['user_name']; $email = $row['email']; echo "{$user_name} ". $email; echo "\n"; $i++; } $j++; } } include 'closedb.php'; ?> can you tell me what's causing the problem? note: i tested the other codes and it works fine, the mere problem is the codes above. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/136049-took-tooooooo-long-to-load/ Share on other sites More sharing options...
JonnoTheDev Posted December 8, 2008 Share Posted December 8, 2008 The number of queries/records returned will be the reason. Have you got a index on invited_by and user_name? Quote Link to comment https://forums.phpfreaks.com/topic/136049-took-tooooooo-long-to-load/#findComment-709343 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 How much data have you got in your users table? You have TWO loops there - have you checked to see which one is slowing it down? Quote Link to comment https://forums.phpfreaks.com/topic/136049-took-tooooooo-long-to-load/#findComment-709349 Share on other sites More sharing options...
redarrow Posted December 8, 2008 Share Posted December 8, 2008 why not like this mate..... <?php include 'opendb.php'; $query2 = "SELECT DISTINCT invited_by FROM users WHERE invited_by!='' ORDER BY invited_by ASC"; $result2=mysql_query($query2) or die("Problem with the query: $query2 on line " . __LINE__ . '<br>' . mysql_error()); while($row2 = mysql_fetch_assoc($result2)) { $query3 = "SELECT * FROM users WHERE user_name='".$row2['invited_by']."' ORDER BY user_name ASC"; $result3=mysql_query($query3) or die("Problem with the query: $query3 on line " . __LINE__ . '<br>' . mysql_error()); while($row = mysql_fetch_assoc($result3)) { $user_name = $row['user_name']; $email = $row['email']; echo "{$user_name} ". $email; echo "\n"; } } include 'closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/136049-took-tooooooo-long-to-load/#findComment-709355 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 What are you trying to accomplish with this code? Stating that may give us an idea of how to correct the issue of grabbing a ton of data into grabbing the needed data. Quote Link to comment https://forums.phpfreaks.com/topic/136049-took-tooooooo-long-to-load/#findComment-709489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.