Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Record Set - Show Field If Contains Data

Posted on 2004-08-03
6
263 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 500 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

789 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