Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and Pull Down Menu with ODBC

Status
Not open for further replies.

kitfox69

Technical User
Aug 6, 2008
36
US
Ok I am working on some PHP pages that use ODBC commands to connect and display data from my Pervasive Database.

So far connecting and getting the data is working fine but now I am trying to populate a pull down menu with some query data and I can't seem to do so.

Here is my script thus far:

<?php
$conn = odbc_connect("HOMES", "", "");
$billdate = $_POST[ 'billdate' ];
$query = ("SELECT DISTINCT(sls_his_cust_id)
FROM sls_his
where sls_his_prchdat_alt = $billdate");
$result = odbc_exec($conn, $query);

echo "<FORM method=POST action=getcustdata.php>";
echo "<SELECT NAME=column_name>";
while($row = @odbc_fetch_array($result))
{
echo "<OPTION VALUE=\"$row[0]\">$row[0]</OPTION>";
}
echo "<INPUT TYPE=submit name=submit VALUE=\"Get Results\"></SELECT></FORM>";


odbc_close($conn);
?>

I get the menu but no data populates it?!?

Does anyone see what I have done wrong?
 
Code:
<INPUT TYPE=submit name=submit VALUE=\"Get Results\"></SELECT>

You can't have a submit button inside your drop down.

Code:
echo "[red]</SELECT>[/red]<INPUT TYPE=submit name=submit VALUE=\"Get Results\"></FORM>";


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ok I adjusted that and made some fixes to my script but still get no data to populate.

<?php
$conn = odbc_connect("HOMES", "", "");
$billdate = $_POST[ 'billdate' ];
$query = ("SELECT DISTINCT sls_his_cust_id FROM sls_his where sls_his_prchdat_alt = $billdate");
$result = odbc_exec($conn, $query);
$a1 = odbc_fetch_array($result);

echo "<FORM method=POST action=getcustdata.php>";
echo "<SELECT NAME=sls_his_cust_id>";
while($row = @odbc_fetch_array($a1))
{
echo "<OPTION VALUE=\"$row[0]\">$row[0]</OPTION>";
}
echo "</SELECT><INPUT TYPE=submit name=submit VALUE=\"Get Results\"></FORM>";
?>
 
Sorry wrong page to copy from... this is the current code:

<?php
$conn = odbc_connect("HOMES", "", "");
$billdate = $_POST[ 'billdate' ];
$query = ("SELECT DISTINCT sls_his_cust_id FROM sls_his where sls_his_prchdat_alt = $billdate");
$result = odbc_exec($conn, $query);

echo "<FORM method=POST action=getcustdata.php>";
echo "<SELECT NAME=sls_his_cust_id>";
while($row = @odbc_fetch_array($result))
{
echo "<OPTION VALUE=\"$row[0]\">$row[0]</OPTION>";
}
echo "</SELECT><INPUT TYPE=submit name=submit VALUE=\"Get Results\"></FORM>";
?>
 
Ok I got a little help from another member of the PHP mailing list.

Turns out you cannot use an associative array for a function of this nature... it just does not work... instead I had to substitute the actual column name for the 0s in the $row statements.
 
Yes, that would have been my next suggestion. Since fetch_array by nature returns column names and not numbered positions.

Glad you got it working.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks.

I need a little more help on this.

I need to take the selected CUSTID and push it to the next page... both pages are as seen below:

<?php
$conn = odbc_connect("HOMES", "", "");
$billdate = $_POST[ 'billdate' ];
$query = ("SELECT DISTINCT sls_his_cust_id FROM sls_his where sls_his_prchdat_alt = $billdate");
$result = odbc_exec($conn, $query);

echo "<form method=post action=getcustdata.php>";
echo "<SELECT name=sls_his_cust_id>";
while($row = @odbc_fetch_array($result))
{
echo "<OPTION VALUE=\"$row[sls_his_cust_id]\">$row[sls_his_cust_id]</OPTION>";
}
echo "</SELECT><INPUT TYPE=submit name=sls_his_cust_id VALUE=\"Get Data\"></FORM>";
?>

Next page:

<?php
$conn = odbc_connect("HOMES", "", "");
$sls_his_cust_id = $_POST[ 'sls_his_cust_id' ];
$query = ("SELECT sls_his_d2_nam,
cust_phone_no,
cust_phone_no_2,
cust_phone_no_3,
sls_his_invc_no,
sls_his_so_bdat,
sls_his_d2_adrs_1,
sls_his_d2_adrs_2,
sls_his_d2_city,
sls_his_d2_state,
sls_his_d2_zip_cod,
slm_nam,
sls_his_pft_ctr,
sls_his_prchdat_alt
FROM sls_his , cust , slm
where CUST_ID = SLS_HIS_CUST_ID
AND slm = sls_his_slm_1
and sls_his_cust_id = $sls_his_cust_id");
$result = odbc_exec($conn, $query);

odbc_result_all($result)

?>

I can't seem to get the variable to stick correctly.
 
You are naming your select box and your submit button the same thing, this effectively overwrites the value from the select box.

Name your submit something else.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top