Jump to content

mysql behaving wierd


ghqwerty

Recommended Posts

ok so im trying to alter the code ive got so that instead of 'deleting' some thing from the records you also get some money back

 

at the moment im just trying to get back the total cost of the items im selecting so that i can process it and then add it to money however it doesnt seem to be working

 

the stats are all in a database

 

the most ive got to so far is it always shows 'drugs' and 10000

 

oh almost forgot the code

 

                                $qryq = mysql_query("select item from items where itemid = '".$id."'") or die(mysql_error());
                                while($qryqresult = mysql_fetch_array( $qryq )){
                                    $itema[] = $qryqresult['item'];
                                    $itemarray = implode(",", $itema);
                                    echo $itemarray;
                                $qeuryitem = mysql_query("select moneyexcellent from itemstats where item = '".$itemarray."'") or die(mysql_error());
                                    while($queryitemselect = mysql_fetch_array($qeuryitem)){
                                        $itemcost[] = $queryitemselect['moneyexcellent'];
                                        $itemstring = implode(",", $itemcost);
                                        echo $itemstring;
                                        }
                                }

Link to comment
https://forums.phpfreaks.com/topic/126875-mysql-behaving-wierd/
Share on other sites

When you do a $itema[] = $qryqresult['item']; this adds an element to the end of the array called $itema.

 

array ("a","b","c","d","e").......

 

Then, using implode you gradually build up a long string "a,b,c,d,e" and search another table for "a,b,c,d,e" and it doens't find anything?

 

is this really what you want?

 

To debug:

4 lines down, add a line print_r($itema); to see what I mean.

 

Also,

 

instead of

$qeuryitem = mysql_query("select moneyexcellent from itemstats where item = '".$itemarray."'") or die(mysql_error());

 

do this..

$SQL="select moneyexcellent from itemstats where item = '".$itemarray."'";

echo $SQL;

$qeuryitem = mysql_query($SQL) or die(mysql_error());

 

 

(Also watch out for that spelling mistake in qeuryitem )

Link to comment
https://forums.phpfreaks.com/topic/126875-mysql-behaving-wierd/#findComment-656400
Share on other sites

ok i get you but how would i get around this ??

 

i have a databse filled with item costs and bonuses

for things like weapons they have differant qualities and each quality is worth more or less

 

so when you select an item(s) it looks for a match to that name

say

bad drugs cost 1000

good drugs cost 5000

excellent drugs cost 10000

and you sold 2 ex and 1 bad it would do (2 x 10000) + (1 x 1000) then you would have to half that because you are selling it

 

i understand what i have to do just stuick on how i am meant to select the cost from the database based on the items stats:S

Link to comment
https://forums.phpfreaks.com/topic/126875-mysql-behaving-wierd/#findComment-656436
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.