Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a boolean column from MySQL table

Status
Not open for further replies.

MichaelHooker

Programmer
Mar 17, 2006
70
GB
After many hours of searching in books and on the net, I can't find the answer to this simple question. Maybe I'm using the wrong keywords to search under?

I pull out rows of data from my table in the usual way, ending up with the row I want to work with in array variable $row. The data are the details relating to a photo, shown as a thumbnail (not stored in the db). There are two buttons, for pulling up a small and a large-sized version of the photo respectively, but in some cases no large-sized version exists - the photo isn't clear enough to cope. In those cases the "large" button is enabled only "if (file_exists($path_to_image_file)) {...}". If the file does not exist, the button is greyed out.

This works surprisingly well, but to my mind it's clunky and disk-intensive. The alternative solution I have in mind is a new boolean column in my details table, true if a large image exists, else false. What I can't find out is what exactly ends up in the php array "cell" corresponding to the boolean field, and how to process it.

Would it be as simple as:
Code:
if ($row[ColNo]) {
  echo  '<input type=button etc etc
} else {
  echo  '<input disabled type=button etc etc
}

or do I have to look for the word "TRUE" or the letter "T" or something else?

Many thanks for the help.

Michael Hooker
 
how do you know what the path to the image is?

i would store it in the table, in the path_to_image column

then make it NULL if the large image doesn't exist



r937.com | rudy.ca
 
how do you know what the path to the image is?

The variable is simply the hard-coded path to the folder where the large-sized photos are stored, concatenated with the image filename, which is the first column in the table. All three versions of the photo, large, small and thumbnail, have the same basic name, they're just in appropriately named folders. This makes far more sense to me, there is no point in repeating columns with the same text in them - which means more typing and more errors. Yes, all sorts of input arrangements could be made to automate this, but the fact is the website is in transition from one (flaky DHTML) system to another (PHP MySQL), and to keep it all running in the meantime I have to input new data to both systems via a hand-typed csv file, which needs only minimal changes for the MySQL.

But in any case, even if another solution is found, I still want to know how to read a Boolean field. If it works, I can use the technique for other website features. The way you avoid giving a straight simple answer to a straight simple question makes me think that maybe there is a reason I can't find the answer myself - maybe it can't be done! Also, I don't know how to detect a "NULL" either! What php code would read a null in the $row array?

I think I'm making huge progress for someone who had never touched php or MySQL until a few months ago; the new bits of my website are a vast improvement. But I just can't seem to find certain basic bits of information in either of the very expensive books I have or by googling the net.

Thanks

Michael Hooker

 
Whoops, I need my eyesight checking. I thought I was in the php forum - must have clicked the wrong link under "My Threadminder"

Thanks anyway

Michael Hooker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top