Jump to content

craygo

Staff Alumni
  • Posts

    1,972
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by craygo

  1. craygo

    Confused

    I think I understand now. you can do a loop within a loop like so <?php $startdate='05/01/2008'; $enddate='05/30/2008'; $SQL1 = "SELECT DISTINCT Request_Group.RequestId AS reqid FROM Request_Group INNER JOIN Request_Date ON Request_Group.RequestId = Request_Date.RequestId WHERE Request_Date.DateFrom >= '$startdate' AND Request_Date.DateTo <= '$enddate'"; $result = mssql_query($SQL1); while ($requestids = mssql_fetch_array($result)) { $reqid = $requestids['reqid']; $SQL2 ="SELECT Request_Group.RequestId as reqid FROM Request_Group WHERE Request_Group.GroupName LIKE '%All Stations%' AND RequestId='$reqid'"; $result2 = mysql_query($SQL2) or die(mysql_error()); while($r = mssql_fetch_array($result2)){ echo $r['reqid']."<br />"; } } ?> Or store your first query results in an array and implode it <?php $startdate='05/01/2008'; $enddate='05/30/2008'; $SQL1 = "SELECT DISTINCT Request_Group.RequestId AS reqid FROM Request_Group INNER JOIN Request_Date ON Request_Group.RequestId = Request_Date.RequestId WHERE Request_Date.DateFrom >= '$startdate' AND Request_Date.DateTo <= '$enddate'"; $result = mssql_query($SQL1); while ($requestids = mssql_fetch_array($result)) { $req_id[] = $requestids['reqid']; } $req_ids = implode(", ", $req_id); $SQL2 ="SELECT Request_Group.RequestId as reqid FROM Request_Group WHERE Request_Group.GroupName LIKE '%All Stations%' AND RequestId IN ('$req_ids')"; $result2 = mysql_query($SQL2) or die(mysql_error()); while($r = mssql_fetch_array($result2)){ echo $r['reqid']."<br />"; } ?> Ray
  2. use a counter $i=1; while($r=mysql_fetch_assoc($result)){ echo $i." ".$r['field1']."<br />\n"; $i++; } Ray
  3. craygo

    Confused

    I guess I just don't get it because something like you want here: Will never happen because you already searched for "All Stations" so NONE of them will have London in them. Like I said before, the INNER JOIN is probably giving you more results than you want. Ray
  4. With checkboxes you have to be careful. If you do not check them they will not be passed. You will get an error when trying to use the value if it is not checked. 2 things you can do. 1.) use php to set value $Headquarters = isset($_POST['headquarters']) ? $_POST['headquarters'] : "0"; then use the query // Insert data into mysql $sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, headquarters) VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments', '$Headquarters')"; 2.) Set the default value for the field to "0" in MySQL, and do not try to insert a value for it in your query and it will be set to 0 when a new row is inserted. the use query // Insert data into mysql if(!isset($_POST['headquarters'])){ $sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments) VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments')"; } else { $sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, headquarters) VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments', '$Headquarters')"; } Personally I would use the 1st option, otherwise you will have to use an additional check to see if the value is set anyway. Ray
  5. craygo

    Confused

    So in the groupName field you can have All Stations AND London in the same field and row?? Cause if you are looking for All Stations in the GroupName then none of them will have London. Try using distinct SELECT DISTINCT Request_Group.RequestId FROM Request_Group INNER JOIN Request_Date ON Request_Group.RequestId = Request_Date.RequestId WHERE Request_Group.GroupName LIKE '%All Stations%' AND Request_Date.DateFrom >= '2008-05-01' AND Request_Date.DateTo <= '2008-05-31' Ray
  6. craygo

    Confused

    I guess I am confused now because it should work, maybe you should just use JOIN and not INNER JOIN. Why use INNER JOIN anyway?? Do you want just one of the rows to be returned for each RQ number?? Maybe an example would help, from the data you listed below, what do you expect to be returned?? Ray
  7. if you use headquarters[] you will get the error because it is an array. you have to get the array to a basic string to insert it. What does your form look like?? Are you just trying to insert numbers or strings for the check boxes?? Ray
  8. craygo

    Confused

    Of course not. I wasn't aware you had other data in the field $SQLrequestID = "SELECT Request_Group.RequestId FROM Request_Group INNER JOIN Request_Date ON Request_Group.RequestId = Request_Date.RequestId WHERE Request_Date.DateFrom >= '$startdate' AND Request_Date.DateTo <= '$enddate' AND (GroupName LIKE '%All Stations%' OR GroupName LIKE '%M-F%')"; i don't see a problem doing this with one query but if need be you should be able to do it with more Ray
  9. yes there is. but you need somewhere to show the results don't you?? Without a web server running how you going to show the results or the form. Unless you are going to write it to a file. you can write a php script then use the command line to run the script and access the file no problem, but you would have to save the results to a file if you do not have a web server running. Ray
  10. craygo

    Confused

    then use IN $SQLrequestID = "SELECT Request_Group.RequestId FROM Request_Group INNER JOIN Request_Date ON Request_Group.RequestId = Request_Date.RequestId WHERE Request_Date.DateFrom >= '$startdate' AND Request_Date.DateTo <= '$enddate' AND GroupName IN ('All Stations', 'M-F')"; Ray
  11. should be easy enough, you just have to give permission to the web account where the file is located. You need to have at least read permission to the folder which holds the file. What are the server specs? OS, Web server, php version??
  12. Is the web server on the same box as the file, or on the same network??
  13. You could read the file as long as it is accessible from the internet. Either through http or through FTP. Ray
  14. do you have some code? What code are you using to show the rows you wish to insert? Ray
  15. some code that you may have?? are you using mysql?? Is all you wanna do is show what they have put into the form fields?? Need a little more info on what you want to do. Ray
  16. read up on this http://www.phpfreaks.com/forums/index.php/topic,191541.0.html No you won't have to save the original image. You can use the second parameter in imagejpeg, imagepng or the others to save the generated image. Ray
  17. what are the names of the fields in the table??
  18. OK made the changes. I didn't add the inserts for the assessor and assessor ID you can do that in th FU_Results page for both the UPDATE query and the INSERT query AssessorLogIn.php <?php session_start(); if(isset($_POST['Assessor'])){ $_SESSION['Assessor'] = $_POST['Assessor']; // Post name from input field $_SESSION['AssessorID'] = $_POST['AssessorID']; $_SESSION['login'] = 1; // set the login to active or 1 header('Location:index_test.php'); // change this line to the page you want them to go to } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Novo Nordisk Selling Skills Recommended Follow-up</title> <link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" /> </head> <body> <form action="" method="post" > <table id="login"> <tr> <td align="center"> <table id="login2"> <tr class="input"> <td> <label for="Name">First and Last Name:</label><br /><br /> <input type="text" size="45" name="Assessor" id="accessor" /> </td> <td><img src="logo.png" alt="logo" /></td> </tr> <tr class="input"> <td> <label for="ID">Assessor ID:</label><br /><br /> <input type="text" size="45" name="AssessorID" id="accessor" /> </td> <td><input type="image" src="Submit.png" name="submit1" value="submit" alt="submit" id="submit" /></td> </tr> </table> </td> </tr> </table> </form> </body> </html> <?php } ?> index_test.php <?php session_start(); if(($_SESSION['login'] == 1) && isset($_SESSION['Assessor'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> Selling Skills Recommended Follow-up</title> <link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" /> </head> <body> <?php /*--------- DATABASE CONNECTION INFO--------- */ //set up table and database names $db_name ="DBName"; $grid_name ="grid"; $employee_table="employees"; $check_table = "emp_checks"; //connect to server and select database /*$connection = @mysql_connect( "localhost" , "UserName" , "PW" ) or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die (mysql_error() );*/ require('../config.php'); include('../includes/mysql.php'); //set the username post from login page $Assessor=$_SESSION['Assessor']; $AssessorID = $_SESSION['AssessorID']; $now = date("Y-m-d H:i:s"); $eid = @$_GET['emp_id']; //gather data from employee list $sql = "SELECT ID, Employee_Name, emp_id FROM $employee_table LEFT JOIN $check_table ON `ID` = `EmpID` ORDER BY ID ASC"; $result = mysql_query($sql) or die(mysql_error()); //begin building HTML table echo '<form action="" method="get">'; echo '<table id="main"> <tr id="header"><td colspan="2">'; if (isset($_SESSION['Assessor'])) { echo 'Welcome '.$Assessor.' '.$AssessorID.'<br /> Today is '.$now.'';} elseif (!isset($_SESSION['Assessor'])) { echo 'you are not logged in!'; } echo '</td>'; echo '<td><img src="novo-logo.png" alt="Novo Nordisk" /></td>'; echo ' </tr> <tr> <td>'; echo '<table id="employees"> <tr> <td> <select name="emp_id" onchange="this.form.submit()" /> '; while(list($id,$name,$emp_id) = mysql_fetch_row($result)){ // this will select the current employee int he dropdown box $selected = $id == $eid ? "selected" : ""; echo '<option value="'.$id.'" '.$selected.' />'.$name.' (' .$emp_id.')</option>'."\n"; $_SESSION['emp_name'] = $name; $_SESSION['emp_id'] = $id; } echo '</select> </td> </tr> </form> </table>'; // Get checkboxes from emp_checks table $ch = "SELECT Blocks FROM $check_table WHERE `EmpID` = '$eid'"; $cres = mysql_query($ch) or die(mysql_error()); $c = mysql_fetch_assoc($cres); // put the comma seperated values in an array $checks = explode(",", $c['Blocks']); //Build and issue query $sql="SELECT * from $grid_name ORDER BY Block"; $result = mysql_query($sql)or die(mysql_error()); // set the block groups $lastblock = ''; echo '<form name="Grid" action="FU_Results.php" method="POST" /> <input type="hidden" name="emp_id" value="'.$eid.'" /> <table id="matrix"> <tr> <th id="main" colspan="11"> Selling Skills Recommended Follow-up</th> </tr>'; while($row = mysql_fetch_assoc($result)){ // if the checkbox is in the array, check off the checkbox $chk = in_array($row['ID'], $checks) ? "checked" : ""; // checks to see if the block name has changed, if it has start a new row if($row['Block'] != $lastblock){ echo "<tr><td id='title'>".substr($row['Block'], 1)."</td>"; } echo '<td class="checkbox"><input type="checkbox" name="grid[]" value="'.$row['ID'].'" class="inactive" '.$chk.' /></td><td>'.$row['Text'].'</td>'."\n"; // set the lastblock to the current block in the loop $lastblock = $row['Block']; } echo '</tr></table> <div id="submit"><input type="image" src="Submit.png" name="submit" value="submit" alt="submit" class="SubmitButton" /></div>'; //end of HTML table echo '</td> </tr> </table> </form>'; ?> </body> </html> <? } else { // redirect them to the login page header('Location:AssessorLogIn.php'); } ?> FU_Results.php <?php session_start(); if(($_SESSION['login'] == 1) && isset($_SESSION['Assessor'])){ //connect to server and select database /*$connection = @mysql_connect( "localhost" , "UserName" , "PW" ) or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die (mysql_error() );*/ require('../config.php'); include('../includes/mysql.php'); $grid_name ="grid"; $employee_table="employees"; $check_table = "emp_checks"; //set the username post from login page $Assessor=$_SESSION['Assessor']; $Assessor_ID = $_SESSION['AssessorID']; $emp = $_SESSION['emp_name']; $emp_id = $_SESSION['emp_id']; $now = date("Y-m-d H:i:s"); // set the employee id $id = $_POST['emp_id']; // change the array to a comma seperated string for storage $blocks = implode(",", $_POST['grid']); // check if employee has an entry in the emp_checks table $check = "SELECT CheckID FROM $check_table WHERE EmpID = '$id'"; $cres = mysql_query($check) or die(mysql_error()); $found = mysql_num_rows($cres); if($found > 0){ // if an employee was found we update the check boxes $update = "UPDATE $check_table SET Blocks = '$blocks' WHERE `EmpID` = '$id'"; mysql_query($update) or die(mysql_error()); //echo $update; $message = 'Assessment Update results for '.$emp.', submitted by '.$Assessor.','.$Assessor_ID; } else { // If employee was not found we insert the checkboxes $insert = "INSERT INTO $check_table (`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$id', '$blocks', '$now')"; mysql_query($insert) or die(mysql_error()); //echo $insert; $message = 'Assessment insert results for '.$emp.', submitted by '.$Assessor.','.$Assessor_ID; } // run your code echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Novo Nordisk Selling Skills Recommended Follow-up Results page</title> <link rel="stylesheet" href="Global.css" type="text/css" media="screen, handheld" /> </head> <body> <table> <tr><th colspan=2>'.$message.'</th></tr> <tr> <td>Employee Name:'.$emp.'</td><td>Employee ID:'.$emp_id.'</td> </tr> </table> <table>'; $text = str_replace(",", "', '", $blocks); $lastblock = ""; $sql = "SELECT * FROM `grid` WHERE `ID` IN ('$text') ORDER BY `Block`"; //echo $sql; $res = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_assoc($res)){ if($r['Block'] != $lastblock){ echo ' <tr> <td colspan="2">'.$r['Block'].'</td> </tr>'; } echo ' <tr> <td width="10"> </td> <td width="490">'.$r['Text'].'</td> </tr> '; $lastblock = $r['Block']; } echo ' </table> </body> </html> '; } else { // redirect them to the login page header('Location:AssessorLogIn.php'); } ?> One of the problems we were having was we were using the $id variable in 2 places trying to get different values. I changed one of them to $eid. Ray
  19. Storing the image itself is not a good idea. I have had nothing but problem doing it. I prefer to store the image name or the name and path in the database and just use html to display the picture when needed. In any case, to store your image you would have to first save the image to the drive, then insert it into the database, then delete the file. You can save the image by adding a parameter to imagejpeg $path = "absolute/path/with/name.jpg"; imagejpeg($img_dst, $path); Ray
  20. The FU_Results page, Is that page you want to show after you click the submit button on the index_test page???
  21. correct!
  22. If you don't store the values in a session, they will not be available from page to page. If you set $name on a previous page it is not available to the next page unless you set it as a session or pass it through the url. so even though you set values on one page you have to set them again on the next page. If you want to post the code for all your pages and give me the names for each page I will look through them for you. Ray
  23. yes you can but now you are talking about re-structuring your tables. as rhodesa said you can make a table to hold the picture id and each catagory it is associated with. example structure pic_table pid = autoincrement unique id name = pic name blah blah blah color_table cid = autoincrement unique id pid = relates to the picure id color = color name so now you have pic03 with pid of 3 in the pic_table and pic04 with a pid of 4 in the color_table you would have some entries cid pid color 1 3 red 2 3 blue 3 3 green 4 4 blue 5 4 green Now you query the color_table to get your matches $sql = "SELECT `pic_table`.`name` AS `picname` FROM `pic_table` JOIN `color_table` ON `pic_table`.`pid` = `color_table`.`pid` WHERE `color_table`.`color` = 'red'"; the above query would return pic03 only bacause pic04 doesn't have an entry for red Ray
  24. not a very good idea to hold passwords in the session. Why not after the person is authenticated, you just set a value $_SESSION['auth'] = 1; Now just check to see if the value is set and a value of 1 if(isset($_SESSION['auth']) && $_SESSION['auth'] == 1){ // run code } else { // redirect to login page header('Location:login.php'); } Ray
  25. Problem is, what is some people have javascript disabled?! Using the function above you can do this $browser = browser_detection("browser"); if($browser != "mozilla"){ header('Location:http://somepage.html'); } else { // run your page below } ?> Ray
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.