473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Return bool from query

Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.

Feb 7 '06 #1
25 2208
frizzle wrote:
Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.


Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '06 #2

Jerry Stuckle wrote:
frizzle wrote:
Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.


Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


This would have me quering against an extra table. Would'nt it be
quicker to add an extra boolean field then?

Frizzle.

Feb 7 '06 #3
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.


Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

This would have me quering against an extra table. Would'nt it be
quicker to add an extra boolean field then?

Frizzle.


Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '06 #4
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.
Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

This would have me quering against an extra table. Would'nt it be
quicker to add an extra boolean field then?

Frizzle.


Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


I understand what you're saying. I think i'm underestimating the speed
of Joins (mySQL)
Not to be a nag, but would it still be faster to add an extra field to
the original table, 'fulltext_available' tinyint(1), which tells me to
look for it or not?

And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
in the query, it leaves the unmentioned fields unbothered, thus not
being influenced by their size/contents ?

Frizzle.

Feb 7 '06 #5
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
>Hi there,
>
>I have a mySQL system with a news publishing part in it:
>Admins can create new items with text in it, and they have an option to
>create 'fulltexts', so you'd get "read more ..." on the front page,
>click it and read the fulltext.
>
>Is there a possibility for mySQL (query) to check if 'fulltext' is
>empty or not, and only return true or false, so i don't have to put the
>whole fulltext into the mysql_fetch_array() to decide wether or not to
>show 'read_more', or should i create an extra boolean field in the DB
>saying fulltext y/n ?
>
>Greetings Frizzle.
>

Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
This would have me quering against an extra table. Would'nt it be
quicker to add an extra boolean field then?

Frizzle.


Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

I understand what you're saying. I think i'm underestimating the speed
of Joins (mySQL)
Not to be a nag, but would it still be faster to add an extra field to
the original table, 'fulltext_available' tinyint(1), which tells me to
look for it or not?

And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
in the query, it leaves the unmentioned fields unbothered, thus not
being influenced by their size/contents ?

Frizzle.


Yes and no. It depends on the implementation of the database.

In MySQL, everything in a table is kept in one file. So if you have
your full text in that table, a table scan will read everything in the
table and throw away the columns you don't want. If you have a lot of
text in relation to the rest of the row data, this can be significant
overhead. If the full text is in a separate table, it will only be read
when you request information from that table.

Additionally, is the absolute speed necessary? Are you talking dozens
(or even hundreds) of queries per second? I doubt it.

Keeping large amounts of data you only occasionally access is generally
a better way of doing things. Putting a T/F column in the table just
makes for another column you have to manage (and violates normalization
principles).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '06 #6
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

Jerry Stuckle wrote:
>frizzle wrote:
>
>
>>Hi there,
>>
>>I have a mySQL system with a news publishing part in it:
>>Admins can create new items with text in it, and they have an option to
>>create 'fulltexts', so you'd get "read more ..." on the front page,
>>click it and read the fulltext.
>>
>>Is there a possibility for mySQL (query) to check if 'fulltext' is
>>empty or not, and only return true or false, so i don't have to put the
>>whole fulltext into the mysql_fetch_array() to decide wether or not to
>>show 'read_more', or should i create an extra boolean field in the DB
>>saying fulltext y/n ?
>>
>>Greetings Frizzle.
>>
>
>Put it in a separate table with just the article's id and the text. If
>the id exists in the second table, there is more text.
>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>js*******@attglobal.net
>==================
This would have me quering against an extra table. Would'nt it be
quicker to add an extra boolean field then?

Frizzle.
Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

I understand what you're saying. I think i'm underestimating the speed
of Joins (mySQL)
Not to be a nag, but would it still be faster to add an extra field to
the original table, 'fulltext_available' tinyint(1), which tells me to
look for it or not?

And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
in the query, it leaves the unmentioned fields unbothered, thus not
being influenced by their size/contents ?

Frizzle.


Yes and no. It depends on the implementation of the database.

