We help IT Professionals succeed at work.
Get Started

Getting a value from a drop down list using php

kanaMT
kanaMT asked
on
64 Views
Last Modified: 2016-03-19
Hi, I am new to PHP and need some help.

I have a small Admin Panel to be used for various options. On the fist page I have a Dashboard, the content of the Dashboard will depend on the Selected Company. The Company is a Drop down list read from MySQL Database. That part works just fine.

<?php 
echo '<form method="post">';
$rows = db_select("SELECT idcompany, company FROM company order by idcompany;"); 
if($rows === false) {
		    $error = db_error();
			echo "<ul class='error'>";
			echo "<li class='error'>Error : $error </li> ";
			echo "</ul>";			
		}
?><label>Company: &nbsp; </label><?php 
?><select id="Company" onChange=" onChange="location.reload()"> <?php 
	 foreach($rows as $row){
          echo "<option value='" . $row['idcompany'] ."'>" . $row['company'] ."</option>";
	 } 
  echo '</select>';
  
echo '</form>'; 
?> 

Open in new window


The issue is that depends on the Selected Company (company_id) the dashboard will display the content.

// SELECT * FROM notifications_vw where idcompany = $id_company

$id_company = $_GET['Company'];
$rows = db_select("SELECT * FROM notifications_vw where idcompany = $id_company"); 
if($rows === false) {
    $error = db_error();
	echo  $error;
}

Open in new window


Unfortunately this does not work for me, I have a problem reading the list value. Ideally I should read it by the Tag ID or something like this.

The ID of the Company should be available at all times. I mean at the moment of the display of dashboard, add new customer, or display any other element that where idcompany is in use.

On the other hand when I change the Company from the drop down list, the website should reload and new company_id to be used.

Any ideas please?
List.PNG
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 4 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE