[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Show content if query is empty

Posted on 2012-08-14
4
Medium Priority
?
377 Views
Last Modified: 2012-08-17
For a search results page, if the search is empty I need to hide the thumbnail and show 'no results'

I'm fine with the first part ie hiding the thumb if there's no content

<?php if(!empty($row_Recordset1[NULL'])): ?>

Thumb content

<?php endif; ?>

I just need to show "noresults" if the query is empty
0
Comment
Question by:BrighteyesDesign
4 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 38291492
You can find num rows and put the message if the query is empty,

<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

if ($num_rows == 0)
{

}
?> 

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38291575
http://www.sitepoint.com/books/phpmysql5/

Trying to use Dreamweaver as a platform for learning PHP is not a very good idea.  Dreamweaver generates some of the worst PHP code ever written, and copying it without understanding how bad it really is, well, ... You get the picture.  If you're going to be responsible for the application you need to understand the essential moving parts.

Recently PHP has begun issuing recommendations to avoid using the MySQL extensions, preferring either MySQLi or PDO, so some of these learning resources may lead you to older documentation.  Don't let that dissuade you from reading - these functions perform activities that are things you need to understand if you are going to use PHP and any kind of data base.  Invest a little time in learning the concepts and you'll never have to copy Dreamweaver again! (cf: line 14)

<?php // RAY_mysql_example.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

// THE ABSOLUTE MINIMUM YOU MUST UNDERSTAND TO USE PHP AND MYSQL
// MAN PAGE: http://php.net/manual/en/ref.mysql.php
// MAN PAGE: http://php.net/manual/en/mysql.installation.php
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
// MAN PAGE: http://php.net/manual/en/function.mysql-real-escape-string.php
// MAN PAGE: http://php.net/manual/en/function.mysql-query.php
// MAN PAGE: http://php.net/manual/en/function.mysql-errno.php
// MAN PAGE: http://php.net/manual/en/function.mysql-error.php
// MAN PAGE: http://php.net/manual/en/function.mysql-num-rows.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-assoc.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-array.php
// MAN PAGE: http://php.net/manual/en/function.mysql-insert-id.php
// MAN PAGE: http://php.net/manual/en/function.error-log.php

Open in new window

0
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 38291583
<?php if(!empty($row_Recordset1[NULL'])): ?>

Thumb content

<?php else: ?>

No Results

<?php endif; ?>

Open in new window

0
 

Author Comment

by:BrighteyesDesign
ID: 38291720
Will do Ray,

I just haven't got a spare minute, I'm designing sites, creating brands, chasing invoices and going to meetings. Even my guitar is gathering dust in the corner! I do understand I need to look into PHP more. Thanks for the heads up though, I will try!

Thanks logudotcom, sure that works fine but I understood xmediamans code as i've used similar before.

Cheers xmediaman, all is working now.
0

Featured Post

Technology Partners: 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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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