In MySQL, everything in a table is kept in one file. So if you have
your full text in that table, a table scan will read everything in the
table and throw away the columns you don't want. If you have a lot of
text in relation to the rest of the row data, this can be significant
overhead. If the full text is in a separate table, it will only be read
when you request information from that table.

Additionally, is the absolute speed necessary? Are you talking dozens
(or even hundreds) of queries per second? I doubt it.

Keeping large amounts of data you only occasionally access is generally
a better way of doing things. Putting a T/F column in the table just
makes for another column you have to manage (and violates normalization
principles).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


I don't know (yet) how much queries there will be, but i guess not
*that* much.
My lack of english causes me te seize your intention in the last part.
Do you mean i should put the fulltexts in another extra table?
I btw hardly doubt if it will be neccesary, since those texts won't be
that big either.
(For mySQL / PHP then ... )
Again, it's a news system, there won't be a whole version of The Da
Vinci Code behind 'read more'.

Frizzle.

Feb 7 '06 #7
SELECT IF( CHAR_LENGTH( `text_column` ) > 0, 1, 0 ) AS fulltext_exists
FROM table WHERE .....

will return fulltext_exists as 1 if `text_column` has a length greater
than 0. Otherwise returns 0
Want to get just the first 50 characters from the fulltext as the
summary or intro?

SELECT LEFT( `text_column`, 50 ) AS summary FROM table WHERE ....

Feb 8 '06 #8
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
>Jerry Stuckle wrote:
>
>
>
>>frizzle wrote:
>>
>>
>>
>>>Hi there,
>>>
>>>I have a mySQL system with a news publishing part in it:
>>>Admins can create new items with text in it, and they have an option to
>>>create 'fulltexts', so you'd get "read more ..." on the front page,
>>>click it and read the fulltext.
>>>
>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
>>>empty or not, and only return true or false, so i don't have to put the
>>>whole fulltext into the mysql_fetch_array() to decide wether or not to
>>>show 'read_more', or should i create an extra boolean field in the DB
>>>saying fulltext y/n ?
>>>
>>>Greetings Frizzle.
>>>
>>
>>Put it in a separate table with just the article's id and the text. If
>>the id exists in the second table, there is more text.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>js*******@attglobal.net
>>==================
>
>
>This would have me quering against an extra table. Would'nt it be
>quicker to add an extra boolean field then?
>
>Frizzle.
>

Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
I understand what you're saying. I think i'm underestimating the speed
of Joins (mySQL)
Not to be a nag, but would it still be faster to add an extra field to
the original table, 'fulltext_available' tinyint(1), which tells me to
look for it or not?

And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
in the query, it leaves the unmentioned fields unbothered, thus not
being influenced by their size/contents ?

Frizzle.


Yes and no. It depends on the implementation of the database.

In MySQL, everything in a table is kept in one file. So if you have
your full text in that table, a table scan will read everything in the
table and throw away the columns you don't want. If you have a lot of
text in relation to the rest of the row data, this can be significant
overhead. If the full text is in a separate table, it will only be read
when you request information from that table.

Additionally, is the absolute speed necessary? Are you talking dozens
(or even hundreds) of queries per second? I doubt it.

Keeping large amounts of data you only occasionally access is generally
a better way of doing things. Putting a T/F column in the table just
makes for another column you have to manage (and violates normalization
principles).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

I don't know (yet) how much queries there will be, but i guess not
*that* much.
My lack of english causes me te seize your intention in the last part.
Do you mean i should put the fulltexts in another extra table?
I btw hardly doubt if it will be neccesary, since those texts won't be
that big either.
(For mySQL / PHP then ... )
Again, it's a news system, there won't be a whole version of The Da
Vinci Code behind 'read more'.

Frizzle.


Yes, I would put the fulltext in a separate table. The join takes very
little overhead (since primary keys have an index associated).

