473,569 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If result set is empty print "no records"

155 New Member
I've tried to incorporate an IF Statement into the below so that if the query returned nothing - a message saying "There are no jobs currently listed" would be displayed, but for some reason it hasn't worked. Right now it just returns a blank table.

[PHP]<?php
$query="SELECT * FROM $nameid WHERE display_ad='yes ' AND submitted > SUBDATE(NOW(), INTERVAL 30 DAY) ORDER BY submitted DESC LIMIT $offset, $rowsPerPage";
$result=mysql_q uery($query) or die('Error, query failed');
$num=mysql_numr ows($result);

$i=0;
while ($i < $num)
{
$id=mysql_resul t($result,$i,"i d");
$company=mysql_ result($result, $i,"company");
$position=mysql _result($result ,$i,"position") ;
$city=mysql_res ult($result,$i, "city");
$date=mysql_res ult($result,$i, "submitted" );
$fdate = explode('-', $date);
?>

<table>
<tr>
<td width="35%"><? echo ("<A HREF='see_job.p hp?nameid=$name id&file=$id'>$c ompany</A>"); ?></td>

<td width="37%"><? echo "$position" ; ?></td>

<td width="16%"><? echo "$city"; ?></td>

<td width="12%"><? echo "$fdate[1]/$fdate[2]/$fdate[0]"; ?></td>
</tr>
</table>

<?php
++$i;
} [/PHP]
Oct 2 '07 #1
3 4798
ak1dnar
1,584 Recognized Expert Top Contributor
First what is this "mysql_numr ows" ? (4th line in the above code)

Then read here please:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $num=mysql_num_rows($result); 
  3. if($num > 0){
  4.     while($row=mysql_fetch_assoc($result)){
  5.     //Print The $row array elements here
  6.     echo $row['MySQL_COLUMN_NAME1'];
  7.     echo $row['MySQL_COLUMN_NAME2'];
  8.     echo $row['MySQL_COLUMN_NAME3'];
  9.     }
  10. }else{
  11. echo 'No-Records';
  12. }
  13. ?>
Oct 2 '07 #2
DavidPr
155 New Member
First what is this "mysql_numr ows" ?
It's just something I've always used, but I like yours better. Works fine now, thanks!

David
Oct 2 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
And David, If you ever need anything post back to the forum. Thanks.
Oct 3 '07 #4

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

Similar topics

19
6449
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread...
0
4830
by: J. Muenchbourg | last post by:
I'm using and If with the BOF and EOF methods to start looping thru a group of records: If rstime.BOF and rstime.EOF Then response.write "There are no records!" <%Else%> <%If Not rstime.BOF Then%> <!-- the old Here are your results header --> <% Do While Not rstime.EOF
2
2092
by: amywolfie | last post by:
I would like to place a Find button on a form which uses the built-in Access Find facility. If no records are found, I would like to display a custom "no records found - plesae try again" message which overrides the standard Access dialog. I do know how to turn Warnings on and off, just not how to code for a "No Records Found" on a button,...
4
9525
by: amywolfie | last post by:
I would like to put code behind a Find button on a form which: 1) Performs a find based on a field on the form 2) If NO RECORDS ARE FOUND, then displays a custom "No Records Found" message box. Thanks!! amy ===
1
5713
by: Kim | last post by:
How can I display "No data found" in the repeater if there are no records found after selecting an item from a dropdown list. Another question is: Can repeater perform paging as in datagrid if the number of records to be displayed in too long ? I am using a repeater instead of datagrid as the latter does not allow me to have one...
9
3001
by: EdWhyatt | last post by:
Hi all, I have searched the group with no answer to this particular problem. In my sendmail program, I would like to have the ability to send a mail message with no-one email address in the To field. I do this by adding the mail to the CC field via a header. However, by the time I get to the point of sending the mail, my recipient list is...
1
2710
by: scottmachado | last post by:
I am currently running a marco that run a query and emails the results as an attachment in excel format. If the query has no records, I would like to email "no records found" in the first cell in the excel attachment. I have a feeling that this needs to be done in VB, but I don't know that much about VB. Would using a report instead be a...
11
6774
by: CrostonScottish | last post by:
Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the corresponding records based on a query i have built in to the code below which is applied to the search command button in my search form. Private Sub...
8
1848
by: W. eWatson | last post by:
I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32"...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.