Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/54020-getting-same-result/
Share on other sites

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';

 

 

Link to comment
https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267139
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267140
Share on other sites

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  :D. So what do i need to change in the array to make it function properly

 

THANKS,

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/54020-getting-same-result/#findComment-267141
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.