The Little Guy Posted December 1, 2006 Share Posted December 1, 2006 How many mysql_query() functions are too many? What would bog down the server?The page with the most query's for me, is 7 each to a different table, is that too many?I am not even finished with that page either, so there will be more query's for that page soon. Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/ Share on other sites More sharing options...
HuggieBear Posted December 1, 2006 Share Posted December 1, 2006 This question is too ambiguous, it's really related to the data the query's bringing back. Look at these two queries:SELECT id FROM table_name WHERE unique_value = 1 LIMIT 1SELECT * FROM table_nameNow imagine that my table has 45 million rows in it 20 columns. The first piece of code is going to execute relatively quickly and is returning one piece of information, the second will take a very long time as it's trying to return 900 million pieces of information.I don't see that there's a problem with having lots of calls to mysql_query() on a page, but try to keep your code efficient.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133334 Share on other sites More sharing options...
The Little Guy Posted December 2, 2006 Author Share Posted December 2, 2006 OK, Cool Thanks. I will have to fix my Select Statements then.Any other opinions? Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133778 Share on other sites More sharing options...
corbin Posted December 2, 2006 Share Posted December 2, 2006 Instead of selecting from 7 differnet tables, you could try to merge statments.Example:Lets say you have a table accounts and a table users and accounts is id name password and users is id accountid and username.Lets also say you are pulling the id from accounts in a query then pulling everything from users for that id. Instead, you could do:SELECT * FROM accounts,users where accounts.id = '{$id} AND users.accountid = accounts.id Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133802 Share on other sites More sharing options...
The Little Guy Posted December 2, 2006 Author Share Posted December 2, 2006 OK, so do a table join, I'm just starting to learn that, and would like to try it.Well... Here is what I currently have (the bottom portion).[CODE]<div class="sub_content"> <h2>Friends</h2> <div class="user_content"> <?php $sqlgetnfriends = mysql_query("SELECT * FROM friends WHERE status='1' AND (friend_id='$_SESSION[userid]' OR owner_id='$_SESSION[userid]')"); $num_friends_row = mysql_num_rows($sqlgetnfriends); $sqlget = mysql_query("SELECT * FROM friends WHERE status='1' AND (friend_id='$_SESSION[userid]' OR owner_id='$_SESSION[userid]') LIMIT 28"); if(!$num_friends_row){ echo'No Friends Yet.'; }else{ echo'<h5>'.$num_friends_row.' Friends</h5>'; } echo'<table>'; echo'<tr>'."\n"; $display = 0; for($i=0;$i<4;$i++){ while($check=mysql_fetch_array($sqlget)){ if($check['owner_id'] == $_SESSION['userid']){ $friends_sql = mysql_query("SELECT * FROM friends WHERE status='1' AND friend_id='$check[friend_id]'")or die(mysql_error()); $user = 1; }else{ $friends_sql = mysql_query("SELECT * FROM friends WHERE status='1' AND owner_id='$check[owner_id]'")or die(mysql_error()); $user = 2; } $friends_row = mysql_fetch_array($friends_sql); if($user==1){ $friends_rows_sql = mysql_query("SELECT * FROM users WHERE user_id='$friends_row[friend_id]'")or die(mysql_error()); }else{ $friends_rows_sql = mysql_query("SELECT * FROM users WHERE user_id='$friends_row[owner_id]'")or die(mysql_error()); } $friends_rows_row = mysql_fetch_array($friends_rows_sql); if($user==1){ $friends_rows_default = mysql_query("SELECT * FROM default_images WHERE owner_id='$friends_row[friend_id]'")or die(mysql_error()); }else{ $friends_rows_default = mysql_query("SELECT * FROM default_images WHERE owner_id='$friends_row[owner_id]'")or die(mysql_error()); } $friends_rows_default = mysql_fetch_array($friends_rows_default); if(!$friends_rows_default && $friends_rows_row['gender']=="male"){ echo'<td style="text-align:center"><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'"><img style="margin-top:2px;" src="images/m_no_photo90.gif"></a>'."\n"; echo'<br><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'">'.$friends_rows_row['first'].'</a></td>'."\n"; }elseif(!$friends_rows_default && $friends_rows_row['gender']=="female"){ echo'<td style="text-align:center"><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'"><img style="margin-top:2px;" src="images/f_no_photo90.gif"></a>'."\n"; echo'<br><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'">'.$friends_rows_row['first'].'</a></td>'."\n"; }else{ echo'<td style="text-align:center"><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'"><img style="margin-top:2px;" src="user_images/mini/'.$friends_rows_default['file_name'].'"></a>'."\n"; echo'<br><a href="user_profile.php?user_id='.$friends_rows_row['user_id'].'">'.$friends_rows_row['first'].'</a></td>'."\n"; } $display++; } echo'<tr>'; } echo'</table>'; ?> </div> </div>[/CODE] Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133807 Share on other sites More sharing options...
trq Posted December 2, 2006 Share Posted December 2, 2006 [quote]Well... Here is what I currently have (the bottom portion).[/quote]And? Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133834 Share on other sites More sharing options...
The Little Guy Posted December 2, 2006 Author Share Posted December 2, 2006 I guess I was just wondering what you thing. with the mysql_query's Quote Link to comment https://forums.phpfreaks.com/topic/29081-mysql_query/#findComment-133864 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.