how to compare value of mysql field


 
Thread Tools Search this Thread
Top Forums Programming how to compare value of mysql field
# 1  
Old 03-13-2012
how to compare value of mysql field

Code:
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <mysql.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <mysql.h>

int main(int argc, char **argv)
{

   MYSQL *conn;
        MYSQL_RES *result;
        MYSQL_ROW row;
        MYSQL_FIELD *field;
        int num_fields;

          conn = mysql_init(NULL);
          mysql_real_connect(conn, "localhost", "biduser", "biduser1234", "bid", 0, NULL, 0);

         mysql_query(conn, "select * from site_auth where user_admin='admin' ");
         result=mysql_use_result(conn);

         num_fields=mysql_num_fields(result);
         printf("Total fields= %d\n",num_fields);

        while(row=mysql_fetch_row(result))
        {
                 printf("%s",row[0]);
                 printf("%s",row[1]);
                 printf("%s",row[2]);
                 printf("%s",row[3]);
                 
                int getrow=row[0];

                if(getrow=='1'){
                        printf("\n admin");
                }
        }


   mysql_free_result(result);
   mysql_close(conn);
}

Code:
siteauth_id    user_admin   password_admin                                   comment
1                  admin           c92b51b2f4d93d4e1081670bd9273402    Administrator
769204065    demouser    81dc9bdb52d04dc20036dbd8313ed055    demo



1. i want to compare row[0] with value 1. How to??
2. possible row[0] change to row['user_admin'] link php

sorry i newbies c programming (i'm php programming)

Last edited by pludi; 03-13-2012 at 04:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

2. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

3. Programming

mysql query multiple records for one field

Hello Group, What I have is a database with about a dozen fields and one being "City". What I would like to do is to have a custom query on a single field for multiple items (cities) but I don't know how to do this. I know this is probably kids play for most of you but I am lost. What I have... (4 Replies)
Discussion started by: vestport
4 Replies

4. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

5. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

Compare one field

Hello to every one: i have and archive like this: 5552952099|5552952099|VAHC600312UY9|VARGAS HERNANDEZ MA DEL CARMEN|METRO|LOMAS|CC|20||||900661026|1|METRO 5552952115|5552952949|AABF680818FT7|ABASOLO BONILLA FERDINAND|METRO|LOMAS|CC|20||||900671255|1|METRO... (6 Replies)
Discussion started by: xasky
6 Replies

7. Shell Programming and Scripting

Compare file of hostnames with table in MySQL DB

Hi all, i have a list of files that contains some PC hostname, then i need to enumerate every hostname and check if there's a table with same name of the hosts in MySQL database XYZ. I need this because have to decide automatically if i have to make a create table or a insert into an existent... (2 Replies)
Discussion started by: maxlamax
2 Replies

8. Shell Programming and Scripting

Insert IP address into MySQL int field

Greets all, I'm using Perl trying to insert an IP address from a log file into an INT field in a MYSQL table. So it needs to be converted into an int first. I thought the pack() function could do this for me, but I'm not sure I get the right thing. I also need to be able to extract it correctly... (3 Replies)
Discussion started by: otheus
3 Replies

9. Programming

Load text file into a MySQL field

Hello, maybe this post is offtopic, sorry for the inconveniencies. I found examples about how to populate different fields from a text file (with MySQL, the LOAD DATA INFILE sentece), but not about how to load a complete plain text file into a concrete database field. Could you please tell me if... (1 Reply)
Discussion started by: aristegui
1 Replies
Login or Register to Ask a Question