/    Sign up×
Community /Pin to ProfileBookmark

am i trin to do the impossible?

Ok, i’ve picked away on this for a while and can’t figure it out. i have a database setup as following:
name | description | per
varchar(150) | text | varchar(255)
(example of data:
tester | This is a test item | 1,3,5,6)

lets say i have a page that i want to only display the test item once, so lets say when the user selects 5. how would i go about and display it only that once? Now i can’t use

[code=php]WHERE `per` = ‘%6%’[/code]

because what if the options in the per list are 4,6,12,16….the wildcard(%) can’t seperate the differance between 6 and 16, thus it will get displayed twice, because it sees 6 twice. Any suggestions?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 10.2005 — Well, the database solution would be to put "per" into a separate table, associated to the other table by the "name" field:

[b][u]people[/u][/b]

name

description

[b][u]per[/u][/b]

name

per

For your example data, you would have one row in table "people" for "tester", then 4 rows in table "per":
<i>
</i>"tester" | 1
"tester" | 3
"tester" | 5
"tester" | 6

Your query would then be:
<i>
</i>SELECT people.name, people.description, per.per FROM people, per
WHERE people.name = per.name AND per.per = 6;

Now you acutally have a "relational database". ?
Copy linkTweet thisAlerts:
@GenixdeaeauthorMay 10.2005 — my only concern with that is that the database will get huge, because when the item is inserted the user can also insert it into multiple dates....so lets say they want it to insert into 5 differant days and 3 differant periods....there's 15 records right there and there's atleast 80 users...that's my concern with doing it like that.
Copy linkTweet thisAlerts:
@NogDogMay 10.2005 — I don't think that it's really a concern. I've worked on an application that had literally hundreds of tables, many with thousands of rows. Admittedly, it was in Oracle, but I really don't think you'll be swamping MySQL just by breaking data out into logical tables instead of trying to cram it all into one. That's why relational databases were created, so that you could group data into logical groupings and associate across those groupings via some sort of relationship.
Copy linkTweet thisAlerts:
@NogDogMay 10.2005 — PS: Since I don't really understand the functionality you are trying to implement, it's possible I'm leading you down the wrong path, or at least not the exact one you need. If you don't mind sharing it with us, I might be able to propose a better solution that fits your exact need.
Copy linkTweet thisAlerts:
@GenixdeaeauthorMay 10.2005 — i dont mind sharing at all, for warning this'll b a bit long.

im a student at a high school, and i've made a calendar script for the teachers. We have 8 periods, total. 4 periods in each day. If you want to take a look at it, you can go [URL=http://sprague.wvi.com/teacher_page_wiz_final/calendarphp/index.php?fname=De&lname=Bugger&per=1]here[/URL]. you can login using:

firstname: De

lastname: Bugger

password: sockie

Now the problem lies when adding the periods to add an event. If you go to add, you can select upto 6 dates to insert the event into, put a subject and a desctiption. then down at the bottom is the periods to insert into. As long as there are only 0-9 amount of periods then what i have currently[code=php]select * from table where per like '%". $_GET["per"] ."%' //this is a condensed version[/code] worsk fine. but if you toss any other periods like 10 or 11 then the script doesnt work. reason being is that the LIKE statement recognizes the 1 in 10 and 11 as one, not as 10 or 11, so when you view the events for 10 and 11 it shows 1 also, same goes when viewing 1, it shows 10 and 11, because it sees the 1 in there.

that's the just of it. If you need any code snippets/pages, database layouts, more detail. let me know i'm more then willing to post, i really want/need to get this fixed.

Edit:: forgot to mention that the periods are seperated by commas. in the database
Copy linkTweet thisAlerts:
@ScleppelMay 10.2005 — When you put the numbers into the database you could put a character at the start and end, like (1) or (11) and then when you search for a number add the charcters and it'll only find the exact pattern, because (11) doesn't contain (1). If that makes sense, although there's almost certainly an easier way.

Edit: Just read your edit, you could use the comma's as the characters, you'd just need to have one at the start and end.
×

Success!

Help @Genixdeae spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...