Jump to content
MakeWebGames

Recommended Posts

Posted

Hello,

Well I've seen some modifications, and some are great as an Idea! But some ruin it from the coding. Mainly is the performance on my concern, so today, I am going to to show you have to increase your performance. This is not going to be a BIG (S.A). But I will be easy to understand. :)

So first I'll start of with: Selecting

So I've seen a few mods selecting everything. Now, when selecting all the table(*), it will select EVERYTHING from that table. Some people don't seem to understand. I have suggested this to some friends on MSN not to select everything. Around 88% said what is needed to select. Now, I understand begginer's(I don't like calling people Noobs -.-) don't know what to select. So I look around on MWG and look for some examples. I found something that is easy to understand. Now look at this code:

 

$q=$db->query("SELECT cm.*, u.* FROM crystalmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER ORDER BY cmPRICE/cmQTY ASC");
while($r=$db->fetch_row($q))
{
if($r['cmADDER'] == $userid) { $link = "[url='cmarket.php?action=remove&ID={$r[']Remove[/url]"; } else { $link = "[url='cmarket.php?action=buy&ID={$r[']Buy[/url]"; }
$each= abs(intval($r['cmPRICE'] / $r['cmQTY']));

 

Now as you can see, there is some very dodgey selecting there, and that is self is not needed. Lets look at it first. SELECT cm.*, u.*: Now if you saw what I typed up there - (*) - Selects everything from a table. This coder has decided to select the same table twice. And if you can see (cm) I looked at table for the `crystal market` and cm is connected to (cmID - cmQTY - cmPRICE - etc...) Seriously.. WTF!

On another part of the code, as most coders can tell. while($r = $db->fetch_row($q)): While(Read that). $r is going to Assign(=) to the query ($q). Now if we go down more(Remember ($r) now assigns to the query ($q)). {$r['cmID']} || {$r['cmID']} || {$r['cmPRICE']} || {$r['cmQTY']} || Now before some of you ask(Who know what there doing) yes I have done cmID. Yes. Because it's there. For people who are most probably think(Should I add `cmID` twice?) Well no. It's already been select so there is no need to select it twice. Anyway, as you can see below, there are 4(4) $r grabbing what's needed here. The fore, they need to be selected. That's all. Now all these extra stuff like (LEFT JOIN users u) It's not needed as it's already adding in `users`. Extra stuff is not needed so.. Just.. Scare them.. Rawr and stuff... So... Let's fix this up :)

 

$Q = $db->query("SELECT `cmID` , `cmQTY` , `cmPRICE` 
                     FROM `crystalmarket` 
                     LEFT JOIN `users` ON `userid` = `cmADDER` 
                     ORDER BY `cmPRICE` / `cmQTY` ASC");

 while ($r = mysql_fetch_row($Q)) // Person Preference (mysql_)
{

 if($r['cmADDER'] == $userid) 
{ $link = "[url='cmarket.php?action=remove&ID={$r[']Remove[/url]"; 

} else { 

  $link = "[url='cmarket.php?action=buy&ID={$r[']Buy[/url]"; }

  $each= abs(intval($r['cmPRICE'] / $r['cmQTY']));

 

Well, hopefully this is correct and will help you. I thought this out myself, so there might be a chance I'm wrong, but some parts I know I am right. A poll would be added to see your thoughts. Comment || Feedback is welcome. Also, I tried to make it funny for you. :P (Submitted votes cannot be changed!)

- Armageddon

Posted

In your example you selected cmID, cmQTY, cmPRICE from the crystalmarket table.

There is nothing being selected from the users table.

So why did you join the users table with the crystalmarket table?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...