Jump to content

[SOLVED] possible to query a array of objects?


krispykreme

Recommended Posts

lets say i have an array of something like

 

$users[]=123;

$users[]=126;

$users[]=323;

 

this array can be an infinite amount of size in theory but 99% will be under 50 in size

 

 

i want to do something like...

 

$query=mysql_query("SELECT rank,score FROM users WHERE userid='$users[]' order by rank ASC");

 

 

now this isnt the correct syntax to use, but the hard part im getting at is that i need this information sorted other wise i could just do multiple queries in a for statement going through the array

 

is it possible to do anything like what i want?

Link to comment
Share on other sites

hmmm is there a certain version of mysql to allow you to do this?

 

currently this just shows no information

 

doesnt error or anything from what i can see

 

 

before it does the join thing in  the query i have it print the array and it shows

Array ( [0] => 772474564 [1] => 1414350111 [2] => 20707488 )

 

all of which are in the database so it should be finding these i believe instead of nothing

Link to comment
Share on other sites

You have numeric customer id's that big, wow. Well, I assume your table column can  handle it.

 

Well, put displays to show the full query before it's executed. Take that query and run it outside of PHP, like using myphpadmin. Post actual code and make sure you're properly checking for any MySQL errors (after every call).

 

Display query:

<?php

$arrUsers[] = 772474564;
$arrUsers[] = 1414350111;
$arrUsers[] = 20707488;

$sql = 'SELECT `rank`, `score` FROM `users` WHERE `userid` IN (' . join (', ', $arrUsers) . ') ORDER BY `rank` ASC';

echo $sql;

?>

 

Above code would produce this query, which you can use to run outside of PHP to see if it works.

SELECT `rank`, `score` FROM `users` WHERE `userid` IN (772474564, 1414350111, 20707488) ORDER BY `rank` ASC

 

 

Link to comment
Share on other sites

alright thanks!

 

looks like my quotes were messing it up it seemed and your example method worked perfectly!

 

do you happen to know the limits of this?  like can the array be of inifinite size?

 

also if userid is indexed will it run optimized still?  since these are primary keys that cant exist more than once and only examine those rows instead of the whole table?  guess i could say examine haha

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.