"Array to string conversion" while writing MySQL output into a variable - php

I'm trying to write the output of a MySQL select into a variable. The problem is that i get the error "Array to String conversion".
$user = mysql_query("select username from user");
echo "<table border='1'>";
if (isset($_POST['winneron'])) {
echo "<tr>";
while ($printuser = mysql_fetch_array($user)) {
echo "<th align='center'>". $printuser['username'] . "</th>";
}
echo "</tr>";
$user = mysql_query("select username from user");
while ($printuser = mysql_fetch_array($user)) {
$games = mysql_query("SELECT s.spielid, date, team1, team2, sieger, wettid, u.userid, w.spielid, team
FROM user u, spiele s, wette w
WHERE u.userid = w.userid
AND u.username = '$printuser'
AND w.spielid = s.spielid"); <-- Error line
while ($printgames = mysql_fetch_array($games)) {
if ( $printgames['sieger'] == $printgames['team1'] ) {
echo "<tr><td align='center'><b>". strtoupper($printgames['sieger']) . "</b></td></tr>";
}
else {
echo "<tr><td align='center'>". strtoupper($printgames['sieger']) . "</td></tr>";
}
}
}
}

AND u.username = '$printuser' replace it with AND u.username = '".$printuser['username']."'

$printuser is a array and you are using it like a string

Related

Add more then two while loop in one while with multiple tables

I want to try multiple while in one while with multiple tables but it's doesn't work.
I have three table and I want a different-different value from table.
Here is my code.
$table1 = GROUPMASTER;
$table2 = LEDGERMASTER;
$table3 = TRANSECTIONMASTER;
$groupmasterdata = mysql_query("select * from $table1 WHERE groupname = 'Capital' OR groupname = 'Fund and Reserves' OR groupname = 'Long Term liabilities' OR groupname = 'Current Liabilities' ");
echo "<table align='center' border=1>";
echo "<tr>";
echo "<td colspan=2 style='text-align:center'><b> CAPITAL and LIABILITIES</b></td>";
echo "<td style='text-align:center'><b> Amount </b></td>";
echo "</tr>";
while($recored = mysql_fetch_array($groupmasterdata))
{
$onegroupname = $recored ['groupname'];
echo "<tr>";
echo "<td colspan=3><b>" . strtoupper($onegroupname) . "</b></td></tr>";
$groupnamelist = mysql_query("select groupname from $table1 WHERE under = '". $onegroupname ."'");
while($data = mysql_fetch_array($groupnamelist))
{
$gname = $data ['groupname'];
$getledgername = mysql_query("select ledgername from WHERE groupname = '". $gname ."'");
while($lname = mysql_fetch_array($getledgername))
{
$gettocashbal = mysql_query("select *, SUM(amount) AS totalto from $table3 WHERE voucherto = '". $ledgername ."'");
while($datato = mysql_fetch_array($gettocashbal))
{
$tototal = $datato['totalto'];
}
$getbycashbal = mysql_query("select *, SUM(amount) AS totalby from $table3 WHERE voucherby = '". $ledgername ."' ");
while($databy = mysql_fetch_array($getbycashbal))
{
$bytotal = $databy['totalby'];
}
$ledgertotal = $opbal - $tototal + $bytotal;
echo "<tr>";
echo "<td class='test'>" . $gname . "</td>";
echo "<td>Rs. $ledgertotal</td>";
echo "<td></td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td style='text-align:right'>Total</td>";
echo "<td></td>";
echo "<td>Rs.</td>";
echo "</tr>";
}
echo "</table>";
I want to try multiple while but doesn't work.
How can I solve these issues?
I tried different way to solve this...
//TABLE 1 = GROUPMASTER
$table1 = $_SESSION['table1'];
//TABLE 2 = LEDGERMASTER
$table2 = $_SESSION['table2'];
//TABLE 3 = TRANSECTIONMASTER
$table3 = $_SESSION['table3'];
echo "<table align='center' border=1>";
echo "<tr>";
echo "<td colspan=2 style='text-align:center'><b> CAPITAL and LIABILITIES</b></td>";
echo "<td style='text-align:center'><b> Amount </b></td>";
echo "</tr>";
echo "<tr>";
$liabilitytotal = 0;
echo "<td colspan=3><b>CAPITAL</b></td></tr>";
$categorytotal = 0;
$groupnamelist = mysql_query("select groupname from $table1 WHERE under = 'Capital'");
while($data = mysql_fetch_array($groupnamelist))
{
$grouptotal = 0;
$gname = $data ['groupname'];
echo "<tr>";
echo "<td class='test'>" . $gname . "</td>";
$ledgername = mysql_query("SELECT ledgername from $table2 WHERE groupname = '". $gname ."' ");
while($datato = mysql_fetch_array($ledgername))
{
$lname = $datato['ledgername'];
$getbytotalquery = mysql_query("SELECT SUM(amount) FROM $table3 WHERE voucherby = '". $lname ."' ");
$gettototalquery = mysql_query("SELECT SUM(amount) FROM $table3 WHERE voucherto = '". $lname ."' ");
$getopbal = mysql_result($getopbalquery,0,0);
$getbytotal = mysql_result($getbytotalquery,0,0);
$gettototal = mysql_result($gettototalquery,0,0);
$result = $getopbal - $gettototal + $getbytotal;
if ($result == null)
{
$result = 0;
}
$grouptotal = $grouptotal + $result;
}
$categorytotal = $categorytotal + $grouptotal;
echo "<td style='text-align:right'>$grouptotal</td><td></td></tr>";
}
$liabilitytotal = $liabilitytotal + $categorytotal;
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td style='text-align:right'>$categorytotal</td>";
echo "</tr>";
echo "</table>";```
I tried my best..
And I will try to also solve this query to another way...
Thank you.. I think and I hope It's helpful..

How to check if a result array element is present in another result array

I have this code in my program:
<?php
session_start();
$_SESSION['user_id']=201102887;
$con = mysqli_connect('localhost', 'root', '');
if(!$con)
{
die("not ok");
}
mysqli_select_db($con,"uoh");
$q = "SELECT * FROM courses
INNER JOIN transfer_student_courses
ON transfer_student_courses.course_number = courses.course_number
INNER JOIN transfered_courses
ON transfer_student_courses.sn = transfered_courses.sn
AND transfer_student_courses.student_ID = " . $_SESSION['user_id'];
$result = mysqli_query($con , $q);
if($result){
echo "<table>";
echo "<tr>";
echo "<th>equivalent</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row["equivalent"]. "</td>";
echo "</tr>";
}
echo "</table>";
}
mysqli_select_db($con,"uoh");
$q = "SELECT * FROM courses
LEFT JOIN degree_plan
ON degree_plan.course_number = courses.course_number
LEFT JOIN student_record
ON courses.course_number = student_record.course_number
AND student_record.id = ". $_SESSION['user_id']."
WHERE degree_plan.major = 'COE'
ORDER BY term_no";
$result = mysqli_query($con , $q );
if($result){
echo "<table>";
echo "<tr>";
echo "<th>course</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row["code"]. "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
I have two queries in this code, each of which give me a list of courses.
If a course appears in the first list, I do not want it to appear in the second list.
If you see the output of this code below, the first query gives me MATH 101, and the second query also gives me MATH 101.
I want MATH 101 to not appear in the second course list because it also appears in the first list.
How can I write a function in PHP language to do that?
Output:
equivalent
MATH 101
course
PHYS 101
CHEM 101
PE 101
IAS 101
MATH 101
ENGL 101
First of all, store all the equivalent courses in an array, say $equivalent array. And then in the second while loop use in_array() function to check if the course already got printed in the first table or not.
Here's the reference:
in_array()
So your code should be like this:
<?php
session_start();
$_SESSION['user_id']=201102887;
$con = mysqli_connect('localhost', 'root', '');
if(!$con){
die("not ok");
}
mysqli_select_db($con,"uoh");
$q = "SELECT * FROM courses INNER JOIN transfer_student_courses ON
transfer_student_courses.course_number=courses.course_number INNER
JOIN transfered_courses ON transfer_student_courses.sn=transfered_courses.sn
AND transfer_student_courses.student_ID = " . $_SESSION['user_id'];
$result = mysqli_query($con , $q) ;
$equivalent = array();
if($result){
echo "<table>";
echo "<tr>";
echo "<th>equivalent</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
$equivalent[] = $row["equivalent"];
echo "<tr>";
echo "<td>" . $row["equivalent"]. "</td>";
echo "</tr>";
}
echo "</table>";
}
mysqli_select_db($con,"uoh");
$q = "SELECT * FROM courses
LEFT JOIN degree_plan ON degree_plan.course_number= courses.course_number
LEFT JOIN student_record ON courses.course_number= student_record.course_number
AND student_record.id= ". $_SESSION['user_id']."
WHERE degree_plan.major='COE' ORDER BY term_no";
$result = mysqli_query($con , $q ) ;
if($result){
echo "<table>";
echo "<tr>";
echo "<th>course</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
if(in_array($row["code"], $equivalent)){
continue;
}
echo "<tr>";
echo "<td>" . $row["code"]. "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
You could load the results of the first query into an array, then when you are displaying the results for the second query, before you display anything check if the result exists in your array, if it does, skip it.
So after your first query:
$equivalent = array(); // Setup a blank array to store the results
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row["equivalent"]. "</td>";
echo "</tr>";
$equivalent[] = $row['equivalent']; // Add the result into your array
}
Then in your courses portion of code:
while($row = mysqli_fetch_array($result))
{
if ( ! in_array($row['code'], $equivalent ) )
{
echo "<tr>";
echo "<td>" . $row["code"]. "</td>";
echo "</tr>";
}
}
This should stop the display of any entry that is in both result sets being displayed in the second.
HTH
Solution : in_array("word", $array)
Run a query get the result into an array :
while($row = mysqli_fetch_array($result))
{
arr1[]=$row["code"];
}
For the second query run the query and add reults as follows:
while($row = mysqli_fetch_array($result)){
if (in_array($row[code], $arr1))
{
//don't add to array2
}
else
{
arr2[] = $row["code"];
}
}
Then you may echo the elements as required.

Single row repeating instead of displaying

I'm pretty new at PHP/MySQL, so please be patient with me.
I am trying to get a list of members in a table to show up on a page. Right now it's showing the first member about 10 times and not displaying anyone else's name. I DID have it working, but I don't know what happened. I just want it to display everyone's name once. Here is my code:
<?php $select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$row = mysql_fetch_array($select);
$rows = mysql_num_rows($select);
$teaching = $row[teaching];
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
$row2 = mysql_fetch_array($select2);
$student=$row2[student_name];
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
}
else {
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
$row3 = mysql_fetch_array($select3);
while($row2 = mysql_fetch_array($select2)) {
$house=$row3[house];
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>"; }
?>
I miss look on your code, since it is mess, but disregard the mysqli and mysql thing, you want to show how many student in the teacher's classes.
<?php $select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$row = mysql_fetch_array($select);
$rows = mysql_num_rows($select);
$teaching = $row[teaching]; <--- This only get first row of the course, if you want multiple course under same username, you need to loop it.
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
$row2 = mysql_fetch_array($select2);
$student=$row2[student_name]; <----- This only get the first row of the student name, if you want multiple student under a course, you need to loop it.
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
}
else {
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
$row3 = mysql_fetch_array($select3);
while($row2 = mysql_fetch_array($select2)) {
$house=$row3[house]; <----This only show the first row of $house under same student, so you need to loop it too.
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>"; }
?>
So what you really want to do is
<?php
$select = mysql_query("SELECT * FROM `member_staff` WHERE `username`='$_SESSION[USR_LOGIN]' AND `status`='Active'");
$rows = mysql_num_rows($select);
if ($rows==0){echo "Sorry, you don't appear to be a professor.";}
else { ?>
<?php }
while( $row = mysqli_fetch_array( $select ) ) {
$teaching = $row[teaching];
$select2 = mysql_query("SELECT * FROM `classes_enrolled` WHERE `course`='" . $teaching . "' ORDER BY `student_name`") or die(mysql_error());
$count = mysql_num_rows($select2);
if($count==NULL) {
echo "<table width=\"80%\">\n";
echo "<tr><td><center>Nobody has registered for your class yet!</center></td></tr>\n";
echo "</table>\n";
echo "<br /><br />\n\n";
} else {
while( $row2 = mysql_fetch_array($select2) ) {
$student=$row2[student_name];
echo "<center><font size=\"3\"><b>YEAR 1, TERM 2</b></font></center>";
echo "<table width=\"80%\" class=\"table-stripes\">\n";
echo "<tr><td width=\"50%\"><b>STUDENT</b></td></tr>\n";
$select3 = mysql_query("SELECT * FROM `members` WHERE `username`='" . $student . "'") or die(mysql_error());
while($row3 = mysql_fetch_array($select3)) {
$house=$row3[house];
echo "<tr><td><strong class=\"$house\">$student</strong></td></tr>";
}
echo "</table>";
}
} // END ELSE
}
} // END ELSE
?>

How to escape & and ' in mssql and Php?

I ma pretty sure I need something like a preg_replace in this situation but I am not sure and if so where to put it. I have a page that allows people to search an employee directory (PHP and MSSQL). They can search by last name, building or by department. the last name and building are fine but I have the problem with three of our departments, two have an & in them (ie. Grants & Planning) and when you click on that department it doesn't return any results and I think it is because it is not recognizing the "& planning" as part of a whole string. The other problem I have is that I have one department that has a ' in it and it throws an error
PHP Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near 's'. (severity 15) in C:\Inetpub\wwwroot\DACC\directory\dept.php on line 179
*PHP Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark before the character string ' ORDER BY Lastname'. (severity 15) in C:\Inetpub\wwwroot\DACC\directory\dept.php on line 179*
Line 179 is this...
$query = mssql_query("SELECT * FROM directory WHERE Displayname = '$department' ORDER BY Lastname");
Here is the rest of the code for the query page for by department.... if anyone can help me I would greatly appreciate it!
`
$department = $_GET['dept'];
// This will evaluate to TRUE so the text will be printed.
if (isset($department)) {
$query = mssql_query("SELECT * FROM directory WHERE Displayname = '$department' ORDER BY Lastname");//$query = mssql_query("SELECT * FROM directory WHERE department IN (SELECT id FROM departments WHERE name='$department') ORDER BY Lastname");
$query2 = mssql_query(
"SELECT TOP 1 directory.FirstName, directory.Lastname, directory.email,
directory.phone, directory.office, directory.title, directory.displayname, departments.id AS dept_id, departments.name AS dept_name, departments.url AS dept_url
FROM directory
INNER JOIN departments on directory.displayname = departments.name
WHERE directory.displayname = '$department'
ORDER BY directory.LastName");
$numofrows = #mssql_num_rows($query);
// Check if there were any records
if (!mssql_num_rows($query)) {
echo 'No records found';
echo '<br />Go Back';
} else {
while($row1 = mssql_fetch_array($query2))
{
$dept_var = $row1['dept_name'];
$dept_id = $row1['dept_id'];
$dept_url = $row1['dept_url'];
print "<h3>$dept_var</h3>";
}
print "<table id=\"directory_table\" width=\"480\">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Office</th>
<th>Title</th>
</tr>";
for($i = 0; $i < $numofrows; $i++)
{
$row = mssql_fetch_array($query);
if($i % 2)
{
print '<tr bgcolor="#ffffff">';
}
else
{
print '<tr bgcolor="#eeeeee">';
}
print "<td>" . $row['Firstname'] . " " . $row['Lastname'] . " </td>";
print "<td>" . $row['email']. " </td>";
print "<td>" . $row['phone'] . " </td>";
print "<td>" . $row['Office'] . " </td>";
print "<td>" . $row['Title'] . " </td>";
print "</tr>";
}
print "</table>";
}
// Free the query result
mssql_free_result($query);
}
else
print "No Search Defined";
?>
EDITED to show changes
ok tried this:
$serverName = "localhost"; //serverName\instanceName
$connectionInfo = array( "Database"=>"DACC", "UID"=>"daccweb", "PWD"=>"go");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
//$conn = sqlsrv_connect("connection string here");
$queryParams = array($department);
//Selector links
print "Go back to main search<br />";
print "<u>Search for Employees:</u><br /><br />\n";
print "<br />";
//$officeloc = $_GET['building'];
$department = $_GET['dept'];
// This will evaluate to TRUE so the text will be printed.
if (isset($department)) {
$query = sqlsrv_query($conn, "SELECT * FROM directory WHERE Displayname = ? ORDER BY Lastname", $params);
$query2 = sqlsrv_query($conn, "SELECT TOP 1 directory.FirstName, directory.Lastname, directory.email,
directory.phone, directory.office, directory.title, directory.displayname,
departments.id AS dept_id, departments.name AS dept_name, departments.url AS dept_url
FROM directory
INNER JOIN departments on directory.displayname = departments.name
WHERE directory.displayname = ?
ORDER BY directory.LastName", $params);
NEW EDIT
query runs but doesn't echo/print results
$query = sqlsrv_query($conn, "SELECT * FROM directory WHERE Displayname = ? ORDER BY Lastname", $params);
$query2 = sqlsrv_query($conn, "SELECT TOP 1 directory.FirstName, directory.Lastname, directory.email,
directory.phone, directory.office, directory.title, directory.displayname,
departments.id AS dept_id, departments.name AS dept_name, departments.url AS dept_url
FROM directory
INNER JOIN departments on directory.displayname = departments.name
WHERE directory.displayname = ?
ORDER BY directory.LastName", $params);
$numofrows = ##sqlsrv_has_rows($query);
// Check if there were any records
if (!#sqlsrv_has_rows($query)) {
echo 'No records found';
echo '<br />Go Back';
} else {
while($row1 = sqlsrv_fetch_array($query2))
{
$dept_var = $row1['dept_name'];
$dept_id = $row1['dept_id'];
$dept_url = $row1['dept_url'];
print "<h3>$dept_var</h3>";
//echo "</h3><br />";
}
print "<table id=\"directory_table\" width=\"480\">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Office</th>
<th>Title</th>
</tr>";
for($i = 0; $i < $numofrows; $i++)
{
$row = sqlsrv_fetch_array($query);
if($i % 2)
{
print '<tr bgcolor="#ffffff">';
}
else
{
print '<tr bgcolor="#eeeeee">';
}
print "<td>" . $row['Firstname'] . " " . $row['Lastname'] . " </td>";
print "<td>" . $row['email']. " </td>";
print "<td>" . $row['phone'] . " </td>";
print "<td>" . $row['Office'] . " </td>";
print "<td>" . $row['Title'] . " </td>";
print "</tr>";
}
print "</table>";
}
// Free the query result
sqlsrv_free_stmt($query);
}
else
print "No Search Defined";
You can use SQL parameters in PHP and MSSQL, have a look at this:
http://blogs.msdn.com/b/sqlphp/archive/2008/09/30/how-and-why-to-use-parameterized-queries.aspx
Your parameter values will automatically be escaped without any work on your part.
You'll need to use the sqlsrv driver, see: http://www.php.net/manual/en/sqlsrv.setup.php
In order to get the number of rows we need to specify some query options as well. (Take a look at http://www.php.net/manual/en/function.sqlsrv-num-rows.php and http://msdn.microsoft.com/en-us/library/hh487160.aspx)
$conn = sqlsrv_connect("connection string here");
$queryParams = array($department);
$queryOptions = array( "Scrollable" => "buffered" );
$query = sqlsrv_query($conn, "SELECT * FROM directory WHERE Displayname = ? ORDER BY Lastname", $queryParams, $queryOptions);
$query2 = sqlsrv_query($conn, "SELECT TOP 1 directory.FirstName, directory.Lastname, directory.email,
directory.phone, directory.office, directory.title, directory.displayname,
departments.id AS dept_id, departments.name AS dept_name, departments.url AS dept_url
FROM directory
INNER JOIN departments on directory.displayname = departments.name
WHERE directory.displayname = ?
ORDER BY directory.LastName", $queryParams, $queryOptions);
$numofrows = sqlsrv_num_rows($query);
Note that the order you build your array in must match the order in which the ? symbols appear in the query. As you only use one parameter in each query and they are the same, you only need to build one array.
You would then substitute all your mssql functions with sqlsrv functions, for a list of the functions and their usage, see the docs: http://www.php.net/manual/en/ref.sqlsrv.php

Troubleshooting "Notice: Undefined index" error

could anyone check my code why i get a notice like this?
Notice: Undefined index: id in C:\xampp\htdocs\HRPO\module\reports\jo\view_jo.php on line 76
line 76:
$id=$_GET['id'];
here is the first could of which I get my id:
<?php
echo "<dl>";
echo "<dt width = 200 id=\"label\">"."SSA"."</dt>";
echo "<dd align='right'>";
$result = mysql_query("SELECT ssa.first_name,ssa.SSA_ID
FROM staffing_specialist_asst ssa
left join jo_partner jp on jp.SSA_ID = ssa.SSA_ID
group by first_name") or die(mysql_error());
$dropdown = "<select name=\"SSA_ID\" style=\"position:relative; left:-51px;\">\n";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['SSA_ID']}'>{$row['first_name']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
echo "</dd>";
echo "</dl>";
?>
and the second code where line 76 is found:
<?php
$id=$_GET['id'];
if(isset($_POST['submit']))
{
$datefrom = $_POST['timestamp'];
$dateto = $_POST['timestamp1'];
//echo $option;
$_SESSION['datefrom'] = $datefrom;
$_SESSION['dateto'] = $dateto;
if(( $datefrom == NULL) || ($dateto == NULL)){
echo "<SCRIPT LANGUAGE='javascript'> confirmationError() ;</SCRIPT>";
exit();
}
$final =("SELECT distinct jp.receivedDate as rDate, ssa.first_name as saFName, ssa.last_name as saLName,job.client_order_number as joNum,
job.job_order_type as joType, job.job_title as joTitle, cl.name as clientName
,ss.first_name as ssFName,ss.last_name as ssLName,jp.acknowledgeDate as aDate, stat.status as stat
FROM staffing_specialist_asst ssa
left join jo_partner jp on ssa.SSA_ID = jp.SSA_ID
left join job_order job on jp.job_order_number = job.job_order_number
left join jo_status stat on job.job_order_number = stat.job_order_number
left join staffing_specialist ss on jp.SS_ID = ss.SS_ID
left join client cl on job.client_ID = cl.client_ID
where jp.receivedDate between '$datefrom1' and '$dateto1'
and ssa.SSA_ID='$id'
group by jp.receivedDate
order by jp.receivedDate asc");
echo $final;
$query = mysql_query($final);
echo "<table>";
while($row = mysql_fetch_array($query))
{
$rDate = $row['rDate'];
$saFName = $row['saFName'];
$saLName = $row['saLName'];
$joNum = $row['joNum'];
$joType = $row['joType'];
$joTitle = $row['joTitle'];
$clientName = $row['clientName'];
$ssFName = $row['ssFName'];
$ssLName = $row['ssLName'];
$aDate = $row['aDate'];
$stat = $row['stat'];
echo "<tr>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$rDate."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$saFName."".$saLName."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$joNum."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$joType."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$joTitle."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$clientName."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$ssFName."".$ssLName."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$aDate."</td>";
echo "<td width='150' colspan=\"1\" align=\"center\">".$stat."</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Thanks in advance for all the suggestions and help.
$_GET['id'] expected the get variable 'id' in the url (i.e. www.google.com?id=4 then $_GET['id'] would equal 4).
In order to avoid this you could do this before checking the get value if (! empty($_GET)) {$id = $_GET['id']}
EDIT: The actual error ended up being the assumption of needing to use $_GET instead of the possibility of $_POST for form data.
Looks like the select box is SSA_ID but you are using a $_GET['id'], try changing it to $_GET['SSA_ID'];

Categories