Hi There,
Im really really pulling my hair out here, and was hoping you guys could help a really poor coder!

basically, I have a table with a list of contracts in it, and a table with a list of applications for each contract.

I can succesfully populate a list box with the contract name by using the following:

<form action="routing.php" action="post">
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("callrouting") or die(mysql_error()); 
$query="SELECT * FROM contracts";
$result = mysql_query($query);
echo '<select name="contract" onchange="this.form.submit()">';
while($nt=mysql_fetch_array($result)){
$name = $nt['name'];
echo '<option value="' . $name . '">' . $name . '</option>';
}
echo '</select>';
echo '</form>';
?>

However it doesnt do anything, it just takes me the routing.php page, its supposed to take to the routing page, but populated with all the fields from the selected contract in the listbox...

Here is the function thats supposed to do it:

//this is the function that retrieves the contract information, static at the moment, will be added a form or list box
function listcontract(){
//get the form data
 //$selectedcontract= $_POST['contract'];
//end form data
$getcontract= "select * from contracts WHERE name = 'Gatwick'";
$results = mysql_query($getcontract);
while($row = mysql_fetch_array($results))
{
  echo "<div id='header'>";
  echo "<h1>" .$row['name']." Call Routing Table </h1>";
  echo "</div>";
  echo "<div id='recordholder'>";
  echo "<div id='title'>" .$row['name'] ." Contract Information</div>";
  echo "<div id='logo'><img src='images/" .$row['logo']."' /><br /><span class='address'>".nl2br($row['address']) ."</span></div>";
  echo "<div id='address'>" . $row['servicenumber'] . "<br />" .$row['servicemailbox'] ."<br /><br /><span class='description'>" .$row['description']."</span></div>";
  echo "</div>";
  echo "<br clear='all' />";
  echo "<br />";
}}

as you can see Ive commented out the code and entered the contract name manually because its not working..

would really appreciate some help

Member Avatar for diafol

I take it that you actually call the function, e.g.:

listcontract();

But anyway this:

<form action="routing.php" action="post">

should be:

<form action="routing.php" method="post">

Yes I call the function, it just doesnt do anything and its driving me insane, all I need is too populate a listbox (done) then whatever is selected a query is executed with all the other fields in the table relating to the selected item..

Thanks for answering, and yes I changed that now!

ok, actually that did now select the contract and display correctly,
now all I need is the apps to display..

function listapp(){
 //get the form data and assign a variable
 $stuff= $_POST['contract'];
//end form data
$query="SELECT * FROM $stuff";
$result = mysql_query($query);
echo '<select name="app" onchange="this.form.submit()">';
while($nt=mysql_fetch_array($result)){
$name = $nt['name'];
echo '<option value="' . $name . '">' . $name . '</option>';
}
echo '</select>';
echo '<br />';
$query="select * from $stuff where appname='$name'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
  {
  echo "<div id='recordholder'>";
echo "<div id='database-heading'>". $row['appname'] . "</div>"."<div id='description'>" . $row['description'] . "</div>";
echo "<div id='opcatholder'><div id='opcatheader'>Operational Cataogories</div><div id='opcat'><span class='op'>OP CAT 1 - </span>".$row['opcat1'] ."</div><div id='opcat'>
<span class='op'>OP CAT 2 - </span>".$row['opcat2'] ."</div><div id='opcat'><span class='op'>OP CAT 3 - </span>".$row['opcat3'] ."</div></div>";
/*echo "<div id='routingheader'>Routing Information</div>";*/
echo"<div id='info'>".$row['info']."</div>";
echo "<div id='opcatholder'><div id='opcatheader'>Routing</div>".$row['routing']."</div>";
  echo "</div>";
  echo "<br clear='all' />";
  }
};

doesnt display at all...

Hi,

Just my guess, by glancing at your codes, aren't you supposed to post this name="app" to have some value for your second query?

Something like this


$whatever = $_POST;

and then on your query, it can be like this
$query="select * from $stuff where appname='$whatever'";

Notice I did not use $name, because you already used it on the earlier part of your script. I am afraid, I might just caused a naming collision. :).

basically, I think im using a circular reference, Im posting a variable $contrat to a page, which picks up the correct record (drop down list picks up all the contract names) this works fine, but on the same page, now that the contract has been selected, I need all the apps related to that contract, but its using the same variable,

ie . select * FROM contract_table WHERE contract = $contract
then im using a 2nd query using the same variable
select * FROM $contract where appname = $appname

im probably confusing you here! its hard to explain, i basically need 2 drop down lists, the second list is populated by the choice made on the first list..

how to create upload files into php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.