0

I have the following code:

$sql_sd = select sd_code from stamp_den;
$rest2   = odbc_exec($conn,$sql_sd);
while(odbc_fetch_into($rest2,$row_s))
 {             
   $row_sd=$row_s[0];
 }
  //here i get sd_code as follows: 45, 46, 47, 48 etc
for ($i=0; $i<$td_date ;$i++)
 {
   $qu=select stamp_type from stamp_type where sd_code=$row_sd; 
 }

This whole code is inside another while loop.

Now in the for loop while executing the '$qu' query it takes values of sd_code as 45,45,45,45,46,46,46,46 etc depending upon the number of iterations.

How can I modify the code to take distinct values of sd_code while executing the $qu query. (45,46,47, etc)

If there is problem with the syntax please ignore, all variables and loops are declared. My code is executing properly, but not giving the desired o/p.

4
  • 1
    you can just you SQL like this => SELECT DISTINCT sd_code from stamp_den to receive distinct values from database Commented Jan 8, 2013 at 7:07
  • Possible duplicate of : stackoverflow.com/questions/6032796/… Commented Jan 8, 2013 at 7:09
  • @DaHaKa what you suggested is the real solution, why not post it as an answer and get some credit for your suggestion Commented Jan 8, 2013 at 7:09
  • Why aren't you just running SELECT sd_code, stamp_type FROM stamp_den JOIN stamp_code USING (sd_code) ORDER BY sd_code, stamp_type and then building a map of sd_codes to lists of stamp_types and work with that? They way you appear to be doing things now will probably generate in an order of magnitude or more of network traffic via database trips. Commented Jan 8, 2013 at 17:56

1 Answer 1

2

Try:

SELECT DISTINCT sd_code from stamp_den

DISTINCT is used to receive unique data from database.

Sign up to request clarification or add additional context in comments.

Comments

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.