Hello
I have a TINYINT(1) field, group1, in a mysql data base and the value
is 1 but php
if ($row['group1'] == "1") {
does not work.
What should I be writing here?
Cheers
Geoff
PS echoing the group1 value does give 1. 21 3694
On Aug 12, 9:16*am, Geoff Cox <g...@freeuk.notcomwrote:
the value is 1 but php
if ($row['group1'] == "1") {
does not work.
This should work. However, if $row['group1'] contains "1 " (one space)
it does not work. You can use vardump($row['group1']) to determine the
precise contents and type of the variable.
What also could be the case is that the if works, but you think it is
not because something else is broken.
Geoff Cox wrote:
Hello
I have a TINYINT(1) field, group1, in a mysql data base and the value
is 1 but php
if ($row['group1'] == "1") {
does not work.
What should I be writing here?
Cheers
Geoff
PS echoing the group1 value does give 1.
Lose the double quotes round 1 ?
-- Jim.
On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sj******@gmail.com>
wrote:
>On Aug 12, 9:16*am, Geoff Cox <g...@freeuk.notcomwrote:
>the value is 1 but php if ($row['group1'] == "1") { does not work.
This should work. However, if $row['group1'] contains "1 " (one space) it does not work. You can use vardump($row['group1']) to determine the precise contents and type of the variable.
This is odd! I am using var_dump and code below which first gives
group1 as 1 and then var_dump as NULL and then no.
any idea what is going on?!
Cheers
Geoff
while ($row = mysql_fetch_array($result)) {
echo $row['user_name'] . " "
.. $row['group1'] ." "
.. $row['group2'] . " "
.. $row['group3'] . " "
.. $row['group4'] . " "
.. $row['group5']
.."<br>";
}
echo var_dump($row['group1']);
if ($row['group1'] == 1) {
echo "yes" . "<br>";
} else {
echo "no" . "<br>";
}
> What also could be the case is that the if works, but you think it is not because something else is broken.
On Tue, 12 Aug 2008 08:41:48 +0100, Jim <no*@this.addresswrote:
>Geoff Cox wrote:
>Hello
I have a TINYINT(1) field, group1, in a mysql data base and the value is 1 but php
if ($row['group1'] == "1") {
does not work.
What should I be writing here?
Cheers
Geoff
PS echoing the group1 value does give 1.
Lose the double quotes round 1 ?
-- Jim.
I've tried that Jim - please have a look at my reply to Sjoerd and see
if you have any thoughts!
Cheers
Geoff
Geoff Cox wrote:
On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sj******@gmail.com>
wrote:
>>On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.notcomwrote:
>>the value is 1 but php if ($row['group1'] == "1") { does not work.
This should work. However, if $row['group1'] contains "1 " (one space) it does not work. You can use vardump($row['group1']) to determine the precise contents and type of the variable.
This is odd! I am using var_dump and code below which first gives
group1 as 1 and then var_dump as NULL and then no.
Please post the output from
var_dump($row)
On Tue, 12 Aug 2008 10:00:18 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>Geoff Cox wrote:
>On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sj******@gmail.com> wrote:
>>>On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.notcomwrote: the value is 1 but php if ($row['group1'] == "1") { does not work.
This should work. However, if $row['group1'] contains "1 " (one space) it does not work. You can use vardump($row['group1']) to determine the precise contents and type of the variable.
This is odd! I am using var_dump and code below which first gives group1 as 1 and then var_dump as NULL and then no.
Please post the output from var_dump($row)
Paul,
not much to tell (if I understand you correctly) - I get
fred 1 0 0 0 0
NULL
no
where NULL refers to $row['group1'] which in the first line is 1?!
Cheers
Geoff
PS the code is
echo var_dump($row['group1']) . "<br>";
if ($row['group1'] == 1) {
echo "yes" . "<br>";
} else {
echo "no" . "<br>";
}
} else {
echo mysql_error();
}
Geoff Cox wrote:
On Tue, 12 Aug 2008 10:00:18 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>>Geoff Cox wrote:
>>On Tue, 12 Aug 2008 00:35:05 -0700 (PDT), Sjoerd <sj******@gmail.comwrote:
On Aug 12, 9:16 am, Geoff Cox <g...@freeuk.notcomwrote: the value is 1 but php if ($row['group1'] == "1") { does not work.
This should work. However, if $row['group1'] contains "1 " (one space) it does not work. You can use vardump($row['group1']) to determine the precise contents and type of the variable.
This is odd! I am using var_dump and code below which first gives group1 as 1 and then var_dump as NULL and then no.
Please post the output from var_dump($row)
Paul,
not much to tell (if I understand you correctly) - I get
fred 1 0 0 0 0
NULL
no
where NULL refers to $row['group1'] which in the first line is 1?!
Cheers
Geoff
PS the code is
echo var_dump($row['group1']) . "<br>";
if ($row['group1'] == 1) {
echo "yes" . "<br>";
} else {
echo "no" . "<br>";
}
} else {
echo mysql_error();
}
I asked:
Please post the output from
var_dump($row)
you posted something else.
Let me try this again:
Please post the output from
var_dump($row)
(Hint, now it is your turn. What you need to do is to READ what I asked and
to DO what is asked. This is how you get help!)
On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>> echo var_dump($row['group1']) . "<br>"; if ($row['group1'] == 1) { echo "yes" . "<br>"; } else { echo "no" . "<br>"; }
} else { echo mysql_error(); }
I asked: Please post the output from var_dump($row)
you posted something else.
Let me try this again: Please post the output from var_dump($row)
Paul,
'sorry - kind of watch my lips stupid!
I get
bool(false)
Cheers,
Geoff
On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>(Hint, now it is your turn. What you need to do is to READ what I asked and to DO what is asked. This is how you get help!)
Paul
this is how I created the table
CREATE TABLE best_users (
user_name text,
group1 tinyint(1),
group2 tinyint(1),
group3 tinyint(1),
group4 tinyint(1),
group5 tinyint(1)
) TYPE=MyISAM;
--
-- Dumping data for table best_docs
--
INSERT INTO best_users VALUES ('fred',1,0,0,0,0);
INSERT INTO best_users VALUES ('jill',0,1,0,0,1);
INSERT INTO best_users VALUES ('jane',1,0,0,0,0);
INSERT INTO best_users VALUES ('sam',0,1,0,0,1);
INSERT INTO best_users VALUES ('bill',0,0,0,1,1);
INSERT INTO best_users VALUES ('mary',0,0,1,0,0);
any clue there?
Cheers
Geoff
PS is using SSH I do a
select * from best_users where group1 = 1
this works OK and I get records 1 and 3 as I ought....
Geoff Cox wrote:
On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>>> echo var_dump($row['group1']) . "<br>"; if ($row['group1'] == 1) { echo "yes" . "<br>"; } else { echo "no" . "<br>"; }
} else { echo mysql_error(); }
I asked: Please post the output from var_dump($row)
you posted something else.
Let me try this again: Please post the output from var_dump($row)
Paul,
'sorry - kind of watch my lips stupid!
I get
bool(false)
Cheers,
Geoff
You need to execute:
$row = mysql_fetch_array($result))
var_dump($row)
You do not use echo with var_dump
On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>You need to execute: $row = mysql_fetch_array($result)) var_dump($row)
You do not use echo with var_dump
OK I see - I get
array(12) { [0]= string(4) "fred" ["user_name"]= string(4) "fred"
[1]= string(1) "1" ["group1"]= string(1) "1" [2]= string(1) "0"
["group2"]= string(1) "0" [3]= string(1) "0" ["group3"]=>
string(1) "0" [4]= string(1) "0" ["group4"]= string(1) "0" [5]=>
string(1) "0" ["group5"]= string(1) "0" }
Cheers
Geoff
On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
<pa**********@btinternet.comwrote:
>Geoff Cox wrote:
>On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman" <pa**********@btinternet.comwrote:
>>>> echo var_dump($row['group1']) . "<br>"; if ($row['group1'] == 1) { echo "yes" . "<br>"; } else { echo "no" . "<br>"; }
} else { echo mysql_error(); }
I asked: Please post the output from var_dump($row)
you posted something else.
Let me try this again: Please post the output from var_dump($row)
Paul,
'sorry - kind of watch my lips stupid!
I get
bool(false)
Cheers,
Geoff
You need to execute: $row = mysql_fetch_array($result)) var_dump($row)
You do not use echo with var_dump
Paul,
I have found out how to get the
if ($row['group1'] == 1) { etc
to work but perhaps you can explain why!?
If I make the test within the while loop,
while ($row = mysql_fetch_array($result)) {
($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
Cheers
Geoff
On 13 Aug, 08:40, Geoff Cox <g...@freeuk.notcomwrote:
On Tue, 12 Aug 2008 14:44:29 +0100, "Paul Lautman"
<paul.laut...@btinternet.comwrote:
Geoff Cox wrote:
On Tue, 12 Aug 2008 13:26:50 +0100, "Paul Lautman"
<paul.laut...@btinternet.comwrote:
>>echo var_dump($row['group1']) . "<br>"; if ($row['group1'] == 1) { echo "yes" . "<br>"; } else { echo "no" . "<br>"; }
>>} else { echo mysql_error(); }
>>I asked: Please post the output from var_dump($row)
>>you posted something else.
>>Let me try this again: Please post the output from var_dump($row)
Paul,
'sorry - kind of watch my lips stupid!
I get
bool(false)
Cheers,
Geoff
You need to execute:
$row = mysql_fetch_array($result))
var_dump($row)
You do not use echo with var_dump
Paul,
I have found out how to get the
if ($row['group1'] == 1) { etc
to work but perhaps you can explain why!?
If I make the test within the while loop,
while ($row = mysql_fetch_array($result)) {
($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
Cheers
Geoff- Hide quoted text -
- Show quoted text -
$row doesn't get a value until you assign one.
So if you do:
$row = mysql_fetch_array($result))
echo "@{$row['group1']}@"
Message-ID: <fo********************************@4ax.comfrom Geoff Cox
contained the following:
> while ($row = mysql_fetch_array($result)) { ($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
<fx: smacks head>
For every iteration of $row = mysql_fetch_array($result) then
$row['group1'] will have a different value corresponding to the entry in
the database for that particular row. Outside the loop (below the while
loop in the code) $row['group1'] will have the value corresponding to
the last row of the database query.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011 http://slipperyhill.co.uk
On Wed, 13 Aug 2008 02:58:39 -0700 (PDT), Captain Paralytic
<pa**********@yahoo.comwrote:
> $row doesn't get a value until you assign one. So if you do: $row = mysql_fetch_array($result)) echo "@{$row['group1']}@"
OK - get it.
Thanks
Geoff
On Wed, 13 Aug 2008 11:05:18 +0100, Geoff Berrow
<bl******@ckdog.co.ukwrote:
>Message-ID: <fo********************************@4ax.comfrom Geoff Cox contained the following:
>> while ($row = mysql_fetch_array($result)) { ($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
<fx: smacks head> For every iteration of $row = mysql_fetch_array($result) then $row['group1'] will have a different value corresponding to the entry in the database for that particular row. Outside the loop (below the while loop in the code) $row['group1'] will have the value corresponding to the last row of the database query.
Thanks - it came to me on the way home just now on my bike!
Cheers
Geoff
Geoff Berrow wrote:
Message-ID: <fo********************************@4ax.comfrom Geoff Cox
contained the following:
>while ($row = mysql_fetch_array($result)) { ($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
<fx: smacks head>
For every iteration of $row = mysql_fetch_array($result) then
$row['group1'] will have a different value corresponding to the entry in
the database for that particular row. Outside the loop (below the while
loop in the code) $row['group1'] will have the value corresponding to
the last row of the database query.
No it wont. It wil have a NULL value assigned, as it is the failure of
$row to be anything other than null that *causes the loop to exit*.
Message-ID: <12****************@proxy00.news.clara.netfrom The Natural
Philosopher contained the following:
><fx: smacks head> For every iteration of $row = mysql_fetch_array($result) then $row['group1'] will have a different value corresponding to the entry in the database for that particular row. Outside the loop (below the while loop in the code) $row['group1'] will have the value corresponding to the last row of the database query.
No it wont. It wil have a NULL value assigned, as it is the failure of $row to be anything other than null that *causes the loop to exit*.
Hmm, good point. In practice you wouldn't normally have a use for $row
outside the loop so it's never an issue.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011 http://slipperyhill.co.uk
On Wed, 13 Aug 2008 19:45:58 +0100, The Natural Philosopher <a@b.c>
wrote:
>Geoff Berrow wrote:
>Message-ID: <fo********************************@4ax.comfrom Geoff Cox contained the following:
>>while ($row = mysql_fetch_array($result)) { ($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this?
<fx: smacks head> For every iteration of $row = mysql_fetch_array($result) then $row['group1'] will have a different value corresponding to the entry in the database for that particular row. Outside the loop (below the while loop in the code) $row['group1'] will have the value corresponding to the last row of the database query.
No it wont. It wil have a NULL value assigned, as it is the failure of $row to be anything other than null that *causes the loop to exit*.
in fact that's what I found - a null value - which made me think I
need to test within the while loop.
Cheers
Geoff
Message-ID: <jh********************************@4ax.comfrom Geoff Cox
contained the following:
>in fact that's what I found - a null value - which made me think I need to test within the while loop.
You're still not getting it are you?
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011 http://slipperyhill.co.uk
Geoff Cox wrote:
On Wed, 13 Aug 2008 19:45:58 +0100, The Natural Philosopher <a@b.c>
wrote:
>Geoff Berrow wrote:
>>Message-ID: <fo********************************@4ax.comfrom Geoff Cox contained the following:
while ($row = mysql_fetch_array($result)) { ($row['group1'] == 1) { etc
this works.
Outside the loop $row['group1'] is empty (or NULL?)
Why is this? <fx: smacks head> For every iteration of $row = mysql_fetch_array($result) then $row['group1'] will have a different value corresponding to the entry in the database for that particular row. Outside the loop (below the while loop in the code) $row['group1'] will have the value corresponding to the last row of the database query.
No it wont. It wil have a NULL value assigned, as it is the failure of $row to be anything other than null that *causes the loop to exit*.
in fact that's what I found - a null value - which made me think I
need to test within the while loop.
Indeed. That is exactly what the code should give you: a null result.
I am not sure what you were TRYING to achieve with that code fragment,
but the problem has nothing to do with equality and tinyints..
Cheers
Geoff
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Terry Parker |
last post by:
I have a database that stores text (and other objects) which I would like to
categorize under multiple categories. I started out creating a "SET" field
with the different category names and I...
|
by: Eugene |
last post by:
Hi,
In Query Analyzer:
update tblUserProcess
set usercode = 1002
Error:
Arithmetic overflow error for data type tinyint, value = 1002.
The statement has been terminated.
|
by: Matt Burland |
last post by:
I'm a little confused about the way the default equality operator works with
classes. Here's the situation, I have two comboboxes that are each filled
with different object (i.e. ComboBox1 contains...
|
by: Fabio Negri Cicotti |
last post by:
I have created into the SQL Server 2 tables parent/child having the parent
an autoincrement primary key. E.g.:
Order table
ordID - tinyint
ordName - string(50)
Order_Detail table
ordID -...
|
by: Wasim Akram |
last post by:
Hi,
I have a field "Month" in my SQL server table. The type of this field is
"tinyint".
Now what I am doing in the code is using DataRow to read this field in a
'int' variable.
int month...
|
by: Gary Brown |
last post by:
Hi,
In C#, how do you determine two objects are the "same" rather
than "equal?" In C/C++ you can check the addresses and LISP
provides a rich set of equality operators but C# appears ambiguous....
|
by: Elmo Watson |
last post by:
I am having all kinds of problems with a Stored Proc I'm trying to run, with
the error I'm getting above.
First - the way I'm reading it - the database EXPECTS a TinyInt - and it
thinks I'm...
|
by: phillip.s.powell |
last post by:
For some bizarre reason, each time I insert or update a row in my table
`image`, the field value for "image_width" is fixed at 127, no matter
what value I use!
Here is the schema:
CREATE...
|
by: tshad |
last post by:
I have a value in my sql table set to tinyint (can't set to bit).
I am trying to move it into a boolean field in my program and have tried:
isTrue = (int)dbReader
and
isTrue =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
| |