473,805 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to assign number values on select

ddtpmyra
333 Contributor
How can I assgined value to each row of my query result?
Example Book=1; Fruits=2; Animals=3
OR is there other way to do it?

thanks for your help!

Expand|Select|Wrap|Line Numbers
  1. echo "<tr><td><b>Categories:</b></td>"; 
  2.             $res=mysql_query("select cat_name  from categories order by cat_name"); 
  3.             if(mysql_num_rows($res)==0){ 
  4.             echo "there is no data in table.."; 
  5.             } else { 
  6.             echo "
  7.  
  8.             <td width='100%'><select name=\"catname\" id=\"catname\" value=\"$catname\" >"; 
  9.                         for($i=0;$i<mysql_num_rows($res);$i++) { 
  10.                         $row=mysql_fetch_assoc($res); 
  11.                         echo"<option value=\"$row[cat_name]\""; 
  12.                         if($catname==$row[cat_name]) 
  13.                         echo "selected"; 
  14.                         echo ">$row[cat_name]</option>"; 
  15.                         } 
  16.                         echo "</select><br></td></tr>"; 
  17.             } 
Sep 28 '09 #1
2 1873
TheServant
1,168 Recognized Expert Top Contributor
Where does the number come from? Is it in your database? Does it change (dynamic)?

If it's in your database, you could select it with your cat_name and include that in your loop.
If it's dynamic then you need a function in your loop to work out which one it is.

I couldn't really make out from your code what you are referring to. Do you want your value for each option to be a number instead of a name?
Sep 29 '09 #2
Atli
5,058 Recognized Expert Expert
Hey.

What column in your table serves as a Primary Key?

Ideally, the Primary Key would be an integer with Auto_Increment.
That creates a "row number" column which you can use if you need a number to go along with a row.
Sep 29 '09 #3

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

Similar topics

1
2641
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For example, my customer table has 1 million unique records, so the results of the following query are as such: select count(customer_nbr) from customer = 1,000,000 There is bit field in the customer table that denotes whether a
2
2481
by: RBohannon | last post by:
I'm using Access 2000 on Windows 2000. I have a DB of several exams and people who have taken them. I need to assign ranks to the people according to their scores (within each exam). I have a select query written like this: SELECT ., Count(.) AS Tally, . FROM
2
1844
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code to identify only those tables beginning with the letters "JA". Is this possible? Or, should I break down and manually type in all the table names?
7
2731
by: Chris Wertman | last post by:
I am so lost on this one. Dim Ary as Integer = New Integer(4) {0,1,2,3} FAILS with the error: Array initializer has 1 too few elements. So I try Dim Ary as Integer = New Integer(3) {0,1,2,3} Since arrays start at 0 (I am thinking)
1
7300
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction for the mailing event. set (fUpdateTS, fAddrType, fAccountID, fOpCode) = (select AddTS, UpdateTypeCode, AccountID, OpCode FROM
4
25514
by: Mahesh BS | last post by:
Hello, I need to write a query to find out a set of missing number in a given sequence. Eg : a Column in some table has the following data
12
2100
by: Danny Colligan | last post by:
In the following code snippet, I attempt to assign 10 to every index in the list a and fail because when I try to assign number to 10, number is a deep copy of the ith index (is this statement correct?). .... number = 10 .... So, I have to resort to using enumerate to assign to the list:
2
3157
by: Birky | last post by:
Assign the output of a select to a variable? I am unable to find a way to assign the results of an SQL statement to a variable. I know how to assign the SQL statement to a variable but again no luck assigning the results. I have the need to assign the primary key of a table, which is an auto number data type) therefore a numeric value. My select is very basic for I am just looking for the primary key where two options are met. "SELECT...
1
2743
by: FrozenDude | last post by:
Help! I'm a VBA newbie and am having trouble getting the array values retrieved from getRows into a series of individual variables. Here is the query: "Select parcelID, DueDate from tablename" I have the array populated with getRows and have the number of returned rows. I need to loop through the array - somehow - and assign the tow field to variavles numParcelID and newDuedate respectively so I can use
0
1286
by: riyap | last post by:
i understood the oracle procedure but only question is after executing the access db query, how do i assign those values(each field values) to the parameters iam passing into oracle procedure i.e value=??? how do i give the access fields values to oracle parameters and pass it sqlComm.Parameters.Add(New OracleParameter("name", OracleType.VarChar)).Value = value sqlComm.Parameters.Item("name").Direction =...
0
9718
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, 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...
0
9596
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,...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
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...
0
6876
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();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.