View Full Version : PHP Help
Brettles1986
8th October 2013, 08:54
Anyone on here proficient in PHP that could lend a hand?
<?php
$conn = odbc_connect('CS_CRM','','');
$sql = "SELECT Person_no, firstname + ' ' + Surname AS AdvisorName FROM People where organisation_no is not null and active = 'Y' ORDER BY Firstname ASC";
$result = odbc_exec($conn, $sql) or die("SELECT Error: ".mysql_error());;
$id=$row["Person_no"];
$thing=$row["AdvisorName"];
echo "<table>";
echo "<form method=\"POST\" action=\"LTResult.php\">";
echo "<tr><th>Advisor Name</th></tr>";
echo "<tr><td><select name = \"AdvisorName\">";
$options.="<OPTION VALUE=\"$id\">".$thing."</option>";
while ($row=odbc_fetch_row($result))
{
echo "<option value=\".&options.\"</option>";
}
echo "</select>";
echo "<td><input type = \"submit\" value = \"Search\"></td></tr>";
echo "</form>";
echo "</table>";
?>
Why am I not getting results in my dropdown box?
I am getting a list of blank records yet the query works fine as I have run it in query analyzer.
Scott
8th October 2013, 11:11
I know nowt about PHP so i was only glancing to see if i could spot any irregular namings etc.. so i have no idea if the two i have highlighted below are relevant or not. Maybe i should stay out of this :P
echo "<table>";
echo "<form method=\"POST\" action=\"LTResult.php\">";
echo "<tr><th>Advisor Name</th></tr>";
echo "<tr><td><select name = \"AdvisorName\">";
$options.="<OPTION VALUE=\"$id\">".$thing."</option>";
while ($row=odbc_fetch_row($result))
{
echo "<option value=\".&options.\"</option>";
Brettles1986
8th October 2013, 12:30
I know nowt about PHP so i was only glancing to see if i could spot any irregular namings etc.. so i have no idea if the two i have highlighted below are relevant or not. Maybe i should stay out of this :P
LOL the parts you highlighted are the hmtl elements and are irrelevant to the php code really :hug:
Sorted it with this in the end:
<?php
$conn = odbc_connect('CS_CRM','','');
$sql = "SELECT Person_no, firstname + ' ' + Surname AS AdvisorName FROM People where organisation_no is not null and active = 'Y' ORDER BY Firstname ASC";
$result = odbc_exec($conn, $sql) or die("SELECT Error: ".mysql_error());;
echo "<table>";
echo "<form method=\"POST\" action=\"LTResult.php\">";
echo "<tr><th>Advisor Name</th></tr>";
echo "<tr><td><select name = \"Advisors\">";
while ($row=odbc_fetch_row($result))
{
$id = odbc_result($result,1);
$thing = odbc_result($result,2);
echo "<OPTION VALUE =\"$id\"]\>".$thing."</OPTION>";
}
echo "</select>";
echo "<td><input type = \"submit\" value = \"Search\"></td></tr>";
echo "</form>";
echo "</table>";
?>
Scott
8th October 2013, 12:53
bah here was me hoping the obvious may have been overlooked. Ill go back to spreadsheets
Brettles1986
8th October 2013, 12:57
bah here was me hoping the obvious may have been overlooked. Ill go back to spreadsheets
Cheers for the effort though.
Alex
8th October 2013, 13:11
If you can use odbc_fetch_object it will save a couple lines :)
<?php
$conn = odbc_connect('CS_CRM','','');
$sql = "SELECT Person_no, firstname + ' ' + Surname AS AdvisorName FROM People where organisation_no is not null and active = 'Y' ORDER BY Firstname ASC";
$result = odbc_exec($conn, $sql) or die("SELECT Error: ".mysql_error());;
echo "<table>";
echo "<form method=\"POST\" action=\"LTResult.php\">";
echo "<tr><th>Advisor Name</th></tr>";
echo "<tr><td><select name = \"Advisors\">";
while ($row=odbc_fetch_object($result))
{
echo '<OPTION VALUE="', $row->Person_no, '">', $row->AdvisorName, '</OPTION>';
}
echo "</select>";
echo "<td><input type = \"submit\" value = \"Search\"></td></tr>";
echo "</form>";
echo "</table>";
?>
Brettles1986
8th October 2013, 14:13
If you can use odbc_fetch_object it will save a couple lines :)
I can't for some reason. Probably because I am interfacing PHP with SQL as opposed to MYSQL.
Alex
8th October 2013, 15:02
I can't for some reason. Probably because I am interfacing PHP with SQL as opposed to MYSQL.
You using a local Access database?
Brettles1986
8th October 2013, 15:16
You using a local Access database?
Nope, access is not involved at all. Database is MS SQL.
vBulletin® v3.8.2, Copyright ©2000-2025, Jelsoft Enterprises Ltd.