SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving wrong data from MySQL

    So I am thinking of things to add to my news script, and I look at the forums and see the post icons. "Hey, maybe I can add post icons next each title!" OK, so I go for it.

    I add an extra column in my 'news' table called 'iconid'. I make it a 'tinyint' and set the default value to '0'. Now, all the news posts have a value of 'iconid=0'. I go into phpMyAdmin to change some of these values so I can see if it is working.

    In my sql select I use '*' to select everything, so I know 'iconid' is getting selected. Then, to make sure I am getting the value for each news item I echo out the variable $row['iconid'].

    What happens? EVERY single news item decides to have a iconid value of 0! Maybe I did something wrong setting up the new column for the iconid? I delete it and start it over, settng the default to 1 for no real reason. I change a few so that not every news item has a value of 1. What happens this time? EVERY single news item decides to have a value of 1 now!

    I don't get it, it seems whatever default value I initially start with is what every single value turns out to be regardless of whether or not I change it.

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the query and the table layout for us to see?

  3. #3
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    #
    # Table structure for table `ashnews_news`
    #

    CREATE TABLE ashnews_news (
      
    id int(10NOT NULL auto_increment,
      
    iconid tinyint(2NOT NULL default '0',
      
    postedby int(10NOT NULL default '1',
      
    title varchar(50NOT NULL default '',
      
    text text NOT NULL,
      
    date datetime NOT NULL default '0000-00-00 00:00:00',
      
    commentcount int(10NOT NULL default '0',
      
    allowcomment tinyint(1NOT NULL default '1',
      
    attach tinyint(1NOT NULL default '0',
      
    attachname varchar(100NOT NULL default '',
      
    PRIMARY KEY  (id)
    TYPE=MyISAM;


    $sql "SELECT *, DATE_FORMAT(date, '$newsdateformat') AS formatted_date FROM ashnews_news "

  4. #4
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the test page: http://demo.ashwebstudio.com/ashnews.php

    I have changed the iconid id value for each item in the database (There are only 9 so far). They each output 0, which is the default.

  5. #5
    SitePoint Guru
    Join Date
    Dec 2001
    Location
    San Diego, CA
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how this fixed it, but I changed how I was doing the bbcode (which had NO relation to the iconid) and now it works. Weird.


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
  •