473,405 Members | 2,379 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,405 software developers and data experts.

Getting Values from database in array format

119 100+
I have a table with only one field say p_code. for that field i have around 30 values like MMBF,TRED,TFRE,EDFC,TTRRE ect., to goes on.

I am trying to retrive all the values in the single query like this:
Expand|Select|Wrap|Line Numbers
  1. $sql_query_product = mysql_query("SELECT Product_Code FROM " . TABLE_PRODUCT_CODE . "");    
  2. while($row_pr = mysql_fetch_array($sql_query_product))
  3. {                      
  4. $product_code = array($row_pr['Product_Code']);
  5. }
  6.  
But i m getting the last value of that field.

Can anyone help me how to get all the values in a single array with comma seperated values.

Thanks in advance,

Regards,
Oct 6 '09 #1
4 4656
Markus
6,050 Expert 4TB
You're resetting the $product_code variable with each iteration. I recommend pushing the new value into an array like so:

Expand|Select|Wrap|Line Numbers
  1. $product_codes = array();
  2.  
  3. while (/* mysql */) {
  4.     $product_codes[] = // data
  5. }
  6.  
Oct 6 '09 #2
Atli
5,058 Expert 4TB
And, once you have them all in an array, if you want that as a comma-separated list, you can use implode.
Expand|Select|Wrap|Line Numbers
  1. $list = implode($product_codes, ",");
Oct 6 '09 #3
Dormilich
8,658 Expert Mod 8TB
info: some PHP classes allow you to directly save the result set into an array without further looping…
Oct 6 '09 #4
phpmagesh
119 100+
@Atli
Yeah,

This solved my problem,

Thanks

Regards,
Oct 6 '09 #5

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

Similar topics

9
by: madsgormlarsen | last post by:
Hi I need to test a field(colum) in a SQL database for for NULL values, and have done so in this way. $query = "SELECT j FROM Andersen"; $result = mysql_query($query, $link_id); $query_data...
3
by: Ben | last post by:
Hi all, This may sound easy but I'm having trouble assigning values to array element. My problem is as follows: m = for o in m: # Here first o is 'Peter'.. I want to do something like this:...
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
1
by: MattB | last post by:
OK, never mind my last post. It was easy enough to refer to the table the repeater is bound to, but I made a big, incorrect assumption in that post. In my last post I thought I was successfully...
2
by: Kiran Kumar Pinjala | last post by:
Hi, May be this is silly, or I just need a second pair eyes to look at this. I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code...
3
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a...
10
by: psbasha | last post by:
Hi, Dictionary works in getting values from the key values.But I would like to get keys from values. For example : d = {100: ,102: ,202: } d.get(102)
1
by: anwar7517525 | last post by:
Dearest how can i find three smallest values in array I solve it by sorting array in ASC Order then i print first three values but i want to another efficient way can you have any efficient way
3
by: nady | last post by:
Dear Techies, I have a code which retrieves values from database cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn) cmdSelectDr =...
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...
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.