Very often if you have large amounts of text (several hundred bytes
minimum) which you don't always need to access you can save processing
time by putting it in its own table.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 8 '06 #9
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
>Jerry Stuckle wrote:
>
>
>
>>frizzle wrote:
>>
>>
>>
>>>Hi there,
>>>
>>>I have a mySQL system with a news publishing part in it:
>>>Admins can create new items with text in it, and they have an option to
>>>create 'fulltexts', so you'd get "read more ..." on the front page,
>>>click it and read the fulltext.
>>>
>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
>>>empty or not, and only return true or false, so i don't have to put the
>>>whole fulltext into the mysql_fetch_array() to decide wether or not to
>>>show 'read_more', or should i create an extra boolean field in the DB
>>>saying fulltext y/n ?
>>>
>>>Greetings Frizzle.
>>>
>>
>>Put it in a separate table with just the article's id and the text. If
>>the id exists in the second table, there is more text.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>js*******@attglobal.net
>>==================
>
>
>This would have me quering against an extra table. Would'nt it be
>quicker to add an extra boolean field then?
>
>Frizzle.
>

Why? Joins are quick. Probably a lot faster than unnecessarily
processing empty text fields in the first table.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
I understand what you're saying. I think i'm underestimating the speed
of Joins (mySQL)
Not to be a nag, but would it still be faster to add an extra field to
the original table, 'fulltext_available' tinyint(1), which tells me to
look for it or not?

And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
in the query, it leaves the unmentioned fields unbothered, thus not
being influenced by their size/contents ?

Frizzle.


Yes and no. It depends on the implementation of the database.

In MySQL, everything in a table is kept in one file. So if you have
your full text in that table, a table scan will read everything in the
table and throw away the columns you don't want. If you have a lot of
text in relation to the rest of the row data, this can be significant
overhead. If the full text is in a separate table, it will only be read
when you request information from that table.

Additionally, is the absolute speed necessary? Are you talking dozens
(or even hundreds) of queries per second? I doubt it.

Keeping large amounts of data you only occasionally access is generally
a better way of doing things. Putting a T/F column in the table just
makes for another column you have to manage (and violates normalization
principles).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

I don't know (yet) how much queries there will be, but i guess not
*that* much.
My lack of english causes me te seize your intention in the last part.
Do you mean i should put the fulltexts in another extra table?
I btw hardly doubt if it will be neccesary, since those texts won't be
that big either.
(For mySQL / PHP then ... )
Again, it's a news system, there won't be a whole version of The Da
Vinci Code behind 'read more'.

Frizzle.

I should also add - something like

SELECT COUNT(id) FROM texttable WHERE id=1;

is quite quick. Chances are since id is a primary key, MySQL won't even
go to the table itself - it will just see if it exists in the index.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 8 '06 #10
On Tue, 07 Feb 2006 14:42:57 -0800, frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
> Jerry Stuckle wrote:
>
>>frizzle wrote:
>>
>>>Jerry Stuckle wrote:
>>>
>>>
>>>>frizzle wrote:
>>>>
>>>>
>>>>>Hi there,
>>>>>
>>>>>I have a mySQL system with a news publishing part in it:
>>>>>Admins can create new items with text in it, and they have an option to
>>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
>>>>>click it and read the fulltext.
>>>>>
>>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
>>>>>empty or not, and only return true or false, so i don't have to put the
>>>>>whole fulltext into the mysql_fetch_array() to decide wether or not to
>>>>>show 'read_more', or should i create an extra boolean field in the DB
>>>>>saying fulltext y/n ?
>>>>>
>>>>>Greetings Frizzle.
>>>>>
>>>>
>>>>Put it in a separate table with just the article's id and the text. If
>>>>the id exists in the second table, there is more text.
>>>>
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>js*******@attglobal.net
>>>>==================
>>>
>>>
>>>This would have me quering against an extra table. Would'nt it be
>>>quicker to add an extra boolean field then?
>>>
>>>Frizzle.
>>>
>>
>>Why? Joins are quick. Probably a lot faster than unnecessarily
>>processing empty text fields in the first table.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>js*******@attglobal.net
>>==================
>
>
> I understand what you're saying. I think i'm underestimating the speed
> of Joins (mySQL)
> Not to be a nag, but would it still be faster to add an extra field to
> the original table, 'fulltext_available' tinyint(1), which tells me to
> look for it or not?
>
> And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
> in the query, it leaves the unmentioned fields unbothered, thus not
> being influenced by their size/contents ?
>
> Frizzle.
>


