473,385 Members | 1,465 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,385 software developers and data experts.

How to query a single data on mySQL database using PHP

Hello everyone!

Can anyone tell me on how can i code using php the query on mysql database that gets a single value from it? i have here my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. $this->SetCon();
  3. $orgSQL = "SELECT org_id FROM users WHERE org_name = '$orgName';";
  4. $org_query_result = mysql_query($orgSQL);
  5. $org_key;
  6. while($row = mysql_fetch_row($org_query_result, MYSQL_ASSOC))
  7. {
  8.    $org_key = $row['org_id'];
  9. }
  10. return $org_key;
  11.  
  12.  
This code allows me to get a value from the database but the problem is i can only get the first value on my database i can't get the value in the database if it is not on the first row. Can anyone tell me of my mistake here?

Im new to PHP and MYSQL environment.

I will really appreciate any help.

Thanks
Jun 27 '11 #1
2 2668
sidhx
50
hey Niheel use array variable like this $org_key[]= $row['org_id']; inside the loop and define it as $org_key=array(); before starting the loop.

Check this link:http://in2.php.net/manual/en/book.array.php
Jun 28 '11 #2
Sid,

You will find that you are only getting the last org_id, not the first one.

The 'mistake' is that you are reading the value of org_id into your $org_key variable, then moving to the next record in your database and again reading the org_id into your $org_key variable - which overwrites the old value that you put in there.

The solution depends on what you are trying to achieve really. From your code, it appears to be a snippet from a function you have written. The function also appears to just pull the org_id of the specified $orgName from the database (in which case I would only expect one org_id to be returned).
Jun 28 '11 #3

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

Similar topics

11
by: menmysql | last post by:
i am getting the following error while connecting mysql database using jsp java.sql.SQLException: Communication link failure: Bad handshake can any one tell what is the actual problem
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
9
by: christopher_board | last post by:
Hi all. I am trying to connect to a MySQL Database using PHP on a local machine using locahost. I am using the following code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass =...
2
by: zalina | last post by:
hai..does anyone have example how to connect to mysql database using c++ language?
3
by: Suresh P | last post by:
Hi All, I tried to access the mysql database in ODBC using ip address and username/password. It returns, "cannot connect to MySQL server on IP ADDRESS(10060)". This could be related to Firewall...
2
by: maheshonmail | last post by:
i want to store pictures in mysql database using php code/ so please send me the most efficient code for doing this.
1
by: nadeenahmed | last post by:
I have Connected to a MySQL Database using a neatbeans editor. Now, I want to use that same database I created earlier on another pc. Can anyone help and tell me how that is done, please? Thank...
1
by: twinkle2010 | last post by:
Hi I am a new web programmer.I got an issue that reads the excel sheet data and store it to MYSQL database using php. I dont have any idea on that. can you help me?
6
by: mfaisalwarraich | last post by:
Hi everyone, I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP. I have looked at google and searched for it on...
1
by: santhanalakshmi | last post by:
Hi, I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made?...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.