Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Record Set - Show Field If Contains Data

Posted on 2004-08-03
6
Medium Priority
?
282 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
[X]
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
  • 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
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…
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…

688 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