Yes and no. It depends on the implementation of the database.

In MySQL, everything in a table is kept in one file. So if you have
your full text in that table, a table scan will read everything in the
table and throw away the columns you don't want. If you have a lot of
text in relation to the rest of the row data, this can be significant
overhead. If the full text is in a separate table, it will only be read
when you request information from that table.

Additionally, is the absolute speed necessary? Are you talking dozens
(or even hundreds) of queries per second? I doubt it.

Keeping large amounts of data you only occasionally access is generally
a better way of doing things. Putting a T/F column in the table just
makes for another column you have to manage (and violates normalization
principles).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


I don't know (yet) how much queries there will be, but i guess not
*that* much.
My lack of english causes me te seize your intention in the last part.
Do you mean i should put the fulltexts in another extra table?
I btw hardly doubt if it will be neccesary, since those texts won't be
that big either.
(For mySQL / PHP then ... )
Again, it's a news system, there won't be a whole version of The Da
Vinci Code behind 'read more'.

Frizzle.


Always normalise your data model first. Then, if it isn't fast enough, add
in shortcuts. Databases ( even mysql (: ) are really powerful - but that
also means that you can really screw everything up if you don't stand back
first, and get a proper idea of what you're trying to do first.

There must be a copy of C.J.Date on the internet somewhere - it must be 30
years old by now.

Steve

Feb 8 '06 #11
Hi

Try to do like when admin enters article he should enter <SPLIT> tag
from where you want break with article so when you read from db try to
split from split tag.

Regards,
Jatin

Feb 8 '06 #12
pjSoni wrote:
Hi

Try to do like when admin enters article he should enter <SPLIT> tag
from where you want break with article so when you read from db try to
split from split tag.

Regards,
Jatin


Thanks all for the replies.
I understand what bobzimuta and pjSoni are saying with the intro thing,
but i need two different fields, so the intro in the fulltext can
differ from just te intro.

I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
id=1;
But the id of the fulltext would have to match the exact id of the
record with intro and other info?
Would it matter if i added LIMIT 1 to it, so the DB won't go on?

How careful should i be asigning extra indexes? I read somewhere, that
if i asign indexes to fields that aren't going te be updated a lot,
it's not bad, otherwise it would take a lot of time ...

And now i also have second thoughts about my field in the topic records
with the number of replies.
It goes against normalization, but i thought it would save a lot of
calculating time ...

Frizzle.

Feb 8 '06 #13
frizzle wrote:
pjSoni wrote:
Hi

Try to do like when admin enters article he should enter <SPLIT> tag
from where you want break with article so when you read from db try to
split from split tag.

Regards,
Jatin

Thanks all for the replies.
I understand what bobzimuta and pjSoni are saying with the intro thing,
but i need two different fields, so the intro in the fulltext can
differ from just te intro.

I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
id=1;
But the id of the fulltext would have to match the exact id of the
record with intro and other info?
Would it matter if i added LIMIT 1 to it, so the DB won't go on?

How careful should i be asigning extra indexes? I read somewhere, that
if i asign indexes to fields that aren't going te be updated a lot,
it's not bad, otherwise it would take a lot of time ...

And now i also have second thoughts about my field in the topic records
with the number of replies.
It goes against normalization, but i thought it would save a lot of
calculating time ...

Frizzle.


Yes, it has to match the key of the other table. It would also the
primary key of that entry. Being a primary key, it would be unique.

Also, if your use INNODB tables you can make it a foreign key
referencing the other table.

You shouldn't need to add LIMIT 1 to the query because you have a unique
index on the field. MySQL should be able to fetch everything it needs
from the index (which, unlike the table, is in order).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 8 '06 #14
Jerry Stuckle wrote:
frizzle wrote:
pjSoni wrote:
Hi

Try to do like when admin enters article he should enter <SPLIT> tag
from where you want break with article so when you read from db try to
split from split tag.

Regards,
Jatin

Thanks all for the replies.
I understand what bobzimuta and pjSoni are saying with the intro thing,
but i need two different fields, so the intro in the fulltext can
differ from just te intro.

I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
id=1;
But the id of the fulltext would have to match the exact id of the
record with intro and other info?
Would it matter if i added LIMIT 1 to it, so the DB won't go on?

How careful should i be asigning extra indexes? I read somewhere, that
if i asign indexes to fields that aren't going te be updated a lot,
it's not bad, otherwise it would take a lot of time ...

And now i also have second thoughts about my field in the topic records
with the number of replies.
It goes against normalization, but i thought it would save a lot of
calculating time ...

Frizzle.


Yes, it has to match the key of the other table. It would also the
primary key of that entry. Being a primary key, it would be unique.

Also, if your use INNODB tables you can make it a foreign key
referencing the other table.

You shouldn't need to add LIMIT 1 to the query because you have a unique
index on the field. MySQL should be able to fetch everything it needs
from the index (which, unlike the table, is in order).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Why is this unlike the table in order? Since both are probably created
in the same instance. The Fulltext indexes have a bigger chance *not*
to be in order, since they could be added later ...

And what exactly do you mean with a foreign key ?

Frizzle.

(Thanks a lot for your effort to help me!)

Feb 8 '06 #15
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
pjSoni wrote:
Hi

Try to do like when admin enters article he should enter <SPLIT> tag

from where you want break with article so when you read from db try to

split from split tag.

Regards,
Jatin
Thanks all for the replies.
I understand what bobzimuta and pjSoni are saying with the intro thing,
but i need two different fields, so the intro in the fulltext can
differ from just te intro.

I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
id=1;
But the id of the fulltext would have to match the exact id of the
record with intro and other info?
Would it matter if i added LIMIT 1 to it, so the DB won't go on?

How careful should i be asigning extra indexes? I read somewhere, that
if i asign indexes to fields that aren't going te be updated a lot,
it's not bad, otherwise it would take a lot of time ...

And now i also have second thoughts about my field in the topic records
with the number of replies.
It goes against normalization, but i thought it would save a lot of
calculating time ...

Frizzle.


Yes, it has to match the key of the other table. It would also the
primary key of that entry. Being a primary key, it would be unique.

Also, if your use INNODB tables you can make it a foreign key
referencing the other table.

You shouldn't need to add LIMIT 1 to the query because you have a unique
index on the field. MySQL should be able to fetch everything it needs
from the index (which, unlike the table, is in order).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Why is this unlike the table in order? Since both are probably created
in the same instance. The Fulltext indexes have a bigger chance *not*
to be in order, since they could be added later ...

And what exactly do you mean with a foreign key ?

Frizzle.

(Thanks a lot for your effort to help me!)


First of all, check out foreign keys in the MySQL documentation:
http://dev.mysql.com/doc/refman/5.0/...eign-keys.html

No, the table wouldn't necessarily be in order (your original one
wouldn't either - SQL is by default unordered). But the index built on
the primary key is always ordered (so the engine can do a quick binary
search of the index). Therefore, MySQL can determine whether a record
exists or not by searching the index and doesn't need to load the file
itself in the query I showed you.

But the advantage is you wouldn't have to read the full text data every
time you need to access the summary information. You only get the full
text when you request it.

Remember - MySQL reads the entire row, even if you only ask for part of
the data, because everything's in one file.

Also, if you have a request which requires a full table scan, having the
full text in a separate table improves the table scan (unless, of
course, you're searching the full text data).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 8 '06 #16
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

pjSoni wrote:
>Hi
>
>Try to do like when admin enters article he should enter <SPLIT> tag

>from where you want break with article so when you read from db try to

>split from split tag.
>
>Regards,
>Jatin
Thanks all for the replies.
I understand what bobzimuta and pjSoni are saying with the intro thing,
but i need two different fields, so the intro in the fulltext can
differ from just te intro.

I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
id=1;
But the id of the fulltext would have to match the exact id of the
record with intro and other info?
Would it matter if i added LIMIT 1 to it, so the DB won't go on?

How careful should i be asigning extra indexes? I read somewhere, that
if i asign indexes to fields that aren't going te be updated a lot,
it's not bad, otherwise it would take a lot of time ...

And now i also have second thoughts about my field in the topic records
with the number of replies.
It goes against normalization, but i thought it would save a lot of
calculating time ...

Frizzle.
Yes, it has to match the key of the other table. It would also the
primary key of that entry. Being a primary key, it would be unique.

Also, if your use INNODB tables you can make it a foreign key
referencing the other table.

You shouldn't need to add LIMIT 1 to the query because you have a unique
index on the field. MySQL should be able to fetch everything it needs
from the index (which, unlike the table, is in order).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Why is this unlike the table in order? Since both are probably created
in the same instance. The Fulltext indexes have a bigger chance *not*
to be in order, since they could be added later ...

And what exactly do you mean with a foreign key ?

Frizzle.

(Thanks a lot for your effort to help me!)


First of all, check out foreign keys in the MySQL documentation:
http://dev.mysql.com/doc/refman/5.0/...eign-keys.html

No, the table wouldn't necessarily be in order (your original one
wouldn't either - SQL is by default unordered). But the index built on
the primary key is always ordered (so the engine can do a quick binary
search of the index). Therefore, MySQL can determine whether a record
exists or not by searching the index and doesn't need to load the file
itself in the query I showed you.

But the advantage is you wouldn't have to read the full text data every
time you need to access the summary information. You only get the full
text when you request it.

Remember - MySQL reads the entire row, even if you only ask for part of
the data, because everything's in one file.

Also, if you have a request which requires a full table scan, having the
full text in a separate table improves the table scan (unless, of
course, you're searching the full text data).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Ok, thanks a lot, you convinced me on this. This of course is quite
important for more other things to achieve. I will for instance not
save the number of comments as an int() in the topics table, but will
perform a count!

Frizzle.

Feb 8 '06 #17
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.

Feb 8 '06 #18
frizzle wrote:
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.


If you're going to use foreign keys, you need to change to innodb. It's
not hard - just call ALTER TABLE on each one.

Or use PHPMyAdmin - a great tool if you're not familiar with it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 8 '06 #19
Jerry Stuckle wrote:
frizzle wrote:
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.


If you're going to use foreign keys, you need to change to innodb. It's
not hard - just call ALTER TABLE on each one.

Or use PHPMyAdmin - a great tool if you're not familiar with it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.

Feb 8 '06 #20
frizzle wrote:

I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.


After you select the table, go to the Operations tab. One of the
entries is "Table type". Change this to INNODB.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 9 '06 #21

Jerry Stuckle wrote:
frizzle wrote:

I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.


After you select the table, go to the Operations tab. One of the
entries is "Table type". Change this to INNODB.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


The only options i get there are:
- MyISAM (current)
- Heap
- ISAM
- Merge

So i guess it's not possible (yet). But i have things up and running
correct now, or do you think it's that important to go use foreign
keys?

Frizle.

Feb 9 '06 #22
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.


After you select the table, go to the Operations tab. One of the
entries is "Table type". Change this to INNODB.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

The only options i get there are:
- MyISAM (current)
- Heap
- ISAM
- Merge

So i guess it's not possible (yet). But i have things up and running
correct now, or do you think it's that important to go use foreign
keys?

Frizle.


OK, you're hosting company may have an older copy of MySQL, may not have
installed INNODB support or whatever.

INNODB will allow you to ensure the integrity of your foreign keys. For
instance, if you delete a row in your main table, it can automatically
delete the matching row(s) in your full text table (other options are
available also). Without it, you can't guarantee the integrity of the
database.

So it all depends on how important it is to you. You'll probably be ok
- this isn't like a bank, for instance, where you don't want to delete a
person's record while they still have open accounts. If you have some
extra rows in your full text table it might slow the server down a
couple of milliseconds is all.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 9 '06 #23

Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.
After you select the table, go to the Operations tab. One of the
entries is "Table type". Change this to INNODB.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

The only options i get there are:
- MyISAM (current)
- Heap
- ISAM
- Merge

So i guess it's not possible (yet). But i have things up and running
correct now, or do you think it's that important to go use foreign
keys?

Frizle.


OK, you're hosting company may have an older copy of MySQL, may not have
installed INNODB support or whatever.

INNODB will allow you to ensure the integrity of your foreign keys. For
instance, if you delete a row in your main table, it can automatically
delete the matching row(s) in your full text table (other options are
available also). Without it, you can't guarantee the integrity of the
database.

So it all depends on how important it is to you. You'll probably be ok
- this isn't like a bank, for instance, where you don't want to delete a
person's record while they still have open accounts. If you have some
extra rows in your full text table it might slow the server down a
couple of milliseconds is all.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Ok, thanks a lot for all the effort. No more further questions ...
for now ;)

Again, thanks a lot for taking so much time!

Frizzle.

Feb 9 '06 #24
FULLTEXT() is a MySQL search function. so you might want to name your
column something else.

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:Nf********************@comcast.com...
frizzle wrote:
Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.


Put it in a separate table with just the article's id and the text. If
the id exists in the second table, there is more text.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 12 '06 #25

"frizzle" <ph********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi there,

I have a mySQL system with a news publishing part in it:
Admins can create new items with text in it, and they have an option to
create 'fulltexts', so you'd get "read more ..." on the front page,
click it and read the fulltext.

Is there a possibility for mySQL (query) to check if 'fulltext' is
empty or not, and only return true or false, so i don't have to put the
whole fulltext into the mysql_fetch_array() to decide wether or not to
show 'read_more', or should i create an extra boolean field in the DB
saying fulltext y/n ?

Greetings Frizzle.


if you create the column with type TEXT or LONGTEXT (or whatever) with
DEFAULT NULL, you can use MySQL's ISNULL() function to detect if it's empty
or not.
for instance,
SELECT ISNULL(fulltext1) FROM tablename ORDER BY itemtimestamp DESC

you can in your code with $row=mysql_fetch_array() see if $row['ISNULL']
(not sure if it should be lower case here) has an appropriate value. echo
it to find out.

Feb 12 '06 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
2
by: Justin Dutoit | last post by:
Hey. I have a function with a boolean return value, called IsInWarehouse, which checks if a product is available in a warehouse, or not. But I need security in the function too, so I have public...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
3
by: Daves | last post by:
a get { ... } for public property SelectedValue returns DateTime type to be used as a parameter in a Sql update query but I'd like it to return "empty" if no date has been selected... I cannot use...
40
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
2
by: fhasdkfhadlksfjhalsdkfh12 | last post by:
I've been working on a decryption program for another encryption program I made. It isn't finished, and when I try to compile it to test it, it gives me the error "expected unqualified-id before...
13
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about...
6
by: exander77 | last post by:
I am quite new to c++, about half of a year. I juct wonder, why such code is not possible: int chlen(char * ar) { for(int i=0;ar||return i;i++); } In my opinion, it would be much "cuter"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.