chocopi Posted May 30, 2007 Share Posted May 30, 2007 if an array is not in numerical order is it in alphabetical order ? EG: In my database i have a, b and c stored. If i had an array like $array = array('','aaa','bbb','ccc'); Would it put them in alphabetical order so a = aaa , b = bbb and c = ccc ? Cheers ~ Chocopi Quote Link to comment Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 you can use sorting features: www.php.net/sort www.php.net/asort www.php.net/array Should have all the information you need. Quote Link to comment Share on other sites More sharing options...
chocopi Posted May 31, 2007 Author Share Posted May 31, 2007 Cheers Frost, This is what I have so far, but I do not know how to put $table1 into the array. <?php $enemy_id = $_SESSION['enemy_id']; $enemy_drop1 = $_SESSION['enemy_drop1']; // Work out enemy drops $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table1, $id1) = split("_", $row['drop1']); $array = array('','Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $array) { $drop1 = mysql_query("SELECT `$id1` FROM `$array` WHERE `id`='$id1'"); } ?> Thanks, ~ Chocopi Quote Link to comment Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 // this will not work as the $array has to stay intact. foreach ($array as $key => $array) { $drop1 = mysql_query("SELECT `$id1` FROM `$array` WHERE `id`='$id1'"); } // try this instead foreach ($array as $key => $table) { $drop1 = mysql_query("SELECT `$id1` FROM `$table` WHERE `id`='$id1'"); } Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Cheers, but its still not returning anything ~ Chocopi Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 add this to the end of the script <?php echo 'This script DID return something, I just forgot to add output to it!!!!'; ?> Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Lol Ok but for some reason the query is empty this is what i have: <?php $enemy_id = $_SESSION['enemy_id']; // Work out enemy drops $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table1, $id1) = split("_", $row['drop1']); $array = array('','Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table1) { $drop1 = mysql_query("SELECT `$id1` FROM `$array` WHERE `id`='$id1'"); mysql_query($drop1) or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 <?php $enemy_id = $_SESSION['enemy_id']; // Work out enemy drops $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table1, $id1) = split("_", $row['drop1']); $array = array('','Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table1) { $drop1 = mysql_query("SELECT `$id1` FROM `$table1` WHERE `id`='$id1'"); mysql_query($drop1) or die(mysql_error()); } ?> I bet it was when you are trying to call the table with the value "Array" you needed to put $table1 not $array as was pointed out above... Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 oh yea my bad, but i only put that in there for a test. But its still saying the query is empty ~ Choocpi Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 blah my bad didn't notice that you are trying to do 2 query runs. <?php $enemy_id = $_SESSION['enemy_id']; // Work out enemy drops $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table1, $id1) = split("_", $row['drop1']); $array = array('','Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table1) { $drop1 = "SELECT `$id1` FROM `$table1` WHERE `id`='$id1'"; mysql_query($drop1) or die(mysql_error() ' ON Query ' . $drop1); // you were trying to run a query that was already ran and returned a resource. once should do. } ?> Try that, sometimes it's hard to catch all the mistakes made. Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks, but i get this error unexpected T_CONSTANT_ENCAPSED_STRING on line 36 line 36: mysql_query($drop1) or die(mysql_error() ' ON Query ' . $drop1); Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 wow... mysql_query($drop1) or die(mysql_error() . ' ON Query ' . $drop1); Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 cheers, i thought about adding the . but i decided against it So im being told the table does not exist (Incorrect table name '' ON Query SELECT `` FROM `` WHERE `id`='' ) But the vaules in the array $array = array('','Body','Hats','Items','Pants','Weapons'); are corrected so i dont have clue what the problem is Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 Note the first value of the array $array = array('','Body','Hats','Items','Pants','Weapons'); it is '' $array = array(Body','Hats','Items','Pants','Weapons'); That may throw it off. $drop1 = "SELECT `$id1` FROM `$table1` WHERE `id`='$id1'"; Why are you trying to select a column $id1, which apparently has no value ??? $drop1 = "SELECT `id` FROM `$table1` WHERE `id`='$id1'"; maybe what you are looking for but that makes no sense what so ever. $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'") or DIE(mysql_error()); Change the above just incase that is not getting the data you want. Other than that you are on your own bud. That is about all I can find wrong without seeing the DB structure etc. Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Cheers i changed it to the following as suggested Now echo $drop1; gives me the resource id so how i change this into the value. I tried $drop1 = $drop1['id']; but that didnt work <?php // Work out enemy drops $enemy_query = mysql_query("SELECT `drop1` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table1, $id1) = split("_", $row['drop1']); $array = array('Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table1) { $drop1 = "SELECT `id` FROM `$table1` WHERE `id`='$id1'"; $drop1 = mysql_query($drop1) or die(mysql_error() . ' ON Query ' . $drop1); } ?> Quote Link to comment 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.