Solved

how to write this in coding terms?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now