Jump to content

[SOLVED] array order


chocopi

Recommended Posts

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
Share on other sites

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
Share on other sites

        // 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
Share on other sites

Lol  ;D

 

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

Cheers i changed it to the following as suggested  ;D

 

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