DarkWater Posted April 24, 2008 Share Posted April 24, 2008 I rewrote a script I made to display posted comments, because I realized I was using a lot of unnecessary MySQL return values. I rewrote it to simply be this: <?php $query="SELECT u.username, comments.* FROM comments, users as u WHERE comments.user_id = u.user_id ORDER BY comment_id DESC"; $result=mysql_query($query) or die (mysql_error()); while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) { echo stripslashes($row['comments']) . "<br /> posted by " . $row['username'] . " <a href=\"./comments.php?id={$row['comment_id']}\">delete</a><hr width=30% align=\"left\"><br />"; } ?> Is there any way to make that query any better? EDIT: I hardly make new topics asking for help, but I just want to know if there's a simpler query. =P I doubt it though/ Link to comment https://forums.phpfreaks.com/topic/102755-best-way-to-query-this-_/ Share on other sites More sharing options...
haku Posted April 24, 2008 Share Posted April 24, 2008 replace the * in comments.* with the actual column names you want. Even if you are getting all fields, when you use the star, the script has to first check all the column names and then pass back all the info. If you specify the column names it removes that step. Link to comment https://forums.phpfreaks.com/topic/102755-best-way-to-query-this-_/#findComment-526290 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Author Share Posted April 24, 2008 Oh, alright. =P Even though I'm using all the columns. xD Link to comment https://forums.phpfreaks.com/topic/102755-best-way-to-query-this-_/#findComment-526297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.