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 Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/ 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. Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-264963 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 Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-265458 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'"); } Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-265534 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 Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266902 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!!!!'; ?> Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266904 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()); } ?> Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266910 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... Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266932 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 Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266935 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. Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266936 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); Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266954 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); Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266956 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 Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266963 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. Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266970 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); } ?> Link to comment https://forums.phpfreaks.com/topic/53605-solved-array-order/#findComment-266982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.