I need to add a column in my database, which will be called 'MemberPackSent' basically I want to send out a pack to members, just wondering would I make this a Boolean? Do I need to specify the 'Length' or is a Boolean simply always 1 or 0?
I need to add a column in my database, which will be called 'MemberPackSent' basically I want to send out a pack to members, just wondering would I make this a Boolean? Do I need to specify the 'Length' or is a Boolean simply always 1 or 0?
Boolean can be 1 or 0, but you can make it "true" or "false" as well. I know in PHP true and false boolean tags are read as 1 and 0 anyways, if you try to echo them.
As long as you don't get too confused, 1 and 0 are fine.
- Mike
Ahhhhh ok is there a way in php that if it was a '1' value I could convert it to 'Yes'?
Code:if ($value == 1) { $value = "Yes"; } else { $value = "No"; }
- Mike
Code:$value = $value ? "Yes" : "No";
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Huh?
Shouldn't:
BeCode:$value = $value ? : "Yes" : "No";
Code:$value = $value ? "Yes" : "No";
- Mike
Yes, sorry, typo. Corrected.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Hi tomy,
Yes, sure you can assign the value using simple “if” condition before updating database.
Here is the basic code to do this..
After converting the value you can simply insert it into the database using SQL statements.Code:<?php $con = @mysql_connect(“Ip Address”, “username”, “password”) or die(mysql_error()); $db = @mysql_select_db(“emp”, $con) or die(mysql_error()); $packets = true; If ($packets = true) { $Val = 1; } Else { $val = 0; } ?>
Last edited by tech_support; 04-16-2007 at 09:12 AM. Reason: Please wait until you have 5 posts before inserting a signature.
Some versions of MySQL will accept "true" and "false" as keywords and convert them automatically.Watch the "smart quotes" -- that won't even parse as PHP.Code:$con = @mysql_connect(“Ip Address”, “username”, “password”) or die(mysql_error());
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Off the topic of connecting, but mysql_query allows it:
so in PHP, you could doCode:SELECT * FROM blah WHERE test=“foo”
Code:mysql_query('SELECT * FROM blah WHERE test=“foo”');
- Mike
Bookmarks