Jump to content

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


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?

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.