Solved

how to write this in coding terms?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 …

758 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

23 Experts available now in Live!

Get 1:1 Help Now