PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello everyone
Can someone please help me popualte a drop down box from a ODBC database and add data from a database into a text box after someone has selected a database entry?
my current code is:
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
its still not working, maybe ignore the code above as i think its terribly wrong
can someone tell me how to read data from an ODBC database and produce a dropdown box from a database column? and then auto fill in 7 text boxes relating to the value selected from the drop down box?
e.g select customer ID, then customers address would be auto filled in
I would try executing that query in the console itself and verify the query is actually returning a result. Otherwise, I see no problem with this code.
May also want to verify your connection. maybe it's not even connecting.
if (PHP_VERSION >= '5.1.0RC1')
date_default_timezone_set('Europe/London');
$pf_time = strtotime("-14 days");
$startdate = date("Y-m-d", $pf_time);
$enddate = date("Y-m-d");
$connectionstring = odbc_connect("odbcdatabasee","username","password");
$query = "SELECT * FROM database WHERE DATE (BETWEEN '$startdate' AND '$enddate')" ;
$result = odbc_do($connectionstring, $query);
Works as I used the echo command during debugging to see if the variables hold any values, I then checked it against the database results, and it produced the correct results but after numerous attempts I cannot get the results into a drop down box!! Any more help is definitely appreciated!!
Start simple. Trash the idea of a drop down box (for the moment) and try echoing out the while loop to see if the query is doing anything. And throw in some error checking to be on the safe side.
<?php
if (PHP_VERSION >= '5.1.0RC1')
{
date_default_timezone_set('Europe/London');
}
$startdate = date("Y-m-d", strtotime("-14 days"));
$enddate = date("Y-m-d");
if (!$connectionstring = odbc_connect("odbcdatabasee","username","password"))
{
die('Could not connect to my database...');
}
$query = "SELECT * FROM database WHERE DATE (BETWEEN '$startdate' AND '$enddate')" ;
if(!$result = odbc_do($connectionstring, $query))
{
die('There was a database error in the query: ' . odbc_errormsg());
}
while ($row = odbc_fetch_row($result))
{
echo '<p>Testing out a data value: ' . $row['database_pk'] . '</p>';
}
?>
<?php
if (PHP_VERSION >= '5.1.0RC1')
{
date_default_timezone_set('Europe/London');
}
$startdate = date("Y-m-d", strtotime("-14 days"));
$enddate = date("Y-m-d");
if (!$connectionstring = odbc_connect("SageLine50v11","manager",""))
{
die('Could not connect to my database...');
}
$query = "SELECT * FROM GRN_ITEM WHERE DATE (BETWEEN '$startdate' AND '$enddate')" ;
if(!$result = odbc_do($connectionstring, $query))
{
die('There was a database error in the query: ' . odbc_errormsg());
}
while ($row = odbc_fetch_row($result))
{
echo '<p>Testing out a data value: ' . $row['GRN_NUMBER'] . '</p>';
}
?>
i just want to make sure that GRN_NUMBER is correct, GRN_NUMBER is the primary key column from the database or something else
i tested the above code and got 8 x "Testing out a data value: " rows on the page