Solved

Record Set - Show Field If Contains Data

Posted on 2004-08-03
6
274 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 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
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!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 …

752 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