Solved

Record Set - Show Field If Contains Data

Posted on 2004-08-03
6
238 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:
Squinky 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:Squinky
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:Squinky
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:Squinky
ID: 11703504
A very nice PHP templating system: http://smarty.php.net/
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now