Solved

how to write this in coding terms?

Posted on 2009-07-05
2
164 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 125 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
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 …

773 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