2

the script querys database and retrieves a single entry that has mulitple numbers

SELECT jnum from database where x = y

output = 11111,22222,33333,44444

So i explode that on , and get $variable[0] = 11111 and $variable[1]= 22222

What i want to do is perform a query on another table using each of those numbers (numbers will be different each time and there may be any number of numbers).

is there a way to structure a foreach for each entry in the array or a while loop that counts so that i can query the database for each of the values i get from output above.

i don't know if i am conveying what 'im trying to do here very clearly so i apologize in advance.

i get a single entry for the database table and it contains a string (11111,22222,33333) i explode on , and get the array variable[] there will not always be 3 entries sometime there could be 5 or 7 or 10 or 1 but each one will be unique. but for each value i want to query a db table and retrieve all the rows that have that single number($variable[]) as an entry. Not sure if a loop count or a foreach statement would work. any ideas?

1
  • 1
    I'm curious, why are you parsing data in your table that relates to other columns? This sort of defeats the purpose of using a relational database. Commented Oct 16, 2012 at 22:31

2 Answers 2

1

Well assuming these are values in a single column there is no need to look you can use WHERE ... IN:

SELECT * FROM the_other_table WHERE some_col IN ('11111','22222','33333')
Sign up to request clarification or add additional context in comments.

Comments

0

Check out foreach loops - http://php.net/manual/en/control-structures.foreach.php

foreach ($variable as $value) {

    $myquery = "some query using $value";
    // then execute your query
 }

1 Comment

ok i understand this part but my problem is the $variable is actually an array with values, there could be one number or ten. for example in your foreach the $variable is actually $variable[$x] with $x being one of the numbers from the string, but i need to change $x from 1 to 2 to 3 for each entry that is in the area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.