Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TARCON
Forum Newbie
Posts: 12
Joined: Wed Dec 02, 2009 3:34 pm

Variables

Post by TARCON »

I tried to do a standard search of this topic, but it is hard to explain with just search words. This is probably really really really simple to solve as well.

Anyways, I am pulling results from my database where collegeID = $collegeID.

Say I want to display a college on my site with the collegeID that equals 200.

This is displays correctly if there is only 1 college ID in the field...say collegeID = 200.

But if there are more college ID's in the field...say collegeID = 200, 210, 220, it will not display this because, technically it won't really equal.

How do you assign collegeID to $collegeID where that dont have to equal, but have that value within the field?

I hope you understand.

Thanks for the help in advance.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Variables

Post by AbraCadaver »

This is bad database design number one. But probably a quick way to do it if you have to is this:

Code: Select all

SELECT * FROM table_name WHERE collegeID = '$collegeID' OR collegeID LIKE '%$collegeID,%' OR collegeID LIKE '%, $collegeID%'
If you just used LIKE '%collegeID%' without the commas, then of course 2000 would match 200 and 200 would match 2, etc...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply