how to query


my problem is how to query/code in the table where ID=IDS

if the ID consist of 20, the result of query will display 01,03,07 and 10 because of the IDS

ex: NAME || ID
rhyan || 01
junel || 02
jaycee || 03
jay || 04
Neil || 05
Stephen || 06
alleen || 07

rhyan || 01
jaycee || 03
Neil || 05
alleen || 07

any idea? plese help me… tnx

I am having trouble understanding what you are trying to do.

Are you looking for SELECT * FROM mytable WHERE id = ‘01’ or id = ‘03’…

or are you saying you have a list of IDs and need to return each one?

If this is the case and you have a string of IDs you will need to convert that to an array which you will want to use explode() or Implode() can’t remember which one it would be. One goes from string to array and the other from array to string.

Then loop through the array and run a query per array item.

SELECT * FROM mytable WHERE id = ‘$myID_array[$i]’…

Hope this helps if not please try to clarify what you are trying to accomplish.

this is my query:
$sql = “SELECT * FROM PM30600”;
$r = mssql_query ( $sql, $cs ) or die ( ‘Query Error’ );
while ( $row = mssql_fetch_array ( $r ) )
now all the id is in the “ids”
my next query is:

how to query in the next table where the empid = ids
something like this:
SELECT * FROM PM10100 WHERE empid = ids

can you help me using array?

i would not use ans array but a query over two tables:

SELECT * FROM PM30600, PM10100 WHERE PM30600.fldid = PM10100.empid

A few notes I’d like to place here:
I’d strongly recommend against using multiple queries when one is sufficient. Q1712’s SQL query would probably be the best solution for this matter, however should you want to use the IDs in an array after retrieving this list of information, then you could also use a second query:

SELECT * FROM PM30600 WHERE fldid IN ($ids)

Disclaimer: not meant to work, do some research before using queries.

Next, make a list for yourself which information from the SQL database you really want. If you query on a table that exists of 30+ columns and you only use two of them, that’s an awful waste of resources and time. Rather than using * in your query, use comma-separated lists of column names if you don’t need most or all column values. It also makes your code look cleaner and gives you more of an overview of which indexes are available without you having to look it up.

Another side note:

$ids = $row[‘id’]; //Will not create an array.

If you were to echo this out you would get only the last value.

$ids[] = $row[‘id’]; //This will create and push the values onto the array.

Just thought I would mention that so next time you do need to do such a thing you would know.

ok, tnx guys for helping me a lot…

my next problem is this:

in my TABLE i have fields (transnum, credit, debit, branch)
now, my table looks like this:

| transnum | credit | debit | branch |


my first query is SELECT * FROM TABLE1 WHERE branch=‘abc’

the result of that query is this
| 111 | 000 | 200 | abc |

my problem is, how to display all the same transnum where the branch = abc

by the way… im using mssql :D
and the front end is Microsoft Business Solution - Great Plains

ur db looks unnormalised.

thy to build up a good db structure firts, and then think about the querys.


im not the one who create the db… thats the default of Microsoft Great Plains… the only thing i can do is only the query…

got it guys… i use nested query…

FROM PM30600
FROM PM30600
WHERE DistRef = ‘12589’))

Sponsor our Newsletter | Privacy Policy | Terms of Service