Jump to content

[SOLVED] How to get data of a string and how to use it seperately.


montgomery

Recommended Posts

Hi guys,

 

I am a complete newbie in PHP / MySQL....

This is my problem:

 

I have a field in the DB with numbers (=$PRESELECTED)

The numbers are seperated with commas. Sometimes it is just one number. Sometimes it can be 30 numbers.

If it would always be 5 numbers I could use them like this.

 

$PreselectedSingle= explode(',',$PRESELECTED);

 

$qs = "SELECT * FROM XL_auctions

WHERE  id= $PreselectedSingle[0]

OR id= $PreselectedSingle[1]

OR id= $PreselectedSingle[2]

OR id= $PreselectedSingle[3]

OR id= $PreselectedSingle[4];"

 

But I can not predict how many numbers are in the field.

I tried the PHP WHILE or FOR functions. But it does not work in this SQL statement.

What can I do?

 

Thanks so much for your help!

how about using a foreach..

 

 

$PreselectedSingle= explode(',',$PRESELECTED);

foreach($PreselectedSingle as $value) {

  $qs = "SELECT * FROM XL_auctions

        WHERE  id= $value";

}

 

What a terrible idea... why do ppl like to hammer the DB and use PHP for everything?

Archived

This topic is now archived and is closed to further replies.

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