473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to fetch a specific row in a mysql database?

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>
  6.  
  7.  
  8. #define host "192.168.0.2"
  9. #define username "root" 
  10. #define password "" 
  11. #define database "senthil"
  12.  
  13. void main()
  14. {
  15.  
  16. MYSQL *conn; 
  17. conn = mysql_init(NULL);
  18.  
  19. mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  20. MYSQL_RES *res_set; 
  21. MYSQL_ROW row;
  22.  
  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);
  27.  
  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. }
  35.  
  36. mysql_close(conn);       
  37. getch();
  38.  }
  39.  
  40.  
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(conn,"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,dff,....)
and the second row wil be returned as another string...(101,102)..


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...

thanks...
senthil
Dec 20 '06 #1
7 16673
ronverdonk
4,258 Expert 4TB
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));
  4.  
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
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
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(conn,"SELECT * FROM sen fetch first 3 rows only");


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

thanks and regards..
senthil
Dec 21 '06 #4
Hai ronald,

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


mysql_query(conn,"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...

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

Ronald :cool:
Dec 21 '06 #6
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...
senthil
Dec 22 '06 #7
ronverdonk
4,258 Expert 4TB
You'd better turn to the C/C++ forum for these questions. Link is
http://www.thescripts.com/forum/forum129.html

Ronald :cool:
Dec 22 '06 #8

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

Similar topics

16
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...
7
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...
3
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.
11
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...
1
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
17
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...
4
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...
1
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...
6
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.