DragonPrime - LoGD Resource Community

Coding Support => Coding Support Desk => Topic started by: TGTarheel on December 03, 2018, 01:32:15 AM



Title: Clan Weapon and Armor Shops
Post by: TGTarheel on December 03, 2018, 01:32:15 AM
ok, I do not understand something here.  When I go into the shops, the order of weapons available does nt seem to match the sql call.  Coding below.

According to what I see, it should order the rows by "value" which is the attack/defense strength of the weapon.

But the output I get is ordered by "shopid" - meaning someone who made a much weaker weapon, later than I made a powerful weapon....my weapon is showing up first...instead of ordering it by order of lowest value to highest value.

Here is the coding - I did not alter this from the original module in any way...except biggifying the type using <big> and </big>
Code:
rawoutput("<table border=0 cellpadding=2 cellspacing=1 bgcolor='#999999'>");
    rawoutput("<tr class='trhead'>");
   rawoutput("<td><big>$buy1</big></td><td><big>$wname</big></td><td><big>$watk</big></td><td><big>$wcost</big></td>");
    rawoutput("</tr>");
   $sql = "SELECT * FROM " .db_prefix("clanshop"). " WHERE type = '1' AND clan = '$clan' AND buyer < 1 AND value < '$dklimit' ORDER BY 'value'";
$res = db_query($sql);
   for ($i=0;$i<db_num_rows($res);$i++){
   $row = db_fetch_assoc($res);
     $id = $row['shopid'];
        $name = $row['name'];
     $value = $row['value'];
     $cost = $row['cost'];
       rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>");
rawoutput("<td nowrap>[ <big><a href='runmodule.php?module=clanforge&op=buyweapon&id=$id'>$choose</big></a>]");
        addnav("","runmodule.php?module=clanforge&op=buyweapon&id=$id");
   output_notl("<td><big>`^%s</big></td>`0", $row['name'], true);
     output_notl("<td><big>`&%s`0</big></td>", $row['value'], true);
        output_notl("<td><big>`^%s`0</big></td>", $row['cost'], true);
        rawoutput("</tr>");
}
    rawoutput("</table>");

It eve says in the SQL call, ORDER BY "value" - so why is the output ordering by "shopid" instead?


Title: Re: Clan Weapon and Armor Shops
Post by: TGTarheel on December 03, 2018, 01:43:24 AM
Never mind.

I found my own problem.  The original coder put 'value' as is

ORDER BY 'value'

and it should be

ORDER BY value ASC

No quotes around value, and specify ascending versus descending order.

I like to play with this stuff to learn how things work and why.

I found my own answer this time.



© 2018 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines