Archive > AO official modules

Modified News.php

<< < (2/5) > >>

Akarah:
the news i had already came with

--- Code: ---  $db -> query("CREATE TABLE IF NOT EXISTS news
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
              name VARCHAR(30),
              news TEXT,
        time INT NOT NULL)");

--- End code ---

so using your update command fails because time already exists..

i think all that is needed in my case was


--- Code: ---mysql> ALTER TABLE news, ADD COLUMN type INT DEFAULT '2' NULL  after id;

--- End code ---

it worked at least :)

Akarah:
now that i think about it some more, setting the new column to type 1 might be more appropriate, since there can only be one headline... yea? :)

so either do the above line then:


--- Code: ---mysql> UPDATE news SET type = 1 WHERE type = 2;

--- End code ---

or just set the default to 1, assuming that doesn't break the script (i haven't looked closely)

Xenixa:
Well what I was doing to make sure only 1 Headline entry exists is to have it remove any Type 2 entry before Setting the new one.

I.E. in the function set_headline
--- Code: ---$this -> bot -> db -> query("DELETE FROM news WHERE type = '2'");
$this -> bot -> db -> query("INSERT INTO news (type, time, name, news) VALUES ('2' ," . time() .
  ", '" . $name . "', '" . addslashes($msg) . "')");
--- End code ---

Seems to work pretty well as I havn't seen more than 1 Headline appear after changing it a couple times to test it.

Akarah:
i was just noting that when adding the new column, if you had previous news entries (i had about 10 or so) they would all get set to type 2, thus get deleted apparently ;p

Xenixa:
OOOh ok I see what your saying, ya set default to 1, guess I should have updated that ALTER TABLE a bit more before stuffing it there. Originally I was gunna set Headlines to 1 and News to 2 but some how ended up going the other way around.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version