Click to See Complete Forum and Search --> : MySQL flush?


bdg1983
06-15-2001, 12:12 PM
$g = "g";
$result2 = mysql_query("SELECT COUNT(id) AS id FROM posts where id < 1000");
$number = mysql_result($result2,'0','id');
if(!mysql_query("CREATE TABLE $result2.$g (id int(11) NOT NULL auto_increment,name text NOT NULL,date text NOT NULL,comment text NOT NULL,KEY id (id)")) die(sql_error());


So basically what I want to happen is supposed to be named called #g.
The number coming from the $result2 Count query.

I know that the $result2 query works, I can echo the result. It just won't build the second table.

Do I have to flush the result or anything weird like that?

The table won't even build if I make it with the name "adas" or anything standardized such as that.

Thanks so much for the help.

Alex

klamath
06-16-2001, 01:56 AM
I won't comment on your actual code (although creating tables for every request (or every user or whatever) sounds like a very bad idea), but do you really want a 'WHERE' clause in that SELECT statement? Based on your previous thread (you said you wanted to count the number of rows in the table), a WHERE clause is dead wrong.

But if that's what you mean to do (and you didn't just cut-and-paste Sweede's code), then my apologies.

bdg1983
06-16-2001, 02:05 AM
Ok. Let me explain what I'm getting at here...
and please do comment on my code, i'm young, and i'll have to go by is a little book i bought.

so let me explain something here...

what is happening is..
someone posts something on the site.... just like an update.. what i want is a comment system.

So for every post, it creates a new table to hold the comments for THAT particular post.
I can't think of any other way to go about it? I really can't grasp the concept of relational databases yet so this is the only way i can think of doing it.

Thanks.

alex

Sweede
06-16-2001, 11:46 AM
Originally posted by maxl stylee:
<STRONG>
$g = "g";
$result2 = mysql_query("SELECT COUNT(id) AS id FROM posts where id &lt; 1000");
$number = mysql_result($result2,'0','id');
if(!mysql_query("CREATE TABLE $result2.$g (id int(11) NOT NULL auto_increment,name text NOT NULL,date text NOT NULL,comment text NOT NULL,KEY id (id)")) die(sql_error());


So basically what I want to happen is supposed to be named called #g.
The number coming from the $result2 Count query.

I know that the $result2 query works, I can echo the result. It just won't build the second table.

Do I have to flush the result or anything weird like that?

The table won't even build if I make it with the name "adas" or anything standardized such as that.

Thanks so much for the help.

Alex</STRONG>


no no no... that is allll wrong.

making a threaded comments system in mysql is hard becuase it lacks a couple features of SQL (foriegn keys and something else, dont remember). the way you are doing it could end up with thousands of 1 row tables, and thats a waste of MySQL resources.

what you need is 2 tables. one table to hold the entire body of the comment post and a unique ID, the other to hold the relation of comment threading, parents, etc.

each article that your commenting on has an ID, each parent thread has an ID, each comment has an ID, then another field to store the main parent (in the case of grandchilds) id

your second table will hold information such as the comment id, the comment title, text, the posters user id, the time of the article and the main parent thread ID (or null if it is a parent).

if the thread is a grandchild, it holds the parent ID of the originating thread.

bdg1983
06-17-2001, 05:35 PM
har har har.
figured it out.

What i ended up doing was each new update to the site would be stored in the table called "posts" .....
they would each have an auto_incremented id number. so the first post would be 1, second would 2 too, etc.

So next thing i did was create a comment table.
This table had an ID field as well as an article_id.

so whenever a comment was entered, the article_id would correspond to the update id of the page.

i don't know if i explained it well, but if you ever need help with something like this email me or contact me on aim.

AIM name: zad