[b]Need correct sql syntax for php script?[/b]
[b]Need correct sql syntax for php script?[/b]
(OP)
Pervasive 8.6
PHP v4.3.1
Apache v1.3.33
The following syntax works if I hardcode in the string value. However, if I use a variable, I get no results. I've tried using wildcards, i.e. %, both before and after the variable but get the same results. If I replace 'SOME NAME HERE' with '$sup_name', no results come back. I have confirmed that $sup_name has a valid name. Any suggestions?
$sup_name = trim($supervisor);
$dir_query = "SELECT lastname, firstname, ssn FROM soinc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'SOME NAME HERE'
UNION
SELECT lastname, firstname, ssn FROM topllc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'SOME NAME HERE'";
$dir_result = odbc_exec($connect_soinc, $dir_query);
$dir_row = odbc_fetch_row($dir_result);
PHP v4.3.1
Apache v1.3.33
The following syntax works if I hardcode in the string value. However, if I use a variable, I get no results. I've tried using wildcards, i.e. %, both before and after the variable but get the same results. If I replace 'SOME NAME HERE' with '$sup_name', no results come back. I have confirmed that $sup_name has a valid name. Any suggestions?
$sup_name = trim($supervisor);
$dir_query = "SELECT lastname, firstname, ssn FROM soinc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'SOME NAME HERE'
UNION
SELECT lastname, firstname, ssn FROM topllc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'SOME NAME HERE'";
$dir_result = odbc_exec($connect_soinc, $dir_query);
$dir_row = odbc_fetch_row($dir_result);
RE: [b]Need correct sql syntax for php script?[/b]
CODE
Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com
RE: [b]Need correct sql syntax for php script?[/b]
SELECT lastname, firstname, ssn FROM soinc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'JOHN SMITH' UNION SELECT lastname, firstname, ssn FROM topllc.upempl WHERE STATUS <> '3' AND SUPERVSR = 'JOHN SMITH'
This is exactly the same result as if I were to use the following and gives the same results, nothing.
CODE
Although if I hardcode 'JOHN SMITH' in the origianl sql statement, it returns records...
RE: [b]Need correct sql syntax for php script?[/b]
If the query is the same, you should be getting the same results.
Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com
RE: [b]Need correct sql syntax for php script?[/b]
CODE
<HTML>
<HEAD>
<TITLE>PHP Sample</TITLE>
</HEAD>
<BODY>
<?php
$conn=odbc_connect("Demodata","","","");
$simple = "ACC 101";
$sql="select * from class where name = '$simple'";
echo $sql;
$rs=odbc_exec($conn,$sql);
echo "<table border=1>\n";
$numfields = odbc_num_fields($rs);
for($i=1;$i<=$numfields;$i++){
$fn=odbc_field_name($rs,$i);
echo "<th>$fn</th>";
}
echo "\n";
while(odbc_fetch_row($rs)){
echo "<tr>\n";
for($i=1;$i<=$numfields;$i++){
$fv=odbc_result($rs,$i);
echo "<td>$fv</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<p>Number of Fields: $numfields</p>\n";
?>
</BODY>
</HTML>
Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com
RE: [b]Need correct sql syntax for php script?[/b]
Your script does work but only if I hardcode the string value in the sql statement. If I put the variable in, it doesn't populate the table. I have never encountered this situation so I am scratching my head. Still working on it, I'll post back when/if I get it worked out. Thanks for the help.
RE: [b]Need correct sql syntax for php script?[/b]
Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com
RE: [b]Need correct sql syntax for php script?[/b]
Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com