Current location: Hot Scripts Forums » Programming Languages » PHP » php/mysql question

php/mysql question

Reply
  #1 (permalink)  
Old 12-01-08, 07:07 PM
richardhotscript richardhotscript is offline
New Member
 
Join Date: Nov 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
php/mysql question

Hi guys

I have a mysql question. here's my problem.

I have a table with a column that contains two IDs from a separate table.
the IDs are separated by commas like this
Name:  1.bmp
Views: 70
Size:  47.1 KB

Now these two IDs are located in separate table so I made my query like this:
$sql=mysql_query("select * from tb_client_category where id like '%$id%' ");

instead of returning only 110 and 52 it return these IDs 110,52 and 1 when it should ony be 110 and 52. Can you guys help fix this? Is there I can fix this without modifying the structure of my table?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-02-08, 05:53 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,029
Thanks: 14
Thanked 34 Times in 33 Posts
Quote:
Originally Posted by richardhotscript View Post
instead of returning only 110 and 52 it return these IDs 110,52 and 1 when it should ony be 110 and 52. Can you guys help fix this? Is there I can fix this without modifying the structure of my table?
If you use "LIKE" then mySQL returns all of the values that match any part of your specified string, which is probably why you're getting values back that you don't want or expect.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-02-08, 07:01 AM
richardhotscript richardhotscript is offline
New Member
 
Join Date: Nov 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
so using LIKE is not correct for this right? so what am I going to use? the datatype for this comma separated ID is varchar.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-02-08, 08:40 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
It might be better to pull the row then split up the ID's, then use them separately? I presume you know the ID's that you need to pull?

PHP Code:
$client_category explode(","$row['client_category']);

// This will loop through all the comma seperated caterogy ID's available
foreach ($client_category as $k => $category_id) {
    
// Use the $category_id you need here

Ignore me if I have misunderstood!
__________________
Always sanitise your data


Best regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple php/mysql question about date() & REMOTE_ADDR jim14 PHP 2 06-07-08 09:36 AM
PHP/MySQL Question nova912 Database 2 03-15-07 01:27 PM
Injecting a string into an If Statement ? nova912 PHP 4 07-21-06 02:04 PM
Another PHP/MySQL Question Lucas PHP 1 06-25-04 12:27 PM
question and answer software jaydifox C/C++ 0 02-21-04 09:26 AM


All times are GMT -5. The time now is 07:08 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.