本文介绍了SELECT语句返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此语句返回正确的数字,但是当没有结果时,我需要它返回"0" ...我尝试了执行此操作的标准方法,但是它没有调试.现在,当未返回记录时,它仅显示空白.这是一个控制台应用程序.
This statement returns the correct numbers, but when there are no results I need it to return ''0''...I tried the standard way to do it but it doesn''t debug. Right now it just shows a blank when a record isn''t returned. This is a console app.
mysql_query(conn,"SELECT * FROM tblURL WHERE IP = ''192.168.1.1'',''0''");
my_ulonglong i = 0;
res_set = mysql_store_result(conn);
my_ulonglong numrows = mysql_num_rows(res_set);
while ((row = mysql_fetch_row(res_set)) != NULL){
printf("%s\n",row[i] != NULL ?
row[i] : "NULL");
[edit]添加了代码块,并删除了内联代码-OriginalGriff [/edit]
[edit]Code block added, inline code removed - OriginalGriff[/edit]
推荐答案
mysql_query(conn,"SELECT COUNT(*) FROM tblURL WHERE IP = ''192.168.1.1''");
res_set = mysql_store_result(conn);
my_ulonglong numrows = mysql_num_rows(res_set);
if (numrows > 0)
{
row = mysql_fetch_row(res_set));
printf("Count is: %s\n",row[0]);
}
这篇关于SELECT语句返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!