473,387 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to display there msg ( there is no item ) when mysql query return no data

khalidbaloch
i want to show on page the messege that say there is currently no item when a mysql query return no record instead of blank page ..
i hope this is not a big issue and will be resolved in first reply

thanks for any help in advance .....
Nov 1 '06 #1
6 2721
ronverdonk
4,258 Expert 4TB
Show the MySQL query. Don't let me quess what you're doing!

Ronald :cool:
Nov 1 '06 #2
vssp
268 100+
If (mysql_num_rows($res)==0)
{
echo "No records";
}
else
{
\\Display result .

}


I hop this massage usfull for u

vssp
Nov 2 '06 #3
here is my sql query with php code please give an example with complete code as i am a new to php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require ("dbconnect.php");
  3. $result = mysql_query("SELECT * FROM news_content WHERE catid='1'
  4.  AND status='approved'") or die(mysql_error());  
  5. $row = mysql_fetch_array( $result );
  6. echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
  7. ?>
Nov 2 '06 #4
ronverdonk
4,258 Expert 4TB
Don't fool me: you are not that new to PHP and you should read what vssp wrote regarding use of mysql_num_rows().
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require ("dbconnect.php");
  3. $result = mysql_query("SELECT * FROM news_content WHERE catid='1'
  4.  AND status='approved'") or die(mysql_error());  
  5. If (mysql_num_rows($result) == 0) {
  6.   echo "No records";
  7. }
  8. else {
  9.   $row = mysql_fetch_array( $result );
  10.   echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
  11. }
  12. ?>
Ronald :cool:
Nov 3 '06 #5
thanx ronald it is done but no i want to use this in mysql_fetch_object function in order to retrive more than one row
i tried alot at last i succedd .i found this way to accomplish that ..
if there is a better idea please let me know
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $topic_id=$_GET['topic_id'];
  3. require 'dbconnect.php';
  4. $sql = "SELECT * FROM news_content  WHERE topic_id='$topicid' LIMIT 10";
  5. $result = mysql_query($sql);
  6. if (mysql_num_rows($result) ==0) { echo "no record";
  7. }
  8. else {
  9. while ($record = mysql_fetch_object($result)) {
  10. echo $row['news_title']." - ".$row['short_description'];"-".$row['news_details'];
  11. }
  12. }
  13. ?>
Nov 4 '06 #6
sorry i have misspelled in previous post i put $row['etc'] instead of $record->etc
so bellow is the right script ..
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $topic_id=$_GET['topic_id'];
  3. require 'dbconnect.php';
  4. $sql = "SELECT * FROM news_content  WHERE topic_id='$topicid' LIMIT 10";
  5. $result = mysql_query($sql);
  6. if (mysql_num_rows($result) ==0) { echo "no record";
  7. }
  8. else {
  9. while ($record = mysql_fetch_object($result)) {
  10. echo $record->short_description - $record->title
  11. }
  12. }
  13. ?>
Nov 4 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: danubian | last post by:
Hi, I'm a newbie in php/mysql programming,really am. I'm working on a web-site that allows registration and posterior logging in. Already registered user logs in with valid username and...
5
by: Jerome | last post by:
Hi, I've got the following problem: I want my ASP page to display a certain number (based on a COUNT query), it works fine if the result is at least 1! If there are no records to be counted...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
7
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
24
by: Phil Latio | last post by:
Let's say I have a simple web application running with just two MySQL tables. The tables structure is as follows: Table: category category_id (PK) category_name parent_category (FK)...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
9
by: tomhawkins1 | last post by:
Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, dwf and dwg. These files are uploaded to /home/**user**/uploads and not /home/...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.