Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Record Set - Show Field If Contains Data

Posted on 2004-08-03
6
Medium Priority
?
287 Views
Last Modified: 2012-05-05
Hi,

I have a dynamic table (DW) which displays a recordset. There is a field (lets say image) and if there is a value in this field then I want to diplay a checkbox with a tick in.

Hope thats clear!

Thanks,

Farawayman
0
Comment
Question by:farawayman
  • 4
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 2000 total points
ID: 11702282
Rather than trying to examine the data after you've extracted it from the database, get the database to tell you if the field is empty:

SELECT blobdata, ISNULL(blobdata) FROM table WHERE id='1'

This way you get to look at a plain boolean value in a field instead of arbitrary binary data or NULL, so when you output:

<input type="checkbox" name="checkbox[]" <?php if ($row[1]) echo ' checked="checked"';?> />

Not quite sure how you'd formulate that to work with DW's system - I use DW, but I use Smarty for stuff like this.
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11702339
Oops sorry, there isn't an is null function, but an operator that does the same:

SELECT blobdata, 1 <=> blobdata FROM table WHERE id='1'
0
 

Author Comment

by:farawayman
ID: 11702371
Hi Squinky,

I went for this:

    <tr class=table_emphasis><td>Attached File Name</td></tr>
    <tr><td><?php if ($row_rs_requestdetail['file_id'] == "") { // Show if recordset field empty ?>
      No Attached File Found
      <?php } // Show if recordset empty ?> <?php if ($row_rs_requestdetail['file_id'] != "") { // Show if recordset field not empty ?>
      <?php echo $row_rs_requestdetail['file_id']; ?>
      <?php } // Show if recordset field  not empty ?> </td></tr>
  <?php } while ($row_rs_requestdetail = mysql_fetch_assoc($rs_requestdetail)); ?>
</table>

Changed a bit of DW stuff - but this doesn't do for the checkbox but I think I can figure it from here.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11702538
OK, that looks fair enough - just add a checkbox input tag - I was assuming you wanted to display the box checked if there was a file and unchecked if it wasn't, rather than present and checked, or entirely absent.
Using a bottom-tested while loop here is untidy - you'll get a warning when accessing $row_rs_requestdetail['file_id'] if no records were found (when it displays 'no attached file found') because the "file_id" index won't exist.
BTW, your code might be a bit more readable if you use this syntax when mixing PHP and content:
http://uk.php.net/manual/en/control-structures.alternative-syntax.php
I don't like this syntax, but it's better than nothing if you're not using Smarty.
0
 

Author Comment

by:farawayman
ID: 11702872
what is smarty?
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11703504
A very nice PHP templating system: http://smarty.php.net/
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question