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

How to store a select menu value in a variable

Hello I am having an issue assigning a variable to a select box selection so that i can feed the variable back into future queries. Please see code below:

Expand|Select|Wrap|Line Numbers
  1. <select name="room" id="msg-room">
  2.                         <?php
  3.                         $query = mysql_query("SELECT * FROM rooms ORDER BY ROOM asc");
  4.                         while($data = mysql_fetch_assoc($query)) {
  5.                         ?>
  6.                         <option value="<?php echo $data["roomid"]; ?>"><?php echo $data["ROOM"]; ?></option>
  7.                         <?php } ?>
  8.                     </select>
The selection list loads and populates fine. I just need a way to assign $data["Room"] a variable so that I can insert it into the Heading of the page as well as back into a sql query that will return the number of users in a selected room.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         $query = mysql_query('SELECT * from user where room = $data[room] and account_status=1')
  3.             or
  4. die(mysql_error());
  5. $num_rows = mysql_num_rows($query);
  6. echo "$num_rows Users Online" 
Please help. Thank you
Nov 13 '12 #1
5 3106
lyodmichael
75 64KB
good day, use the [/code][//code] next time to show the code :) . by the way, you can use id to label the value.
Nov 13 '12 #2
The select box has an id=msg-room. How would I display the currently selected value as another page's heading?
Nov 13 '12 #3
Rabbit
12,516 Expert Mod 8TB
If it's part of the the form that gets submitted, it will be in the POST or GET data. You can then use the $_POST or $_GET arrays to access the data that was passed.
Nov 13 '12 #4
Thank you. Im sure that should make sense to someone more experienced but I am still not quite clear. Below is another portion of the code that monitors the selection in #msg-room. The portion of code does work because I am able to change rooms successfully. Im just having the toughest time trying to pass the selection on as a variable. I hope Im making sense. The site was (partially) built for me by a developer I hired and has now vanished so I am trying to familiarize myself with this code.


Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  $('#msg-room').change(function() {
  3.             change_room();
  4.             getChatText();
  5.         });
  6.  
  7.         function change_room() {
  8.             var room = $('#msg-room :selected').text();
  9.             $('#current_room').html(room);
  10.                 $('#ajax').load('ajax.php?type=change_room&room=' + escape(room) + '', function() {
  11.                 $('#chatbox-0').append($('#ajax').html());
  12.                 $('.newpost').fadeIn(300, function() {
  13.                     $(this).removeClass('newpost');        
  14.                 });    
  15.                 chat_div.scrollTop = chat_div.scrollHeight;                        
  16.             });    
  17.         }
  18.         change_room();
Nov 13 '12 #5
Rabbit
12,516 Expert Mod 8TB
The first thing to do when trying to understand code is to learn the basics. You should start with a tutorial, like this one. In the tutorial, it also shows you how to pass and retrieve values between pages.
Nov 14 '12 #6

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

Similar topics

0
by: work4u | last post by:
My case is from the client site web page, there is a select menu, on a form, which dynamically show all data from a database But the data under this select menu which need to follow a rule which...
3
by: PW | last post by:
I use a multi-select menu in an ASP so the user can pick several values. <select multiple name="lbErrorType" size="12"> However, after I have saved the records to the DB, and the user comes...
3
by: david | last post by:
Hello all, on a web page, i use php to create several associative arrays in javascript: subTab1 = new Object(); subTab1 = "value1"; subTab2 = new Object(); subTab2 = "value1";
7
by: ???????J | last post by:
Javascript may inquire the push down menu value, can I inquire the description? The following example, the variable($answer) can be get the menu1's value. For example, if I select first data,...
6
by: trope | last post by:
Does anyone have the code to clear all of the elements in a select menu? I've been having trouble with this following code: for (var i=0; i< 100; i++) document.addskill.cat2.options = null; ...
3
by: jojowebdev | last post by:
Picking up from Friday.. I am still having trouble creating the Select Menu option. I got parts of the correct syntax but it is still not creating the selected carrier as an option in the parent...
6
by: tuxedo | last post by:
I have a fixed html structure, where only one form and a simple select menu will exist on an html page, as follows: <form action="order" method="POST"> <select name="dinner"> <option...
1
by: tahirakramch | last post by:
Dear Experts I have a select menu lets say <select id="textAds" name="textAds" multiple="true" > <option value="3">Zingar Burger</option> <option value="5">Pakistani Biryani</option> ...
2
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...
1
by: LongWei | last post by:
Hi all, i got small select menu with codes that goes <select name="size" id="size" size ="2"> <option value="a">Less than 1 Megabyte</option> <option...
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: 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?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.