troubleshooting Question

Getting a value from a drop down list using php

Avatar of kanaMT
kanaMT asked on
PHPHTMLWeb DevelopmentJavaScript
10 Comments4 Solutions68 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Member_2_248744

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 4 Answers and 10 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 4 Answers and 10 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004