Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to write this in coding terms?

Posted on 2009-07-05
2
Medium Priority
?
171 Views
Last Modified: 2012-05-07
how to write in the programing language that

if there is no record in the database the show the message
Empty Records
else show all the records from the database.

0
Comment
Question by:designersx
2 Comments
 
LVL 7

Accepted Solution

by:
aamodt earned 500 total points
ID: 24782831
Something like this .. ofc needs modification to work in your DB

This is MySQL by the way, dont know what you want :)

Regards Aamodt
<?php
 
mysql_connect('ipaddress','username','password');
mysql_select_db('database');
 
$result = mysql_query("SELECT * FROM table where field='something'");
 
if(mysql_num_rows($result) != 1) { echo 'Empty Records'; } else {
while ($row = mysql_fetch_array($result)) {
echo $row['id'].' - '.$row['test'].'<br />';
}
}

Open in new window

0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24782896
Hi aamodt,

I have done a little modification in your code.

<?php
mysql_connect('ipaddress','username','password');
mysql_select_db('database');
 
$result = mysql_query("SELECT * FROM table where field='something'");
 
if(mysql_num_rows($result) == 0) { 
	echo 'Empty Records';
} else {
	while ($row = mysql_fetch_array($result)) {
		echo $row['id'].' - '.$row['test'].'<br />';
	}
}
 
?>

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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 dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

916 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