chocopi Posted June 2, 2007 Share Posted June 2, 2007 In my code i get the 3 values from the database and then echo then. But when i echo them it shows the same results: <?php // Get drop1 $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 `id` FROM `$table1` WHERE `id`='$id1'"); $drop1 = mysql_fetch_assoc($drop1) or die(mysql_error() . ' ON Query ' . $drop1); $drop1 = $drop1['id']; $drop1_image = $image_root.''.strtolower($table1).'/'.$drop1.'.gif'; } // Get drop2 $enemy_query = mysql_query("SELECT `drop2` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table2, $id2) = split("_", $row['drop2']); $array = array('Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table2) { $drop2 = mysql_query("SELECT `id` FROM `$table2` WHERE `id`='$id2'"); $drop2 = @mysql_fetch_assoc($drop2) or die("Invalid query, please contact an administrator!"); $drop2 = $drop2['id']; $drop2_image = $image_root.''.strtolower($table2).'/'.$drop2.'.gif'; } // Get drop3 $enemy_query = mysql_query("SELECT `drop3` FROM `Enemies` WHERE `id`='$enemy_id'"); $row = @mysql_fetch_assoc($enemy_query) or die("Invalid query, please contact an administrator!"); list($table3, $id3) = split("_", $row['drop3']); $array = array('Body','Hats','Items','Pants','Weapons'); sort($array); foreach ($array as $key => $table3) { $drop3 = mysql_query("SELECT `id` FROM `$table3` WHERE `id`='$id3'"); $drop3 = @mysql_fetch_assoc($drop3) or die("Invalid query, please contact an administrator!"); $drop3 = $drop3['id']; $drop3_image = $image_root.''.strtolower($table3).'/'.$drop3.'.gif'; } ?> So when i echo these i get the same value printed: <?php print ("<br /><img src=\"$drop1_image\" name=\"$drop1\" id=\"$drop1\" alt=\"$drop1\" /><b>$drop1</b>\n"); print ("<br /><img src=\"$drop2_image\" name=\"$drop2\" id=\"$drop2\" alt=\"$drop2\" /><b>$drop2</b>\n"); print ("<br /><img src=\"$drop3_image\" name=\"$drop3\" id=\"$drop3\" alt=\"$drop3\" /><b>$drop3</b>\n"); ?> These all give the value of what should be in $drop1. I think the problem is to do the $table variables. Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/ Share on other sites More sharing options...
Barand Posted June 2, 2007 Share Posted June 2, 2007 I haven't spotted the cause yet but this query puzzles me $drop2 = mysql_query("SELECT `id` FROM `$table2` WHERE `id`='$id2'"); Threre's every chance it's just going to give an answer of $id2, so why bother? Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267120 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Sorry, ??? I dont quite understand what you mean Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267123 Share on other sites More sharing options...
Barand Posted June 2, 2007 Share Posted June 2, 2007 Think about it. If you select id from those records where id=2, what value do think will be in the returned id column? Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267133 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 well its gonna be 2, so what do you suggest i do differently Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267135 Share on other sites More sharing options...
saf Posted June 2, 2007 Share Posted June 2, 2007 Try inserting a few echos throughout your code to trace what it is doing (TRY echoing the $id's so that you know what they hold before you run your query), and you might find the mistake. Secondly, I noticed that you create an array - $array = array('Body','Hats','Items','Pants','Weapons'); and then you run through a similar foreach - foreach ($array as $key => $table1), but in the foreach, you do not have the variables as an array, thus at then end the code will only store what it got from the last element of the array (which would be weapons). if this is what you are planning on doing anyways, i'd suggest you do it like this: $table1='weapons'; $drop1 = mysql_query("SELECT `id` FROM `$table1` WHERE `id`='$id1'"); $drop1 = mysql_fetch_assoc($drop1) or die(mysql_error() . ' ON Query ' . $drop1); $drop1 = $drop1['id']; $drop1_image = $image_root.''.strtolower($table1).'/'.$drop1.'.gif'; Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267139 Share on other sites More sharing options...
Barand Posted June 2, 2007 Share Posted June 2, 2007 well its gonna be 2, so what do you suggest i do differently Either replace $drop2 = mysql_query("SELECT `id` FROM `$table2` WHERE `id`='$id2'"); $drop2 = @mysql_fetch_assoc($drop2) or die("Invalid query, please contact an administrator!"); $drop2 = $drop2['id']; with the equivalent $drop2 = $id2; OR ask yourself if it's really the id column you meant to select in that query. Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267140 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks, but the reason why the id is selected is because it depends on the table. thats why there is $table otherwise if i just had drop2 = $id2; then it would not work. Hey Saf, i just found out that the problem was with the array, and then you posted it . So what do i need to change in the array to make it function properly THANKS, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267141 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.