473,699 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fetch a specific row in a mysql database?

61 New Member
Hai to all,
this is senthil...
i'm now working in the field of VC++...
i want to connect a mysql database...

just now tried to retrieve rows from a simple
mysql database by using VC++

My database is like this...

Name roll no
asd 101
dff 102
sdf 103
fdf 104
dfd 105

i have used the following codings for connecting the database..
And the output also comes clearly.. No probs for the output..
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> 
  2. #include <mysql.h> 
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include<string.h>
  8. #define host ""
  9. #define username "root" 
  10. #define password "" 
  11. #define database "senthil"
  13. void main()
  14. {
  16. MYSQL *conn; 
  17. conn = mysql_init(NULL);
  19. mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  20. MYSQL_RES *res_set; 
  21. MYSQL_ROW row;
  23. unsigned int i=0; 
  24. mysql_query(conn,"SELECT * FROM sen"); 
  25. res_set = mysql_store_result(conn); 
  26. unsigned int numrows = mysql_num_rows(res_set);
  28. while ((row = mysql_fetch_row(res_set))!= NULL)
  29. {
  30. i=0;
  31. printf("%s\t", row[i]!=NULL? row[i]:"NULL");
  32. i++;
  33. printf("%s\n", row[i]!=NULL? row[i]:"NULL");
  34. }
  36. mysql_close(conn);       
  37. getch();
  38.  }
Here row[0]= asd,dff,...
row[1]= 101,102,....

Here MYSQL_ROW row; -return data as array of strings
I also used the following codings for fetching a single field from the database by using
the following codings....

For example if i want to fetch 'sdf' field from the database
i gave the condition like this in select statement...
mysql_query(con n,"SELECT * FROM sen where Name='sdf'");

and here also the output comes clearly..

But i dont know how to fetch from a specific row...

for example...

i dont want the first two rows.... and if i want to fetch from
the third row only! what condition shall i give for this?

Very important point is that,
here MYSQL_ROW row; -return data as array of strings,
ie rows can only be returned as strings...
ie the first row will be return as a string..(asd,df f,....)
and the second row wil be returned as another string...(101,1 02)..

But i want to split that row....

How can i do that?

plzz explain me, this concept is going to be used for my project....

itz very important for me....

Can any one plzz reply me...

Dec 20 '06 #1
7 16709
4,258 Recognized Expert Specialist
Please read the Posting Guidelines before you post in this forum!

You can get the result's exact row by using command mysql_data_seek ().
Expand|Select|Wrap|Line Numbers
  1. $res=mysql_query("SELECT name from table");
  2. mysql_data_seek($res, 2);
  3. $row=mysql_fetch_assoc($res));
sets the pointer to the third row and fetches that row.

Getting a specific field from a specific row use mysql_result()
Expand|Select|Wrap|Line Numbers
  1. $res=mysql_query("SELECT name from table");
  2. mysql_result($res, 2);
gets you the content of column 'name' from the third row.

Caveat: you must check if these functions are available in VC++!

Ronald :cool:
Dec 20 '06 #2
61 New Member
Hai ronald,
thanks for ur reply...
ur conditions worked supervly in VC++,

i fetched the specific row in a mysql database..

Now i want to fetch only the first three rows and dont want the
next rows in the above database...

What condition shall i give for this...

i'm beginner for this type of works..

so plzz explain me...
Dec 21 '06 #3
61 New Member
Hai ronald,

i tried the following two conditions for fetching the fetching the
first 3 rows but nothing happened...

condition 1:
mysql_data_seek (res_set, -2);

condition 2:
mysql_query(con n,"SELECT * FROM sen fetch first 3 rows only");

will u plzz explain me how to fecth the first 3 rows...

thanks and regards..
Dec 21 '06 #4
61 New Member
Hai ronald,

i found the condition for fetching first 3 rows..
itz very simple..

mysql_query(con n,"SELECT * FROM sen LIMIT 0,3");

this is the condition...

Any way i cant do it without ur help....

thanks for ur support and expecting ur support in the future...

Dec 21 '06 #5
4,258 Recognized Expert Specialist
Glad you found the solution yourself, before I could answer that. Happy to have helped you out.

Ronald :cool:
Dec 21 '06 #6
61 New Member
Hai ronald,

i'm working in the field of
creating Adobe Indesign plugin's using VC++..

R u having knowledge in that?

Or any of ur friends working in that field?

i'm a beginner to this field and i'm going to work inidividually.. .

so i'm expecting the supports of experienced persons like u...

plzz give me ur friends mail id who r knowing about that field...

Will u plz help me?

Expecting for ur reply...
Dec 22 '06 #7
4,258 Recognized Expert Specialist
You'd better turn to the C/C++ forum for these questions. Link is

Ronald :cool:
Dec 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however lately I've been wanting to do more stuff with user accounts, and had been eying MySQL for over a year. Finally I've decided to start off small by converting the forum's account system to a MySQL database (and convert the rest later after I'm...
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that performs MySQL queries to a database. These queries are performed at regular intervals. Basically it is looking for fields that match certain criterias. Such fields are not present at all time. When the program finds such field, it then takes
by: nymano | last post by:
Hi. Just a brief question: Are "FETCH FIRST ROW ONLY" and "FETCH FIRST x ROWS ONLY" DB2 specific or SQL92? thanks for any help, nymano.
by: saurabhbpl | last post by:
hi, i have a html drop down menus and i want to conver it into dynamically means that menu show data from database.how can i fetch data from database for using menus and sub menus using php and mysql.
by: hemashiki | last post by:
hi i inserted an image in mysql,by using BLOB type i wan to fetch..can anyone tell me,how to do this
by: broughcut | last post by:
Is it possible to fetch a specific div from a source html document using XMLHttpRequest, rather than fetching the entire file? I was going to use Ajax on mouseover but keep the normal link intact, so that if the user does not have javascript they can click the link as normal and this would take them to the new page, but if they have javascript (and ActiveX enabled I guess, in the case of IE) it would just fetch the appropriate div into...
by: Marcus | last post by:
Hello, Whenever the PHP documentation references the optional link_identifier parameter in many mysql related functions (such as mysql_query, mysql_insert_id, etc.), it says: "The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or...
by: robin1983 | last post by:
Dear All, How are you everyone! I need a help from you all. Firstly, I want to know is it possible to fetch the email details from the Outlook to Excel or Database by using PHP. MS outlook has his own feature to export the details. But, by this its not possible to extract the body of the mail. Here, I want to know, is it possible to fetch mail details like sender email, sender date, received date, subject, body of the mail etc and save in...
by: edoplaza | last post by:
Hello, I'm new here. I'm creating a registration / reservation page for a hotel Web Site. After the user submits the information, I'd like him to see a feedback page just showing the information he just submitted. How can I tell php to fetch just that specific row?
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.