close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

PHP code to prevent empty database field from displaying

Thread began 2/14/2016 6:33 pm by John | Last modified 2/15/2016 12:12 pm by Ray Borduin | 1728 views | 9 replies |

John

PHP code to prevent empty database field from displaying

I have just upgraded to DW CC2015 and purchased the entire WebAssist Suite. I have always used some PHP code to make it so an empty database field will not display on the web page. Very simple and always worked. Now, for some reason it no longer works and it's a critical thing for the websites I develop. Here is the code (recordset and field names changed to protect the innocent):

<?php if($row_rsRecordset['db_field']<>"") { ?><a href="<?php echo($row_rsRecordset->getColumnVal("db_field")); ?>" target="_blank">Website</a><?php } ?>

I have also tried !="" instead of <>"" and <? }?> at the end instead of <?php } ?> and still didn't work.

This is basically a text link to display a link to an author's website. If the field is empty (no URL in the field), the text should not display. The problem is that it never displays. I have the same thing for Facebook and Twitter for the author, and the same thing happens - nothing displays. I have probably 20 websites where I use this same code and it works fine, mostly implemented in Dreamweaver CS6 or earlier. Any idea what this is not working now. I have spent hours today trying to figure it out with no success. The MySQL database is the same, and I have checked the data and the fields, everything is as it should be but it doesn't work. Very frustrated!!

I have also tried it where some authors have a photo and some don't, so I want to hide it when they don't. Same problem. When I wrap the code around the image, none of them show up.

Thanks,
John Burke

Sign in to reply to this post

Jamie

have you tried wrapping it like this:

<?php if ("".$row_RecordsetName['ColumnTitle']  ."" != "") {  ?>
<a href="<?php echo($row_rsRecordset->getColumnVal("db_field")); ?>" target="_blank">Website</a>
<?php } ?>



Jamie

Sign in to reply to this post

John

Jamie, thanks for the response.

I tried that and no luck either. This is just baffling to me. It's such a simple thing that I have always done and now it's not working. Here are the differences from my previous implementations:

1. Using Dreamweaver CC 2015 instead of DW CS6
2. Using WebAssist Suite which generates MySQLi instead of MySQL, so the generated PHP is different.

Otherwise, I think it's the same - the database is a copy of one I had used for dev purposes, so nothing changed there, and the db and website are on the same server as all the other sites (my dedicated server at a web hosting company), so versions of MySQL and PHP are the same.

Any help would be greatly appreciated.

Thanks!

Sign in to reply to this post

Jamie

If its mysqli then try wrapping it with this

<?php if ("".($RecordsetName->getColumnVal("ColumnTitle"))  ."" != "") { ?>

<?php } ?>
Sign in to reply to this post

John

Originally Said By: Jamie
  If its mysqli then try wrapping it with this

<?php if ("".($RecordsetName->getColumnVal("ColumnTitle"))  ."" != "") { ?>

<?php } ?>
  



Jamie, I just tried this and got the following error message. I'm not much of a programmer so I don't know what it means:

Fatal error: Call to a member function getColumnVal() on a non-object

Thanks again.

Sign in to reply to this post

Jamie

can you show the RS you are using?

Sign in to reply to this post

John

Originally Said By: Jamie
  can you show the RS you are using?  



Sure, here it is: I'm pulling from two tables, authors and books, so I can display author information and list their books (there is another RS for the book list and the auth_id ties the author and books together and it's passed in the URL). Everything works fine until I try to hide fields.

<?php
$rsAuthorDisplay = new WA_MySQLi_RS("rsAuthorDisplay",$connProjMain1,1);
$rsAuthorDisplay->setQuery("SELECT books.full_title, books.title, books.subtitle, books.isbn13, books.active_web, books.pub_date, books.auth_id, books.publisher, books.coverimage, books.accolades, authors.auth_id, authors.auth_photo, authors.author_full, authors.authfirst, authors.authlast, authors.authbio, authors.auth_website, authors.auth_facebook, authors.auth_twitter FROM books, authors WHERE authors.auth_id = ? AND authors.auth_id = books.auth_id");
$rsAuthorDisplay->bindParam("s", "".$_GET['auth_id'] ."", "-1"); //colname
$rsAuthorDisplay->execute();
?>

Sign in to reply to this post

Jamie

And if you use this, whats the full error youre getting?

<?php if ("".($rsAuthorDisplay ->getColumnVal("auth_website")) ."" != "") { ?>
<a href="<?php echo($rsAuthorDisplay->getColumnVal("auth_website")); ?>" target="_blank">Website</a>
<?php } ?>

Sign in to reply to this post

John

It works now!!! On my last try with what you sent I made a small typo. Once corrected it worked.

Thank you SOOOO much for your help. I really appreciate it.

John Burke

Sign in to reply to this post

Jamie

glad you got it working John. Happy to have helped :)

Jamie

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...