SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rules for naming fields

    Ok, I ran into some trouble at work today. I have a table with multiple fields for the same topic. For example, users can enter three URLs and they get inserted into three different fields url1, url2, url3. It did allow me to rename the fields to url[1], url[2], url[3] so that I can use them in a loop. However, I can't get the PHP to read the fields when they're named with brackets. I can read them in PuTTY if I enclose them in double quotes, but phpMyAdmin gives me errors that point to the brackets (I've tried both single and double quotes, I don't know if that matters). Is there a certain way I need to code it for it to work?

    Thanks

    -C

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try using aliases on the query.

    SELECT url[1] as firstUrl FROM table;

    However, those are some looney column names, if you ask me. I am thinking your rationale for using brackets in column names is spurious: just a guess. :-)

    Or perhaps I've misunderstood your problem entirely.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should also redesign your table.
    create one column to hold the actual URL and a second column to state whether it is URL1, 2, or 3.

  4. #4
    SitePoint Addict pointbeing's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by daveman
    You should also redesign your table.
    create one column to hold the actual URL and a second column to state whether it is URL1, 2, or 3.

    or even better, learn a little bit about normalisation:

    http://www.oreilly.com/catalog/javad...apter/ch02.pdf

    The bit about 1NF is most relevant to this one.

    But if you insist, why not just get rid of the [] and call them url01, url02 or something, at least that would work.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by daveman
    You should also redesign your table.
    create one column to hold the actual URL and a second column to state whether it is URL1, 2, or 3.
    That's a good idea, but I don't want three rows for every release (I'm cataloging news releases). I could join multiple tables, but I don't think that would be any more efficient, especially since I have four or five fields that each have 3 options.

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Michigan
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pointbeing
    or even better, learn a little bit about normalisation:

    http://www.oreilly.com/catalog/javad...apter/ch02.pdf

    The bit about 1NF is most relevant to this one.

    But if you insist, why not just get rid of the [] and call them url01, url02 or something, at least that would work.
    I'll look into the normal stuff, thanks.

    Can you still run through loops with brackets? Will it work to use something like "url" . $i instead of url[$i]?


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
  •