SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    new mysql table setup *Solved*

    I am creating a new table containing information about different weekling summer camps. I am having trouble developing the structure.

    All is good till i get to the ages or in this case, the school grades of the kids that will be allowed to go to each camp. it will be somthing similar to this when displayed:

    name: camp 1
    grades: 9-12

    I thought initially about seting grades as a varchar, and inputing in "9-12" however, when performing a search over this field, 10th and 11th grade query's would not return any successful results. So i thought maybe an integer, but i can't have a value of "9, 10, 11, 12"

    my last thought was a varchar that would convert the input grades into this format: "9, 10, 11, 12" this would work, howver, how would i go about displaying...in php:

    grades: 9-12

    from this data

    varchar grades: "9,10,11,12"

    any help would be great thanks.
    Last edited by Raskolnikov; Apr 1, 2005 at 08:21.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Ireland
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use the explode function to load the values into an array ie.
    PHP Code:
    $gradesArray explode(", "$grades);
    print_r($gradesArray); 
    get the first and last values in the array and place a - in between them

    this should probably be posted in the php forum

  3. #3
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was more curious as to the column typ for that variable. in this case if i go with this kind of display i should use a varchar of some sort. When loading the data into the db it should go in as an array or would it be just as easy to implode them all to somthing like: "9,10,11,12"?

  4. #4
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THat seemed to work.

    I created a carchar, took the info from checkboxes, and imploded them into a string, then on the other end exploded them to an array for display.

    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •