Milan wrote:
In short, this is what i am trying to do, i have a field "neednda" in the table, and i need to display a HTML section if the value is 1 and hide it if the value is 0.
Something is wrong in the code i have:
Code: Select all
if ($row_Recordset3['NDA']!='0')
{
print "<table width='450' border='0' cellspacing='0' cellpadding='0'><tr><td width='305' valign='top'><span class='title1'>Attach NDA ! </span><span class='text3'></table>";
}
else
{
}
Is there an alternative way to do this?
Well, as
Weirdan mentioned, you might want to look at your data prior to trying script logic. One question I have, what type of field is this? Is it a BOOL or TINYINT type field with a 0 or 1 switch? Or is it a VARCHAR type field? Or ENUM? Once you decide specifically what data belongs in the field, then you can more easily make the comparison.
I have found it useful to use NULL field values whenever applicable. This should be your comparison for an empty field. For example, you define a table as such:
Code: Select all
CREATE TABLE IF NOT EXISTS `Users` (
UserID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName VARCHAR(50) NOT NULL,
Bio TEXT NULL,
UNIQUE (UserName)
);
Now, the first field `UserName` is defined as being 'NOT NULL', or in layman's terms, it
has to have a value when you perform an INSERT on the table. The other field, `Bio` is defined as NULL, and can be NULL when performing an INSERT. Essentially, if the field is NULL, it means 'the Bio data is unknown', vs 'the Bio data is 0 or an empty string'. It literally has no value. This isn't the best explanation, but hopefully you get the gist. You can then use the PHP function
is_null() on the resultset data to definitively test for NULL values.
Some further reading:
MySQL Manual: '
CREATE TABLE syntax'
MySQL Manual: '
NULL Values'
MySQL Manual: '
Working with NULL values'
MySQL Manual: '
Problems with NULL Values'
Milan wrote:
Also can someone recomend a good MySQL book?
I have found the Paul Dubois book 'MySQL' (SAMS, ISBN: 0672326736) to be excellent (although I don't own it, I do own his O'Reilly book, 'MySQL Cookbook'). The other book I might look at is by Welling & Thomson, well known for their writing in the field, 'MySQL Tutorial' (SAMS, ISBN: 0672325845).
Other than that, the MySQL manual online is wonderful, and I it would appear as though the print edition of the online manual has been condensed into several books, the abovementioned 'MySQL Tutorial' one of them.