Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to setup a database table?

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 56 total)
  • Author
    Posts
  • #45984
    chrisburton
    Participant

    URL: http://chrisburton.me/recently

    First, I’m trying to store the `url` and `title` into a database from my “Read” section. I’ve created a database, database user and set a table with the name `read` with 2 columns (one for url and the other for link). This is where I’m stuck. I’m not exactly sure what I should put inside some of the options shown below.

    Or should my PHP be setting this information from the array?

    View larger image.

    Also, I hope I’m not exposing any sensitive information here. Please let me know if I am.

    #141067
    chrisburton
    Participant

    Damn it. I thought it would be easier to understand than all of what you just said.

    #141070
    chrisburton
    Participant

    @CrocoDillion I have many questions.

    But first, in PHPMyAdmin under localhost->db-name, why is my database collation set at `latin1_swedish_ci`? I should probably change that, yes?

    #141071
    Alen
    Participant

    you should have:

    id – tinyint(8), primary index, auto increment

    url – varchar(250)

    title – varchar(250)

    #141073
    Alen
    Participant

    How is this table related to other tables? do you have users creating url’s and title’s? you might want to add user_id as well so you can relate(join) two tables if you ever need to display more complex data. `user_id` would be the id in the users table for example.

    #140926
    chrisburton
    Participant

    @AlenAbdula

    I’m not sure why I should set an ID? What’s supposed to go there?

    No, the only “user” would be me. I add what I read to my readability account and pull that data from the RSS feed.

    I’m just trying to store that data in case I decide to do something with it later. Something like show what all I’ve read throughout the year. As for now, I’m just going to be outputting my latest article that I’ve read.

    #140927
    Alen
    Participant

    ID is your table index, every table should have it.

    This number keeps track how many different unique entries you have. It starts at 1 and with every entry it auto increments. In the example you have how would you display ascending or descending data? You would only be able to sort it by url or title.

    #141075
    Alen
    Participant

    In your use case you would only have one user id = 1 and the table read would have all user_id fields with value 1. The id’s once you set them up they auto increment, so there’s no need to pass data to it. You would only pass user_id value of 1, then title and url.

    #141076
    chrisburton
    Participant

    @AlenAdbula What is confusing me is the way you were explaining it. The image helped a lot.

    I won’t be needing a `user_id` since there will only be one user. Do I still need to set one for myself? Seems kind of unnecessary.

    #141077
    Alen
    Participant

    I would, so if you wanted to add extra info about the user down the road that data will be abstracted. Since you are the only user just pass 1 to user_id. or if you want to keep it real simple just add id (index, auto increment) to the read table.

    So

    CREATE TABLE IF NOT EXISTS `read` (
    `id` tinyint(8) NOT NULL AUTO_INCREMENT,
    `title` varchar(250) NOT NULL,
    `url` varchar(250) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

    #141078
    pixelgrid
    Participant

    your table should have a primary auto incrementing integer id two varchar for url and title. just set a length for those and you shouldnt have any issues.

    no need for user id if you are the only user

    #141080
    chrisburton
    Participant

    Now I’m confused again. Should I be using `latin1_swedish_ci` or `utf8_unicode_ci`?

    #141081
    chrisburton
    Participant

    @pixelgrid @AlenAbdula So my table should look something like this, correct?

    http://cloud.chrisburton.me/image/1t0L0e3W1412

    #141083
    chrisburton
    Participant

    @CrocoDillon Just read that! Thanks for the info.

    I really appreciate all the information everyone has given me. Thanks for helping out and teaching me a few things.

    #141085
    Alen
    Participant

    Yeah ignore that part I quickly generated it here on my machine. Go with whatever you need.

Viewing 15 posts - 1 through 15 (of 56 total)
  • The forum ‘Other’ is closed to new topics and replies.