473,563 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_arr ay() 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 2228
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_arr ay() 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*******@attgl obal.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_arr ay() 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*******@attgl obal.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_arr ay() 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*******@att global.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*******@attgl obal.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_arr ay() 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*******@att global.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*******@attgl obal.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_avail able' 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_arr ay() to decide wether or not to
>show 'read_more', or should i create an extra boolean field in the DB
>saying fulltext y/n ?
>
>Greeting s 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*******@a ttglobal.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*******@att global.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_avail able' 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*******@attgl obal.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_arr ay() to decide wether or not to
>>show 'read_more', or should i create an extra boolean field in the DB
>>saying fulltext y/n ?
>>
>>Greeting s 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*******@a ttglobal.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*******@att global.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_avail able' 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*******@attgl obal.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_arr ay() to decide wether or not to
>>>show 'read_more', or should i create an extra boolean field in the DB
>>>saying fulltext y/n ?
>>>
>>>Greeting s 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
processin g empty text fields in the first table.

--
=========== =======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@a ttglobal.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_avail able' 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.

Additionall y, 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*******@att global.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*******@attgl obal.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_arr ay() to decide wether or not to
>>>show 'read_more', or should i create an extra boolean field in the DB
>>>saying fulltext y/n ?
>>>
>>>Greeting s 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
processin g empty text fields in the first table.

--
=========== =======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@a ttglobal.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_avail able' 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.

Additionall y, 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*******@att global.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*******@attgl obal.net
=============== ===
Feb 8 '06 #10

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

Similar topics

30
2140
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 would be more orthogonal if a method could only have one return statement. --
2
5344
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 bool IsInWarehouse(string productName) { if (Login(username, password)) { // query db about available product } else {
10
19121
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 ray, int count)" Now I'm having problems with C++ "return(false)" being True in C#. Here is the C# code. ========================= using...
5
2062
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 "in/out" or "out" parameters ? Or is it simply that events are just notifications and are not interested in any values which event handlers might be able...
3
1905
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 return null; because "Cannot convert null to 'System.DateTime' because it is a value type" How can this be done?
40
3108
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 fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case...
2
27038
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 'return'" right at the line where "return 0;" is. I am using Xcode for mac os, which is the same as g++ 4.0 for Unix/Linux. I can't seem to figure this...
13
2892
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 it and doubt it. Anybody heard of it? What would be the advantage? Regards, Marc Example:
6
1824
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" than this: int chlen(char * ar) {
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.