Jump to content

kahodges

Members
  • Posts

    42
  • Joined

  • Last visited

Everything posted by kahodges

  1. I am having some trouble getting the code below to pull dates from a database and echo: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT nickname, last_name, date_format(BirthDate,"%m/%d/%Y"), QuitDate FROM employees WHERE QuitDate is null AND MONTH(BirthDate) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH));"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td></td> <td></td> <td></td> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"nickname"); $f2=mysql_result($result,$i,"last_name"); $f3=mysql_result($result,$i,"date_format(BirthDate,"%m/%d/%Y")"); ?> It throws the error: Parse error: syntax error, unexpected '%'. But, the above query is valid and works in phpMyAdmin. Any help would be appreciated. Thanks in advance.
  2. I have the FPDF script where it prints out the 3 columns, but I need a little help with the code to get it to pull the first and last name with the suffix together out of mysql, and echo it to one column. This is the code I have now: $pdf=new PDF(); $pdf->AddPage(); //specify 3 columns $pdf->Image('images/mylogo.gif',100,0,10,10,'','http://www.mysite.com'); $pdf->AddCol('"first_name". "last_name". "suffix"',55,'Name','L'); $pdf->AddCol('nextel',30, 'Nextel','C'); $pdf->AddCol('cellphonenum',28,'Cell Number','R'); $prop=array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), 'color2'=>array(255,255,210), 'padding'=>2); $pdf->Table('SELECT first_name, last_name, suffix, nextel, cellphonenum from employees WHERE nextel is not null ORDER by employee_name'); $pdf->Output(); Can someone please let me know how I should code the line to combine the three mysql fields into one column and echo? The other two columns echo fine. Thanks in advance.
  3. I'm using the script at the link below: http://www.ros.co.nz/pdf/user.php I can get the pdf file to generate, but I'm having trouble figuring out how to get the mysql data to populate into the labels, the arrays, etc.. Here is the code I have so far: <?php ## include the class include ('class.label.inc'); ## connect to the database $host = 'localhost'; $user = 'myusername'; $password = 'mypassword'; $database = 'mydatabase'; $query = 'select * from employees'; //-------------------------------------------------- // open the connection to the db server $link = mysql_connect($host,$user,$password); // change to the right database mysql_select_db($database); // do the SQL query $query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY employee_name"; $result = mysql_query($query) or die('Error, query failed'); while($data[] = mysql_fetch_assoc($result)) {} ## choose a labeltype $labeltype="Av5160"; ## create a new instance of the class of that labeltype $label= new Clabel($labeltype); // initialize the array $data = array(); $info=array(1=>array('line1'=>'employee_name', 'line2'=>'street_address', 'line3'=>'', 'line4'=>'City'.'state'.'zip_code'),); reset($info); ## just to be sure ## make the labels! $label->makeLabel($info); ?> I'd really appreciate some help. Thanks.
  4. Trying to embed a wysiwyg editor into a php script. I have the wysiwyg showing on the page, but the form seems to show below the original form. The wysiwyg form doesn't submit the data to the database. Here is the code I have for the form: <?php function addrec() { ?> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><a href="moves.php">Home</a></td> </tr> </table> <hr size="1" noshade> <form enctype="multipart/form-data" onsubmit="editor1.prepareSubmit();" action="moves.php" method="post"> <p><input type="hidden" name="sql" value="insert"></p> <?php $row = array( "id" => "", "time" => "", "time_update" => "", "username" => "", "filename" => "", "text" => ""); showroweditor($row, false); ?> <script type="text/javascript"> var editor1 = new WYSIWYG_Editor('editor1'); editor1.display(); </script> <noscript> <p style="notSupported"> Your browser does not support Javascript with your current setings. I am unable to display the editor to you. Check your settings and enable Javascript, or use one of the supported web browsers (listed in the right column) to view this page for a demonstration. </p> </noscript> <p><input type="submit" name="action" value="Submit"></p> </form> <?php } ?> Here is the code for the entire php page: <?php require('/home/directory/public_html/HR2/header.php'); ?> <?php if (allow_access(administrators) != "yes") { include ('/home/directory/public_html/HR2/login.php'); //Check to see if the user is approved if (allow_access(verified) == "1") { include ('errorlogin.php'); exit; } if (allow_access(verified) != "0") { include ('sorry.php'); exit; } exit; } ?> You are logged in as <b><?php echo $_SESSION[user_name]; ?></b><br> Your email address is <b><?php echo $_SESSION[email]; ?></b> <?php if (isset($_GET["order"])) $order = @$_GET["order"]; if (isset($_GET["type"])) $ordtype = @$_GET["type"]; if (isset($_POST["filter"])) $filter = @$_POST["filter"]; if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"]; $wholeonly = false; if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"]; if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"]; if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"]; if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"]; if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"]; ?> <html> <head> <title>Moves List</title> <meta name="generator" http-equiv="content-type" content="text/html"> <link rel="stylesheet" type="text/css" href="crr.css"> <link rel="stylesheet" href="cwcalendar.css" type="text/css"> <script type="text/javascript"> var sundayFirst = true; var formatSplitter = "-"; var monthFormat = "mm"; var yearFormat = "yyyy"; var formatType = monthFormat+formatSplitter+"dd"+formatSplitter+yearFormat; </script> <script type="text/javascript" src="js/calendar.js"></script> <script type="text/javascript" src="js/editor.js"></script> </head> <body> <table class="bd" width="100%"><tr><td class="hr"><h2 align="center">My Script</h2></td></tr></table> <table width="100%"> <tr><img src="images/logo.gif"></tr> <tr> <td width="10%" valign="top"> <?php require "menu.php" ?> </td> <td width="5%"> </td> <td bgcolor="#e0e0e0"> </td> <td width="5%"> </td> <td width="80%" valign="top"> <?php $conn = connect(); $showrecs = 100; $pagerange = 10; $a = @$_GET["a"]; $recid = @$_GET["recid"]; $page = @$_GET["page"]; if (!isset($page)) $page = 1; $sql = @$_POST["sql"]; switch ($sql) { case "insert": sql_insert(); break; case "update": sql_update(); break; case "delete": sql_delete(); break; } switch ($a) { case "add": addrec(); break; case "view": viewrec($recid); break; case "edit": editrec($recid); break; case "del": deleterec($recid); break; default: select(); break; } if (isset($order)) $_SESSION["order"] = $order; if (isset($ordtype)) $_SESSION["type"] = $ordtype; if (isset($filter)) $_SESSION["filter"] = $filter; if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield; if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly; mysql_close($conn); ?> <table class="bd" width="100%"><tr><td class="hr">http://www.mysite.com</td></tr> <td><tr>By Me</td></tr></table> </body> </html> <?php function select() { global $a; global $showrecs; global $page; global $filter; global $filterfield; global $wholeonly; global $order; global $ordtype; if ($a == "reset") { $filter = ""; $filterfield = ""; $wholeonly = ""; $order = ""; $ordtype = ""; } $checkstr = ""; if ($wholeonly) $checkstr = " checked"; if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; } $res = sql_select(); $count = sql_getrecordcount(); if ($count % $showrecs != 0) { $pagecount = intval($count / $showrecs) + 1; } else { $pagecount = intval($count / $showrecs); } $startrec = $showrecs * ($page - 1); if ($startrec < $count) {mysql_data_seek($res, $startrec);} $reccount = min($showrecs * $page, $count); ?> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr><td>Move Schedule</td></tr> <tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr> </table> <hr size="1" noshade> <form action="moves.php" method="post"> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><b>Search</b> </td> <td><input type="text" name="filter" value="<?php echo $filter ?>"></td> <td><select name="filter_field"> <option value="">Search All</option> <option value="<?php echo "text" ?>"<?php if ($filterfield == "text") { echo "selected"; } ?>><?php echo htmlspecialchars("move schedule") ?></option> </select></td> <td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Whole words only</td> </td></tr> <tr> <td> </td> <td><input type="submit" name="action" value="Apply Search"></td> <td><a href="moves.php?a=reset">New Search</a></td> </tr> </table> </form> <hr size="1" noshade> <?php showpagenav($page, $pagecount); ?> <br> <table class="tbl" border="1" cellspacing="1" cellpadding="5"width="100%"> <tr> <td class="hr"> </td> <td class="hr"> </td> <td class="hr"> </td> <td class="hr"><a class="hr" href="moves.php?order=<?php echo "text" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("move schedule") ?></a></td> </tr> <?php for ($i = $startrec; $i < $reccount; $i++) { $row = mysql_fetch_assoc($res); $style = "dr"; if ($i % 2 != 0) { $style = "sr"; } ?> <tr> <td class="<?php echo $style ?>"><a href="moves.php?a=view&recid=<?php echo $i ?>">View</a></td> <td class="<?php echo $style ?>"><a href="moves.php?a=edit&recid=<?php echo $i ?>">Edit</a></td> <td class="<?php echo $style ?>"><a href="moves.php?a=del&recid=<?php echo $i ?>">Delete</a></td> <td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["text"]) ?></td> </tr> <?php } mysql_free_result($res); ?> </table> <br> <?php showpagenav($page, $pagecount); ?> <?php } ?> <?php function showrow($row, $recid) { ?> <table class="tbl" border="1" cellspacing="1" cellpadding="5"width="50%"> <tr> <td class="hr"><?php echo htmlspecialchars("move schedule")." " ?></td> <td class="dr"><?php echo htmlspecialchars($row["text"]) ?></td> </tr> </table> <?php } ?> <?php function showroweditor($row, $iseditmode) { global $conn; ?> <table class="tbl" border="1" cellspacing="1" cellpadding="5"width="50%"> <tr> <td class="hr"><?php echo htmlspecialchars("move schedule")." " ?></td> <td class="dr"><input type="text" name="text" value="<?php echo str_replace('"', '"', trim($row["text"])) ?>"></td> </tr> </table> <?php } ?> <?php function showpagenav($page, $pagecount) { ?> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><a href="moves.php?a=add">Add Record</a> </td> <?php if ($page > 1) { ?> <td><a href="moves.php?page=<?php echo $page - 1 ?>"><< Prev</a> </td> <?php } ?> <?php global $pagerange; if ($pagecount > 1) { if ($pagecount % $pagerange != 0) { $rangecount = intval($pagecount / $pagerange) + 1; } else { $rangecount = intval($pagecount / $pagerange); } for ($i = 1; $i < $rangecount + 1; $i++) { $startpage = (($i - 1) * $pagerange) + 1; $count = min($i * $pagerange, $pagecount); if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) { for ($j = $startpage; $j < $count + 1; $j++) { if ($j == $page) { ?> <td><b><?php echo $j ?></b></td> <?php } else { ?> <td><a href="moves.php?page=<?php echo $j ?>"><?php echo $j ?></a></td> <?php } } } else { ?> <td><a href="moves.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td> <?php } } } ?> <?php if ($page < $pagecount) { ?> <td> <a href="moves.php?page=<?php echo $page + 1 ?>">Next >></a> </td> <?php } ?> </tr> </table> <?php } ?> <?php function showrecnav($a, $recid, $count) { ?> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><a href="moves.php">Home</a></td> <?php if ($recid > 0) { ?> <td><a href="moves.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Previous Record</a></td> <?php } if ($recid < $count - 1) { ?> <td><a href="moves.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td> <?php } ?> </tr> </table> <hr size="1" noshade> <?php } ?> <?php function addrec() { ?> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><a href="moves.php">Home</a></td> </tr> </table> <hr size="1" noshade> <form enctype="multipart/form-data" onsubmit="editor1.prepareSubmit();" action="moves.php" method="post"> <p><input type="hidden" name="sql" value="insert"></p> <?php $row = array( "id" => "", "time" => "", "time_update" => "", "username" => "", "filename" => "", "text" => ""); showroweditor($row, false); ?> <script type="text/javascript"> var editor1 = new WYSIWYG_Editor('editor1'); editor1.display(); </script> <noscript> <p style="notSupported"> Your browser does not support Javascript with your current setings. I am unable to display the editor to you. Check your settings and enable Javascript, or use one of the supported web browsers (listed in the right column) to view this page for a demonstration. </p> </noscript> <p><input type="submit" name="action" value="Submit"></p> </form> <?php } ?> <?php function viewrec($recid) { $res = sql_select(); $count = sql_getrecordcount(); mysql_data_seek($res, $recid); $row = mysql_fetch_assoc($res); showrecnav("view", $recid, $count); ?> <br> <?php showrow($row, $recid) ?> <br> <hr size="1" noshade> <table class="bd" border="0" cellspacing="1" cellpadding="4"> <tr> <td><a href="moves.php?a=add">Add Record</a></td> <td><a href="moves.php?a=edit&recid=<?php echo $recid ?>">Edit Record</a></td> <td><a href="moves.php?a=del&recid=<?php echo $recid ?>">Delete Record</a></td> </tr> </table> <?php mysql_free_result($res); } ?> <?php function editrec($recid) { $res = sql_select(); $count = sql_getrecordcount(); mysql_data_seek($res, $recid); $row = mysql_fetch_assoc($res); showrecnav("edit", $recid, $count); ?> <br> <form enctype="multipart/form-data" action="moves.php" method="post"> <input type="hidden" name="sql" value="update"> <input type="hidden" name="xid" value="<?php echo $row["id"] ?>"> <?php showroweditor($row, true); ?> <p><input type="submit" name="action" value="Submit"></p> </form> <?php mysql_free_result($res); } ?> <?php function deleterec($recid) { $res = sql_select(); $count = sql_getrecordcount(); mysql_data_seek($res, $recid); $row = mysql_fetch_assoc($res); showrecnav("del", $recid, $count); ?> <br> <form action="moves.php" method="post"> <input type="hidden" name="sql" value="delete"> <input type="hidden" name="xid" value="<?php echo $row["id"] ?>"> <?php showrow($row, $recid) ?> <p><input type="submit" name="action" value="Confirm"></p> </form> <?php mysql_free_result($res); } ?> <?php function connect() { require('includes/config.php'); return $conn; } function sqlvalue($val, $quote) { if ($quote) $tmp = sqlstr($val); else $tmp = $val; if ($tmp == "") $tmp = "NULL"; elseif ($quote) $tmp = "'".$tmp."'"; return $tmp; } function sqlstr($val) { return str_replace("'", "''", $val); } function sql_select() { global $conn; global $order; global $ordtype; global $filter; global $filterfield; global $wholeonly; $filterstr = sqlstr($filter); if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%"; $sql = "SELECT `id`, `time`, `time_update`, `username`, `filename`, `text` FROM `moves`"; if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') { $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'"; } elseif (isset($filterstr) && $filterstr!='') { $sql .= " where (`text` like '" .$filterstr ."')"; } if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`"; if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype); $res = mysql_query($sql, $conn) or die(mysql_error()); return $res; } function sql_getrecordcount() { global $conn; global $order; global $ordtype; global $filter; global $filterfield; global $wholeonly; $filterstr = sqlstr($filter); if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%"; $sql = "SELECT COUNT(*) FROM `moves`"; if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') { $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'"; } elseif (isset($filterstr) && $filterstr!='') { $sql .= " where (`text` like '" .$filterstr ."')"; } $res = mysql_query($sql, $conn) or die(mysql_error()); $row = mysql_fetch_assoc($res); reset($row); return current($row); } function sql_insert() { global $conn; global $_POST; $sql = "insert into `moves` (`text`) values (" .sqlvalue(@$_POST["text"], true).")"; mysql_query($sql, $conn) or die(mysql_error()); } function sql_update() { global $conn; global $_POST; $sql = "update `moves` set `text`=" .sqlvalue(@$_POST["text"], true) ." where " .primarykeycondition(); mysql_query($sql, $conn) or die(mysql_error()); } function sql_delete() { global $conn; $sql = "delete from `moves` where " .primarykeycondition(); mysql_query($sql, $conn) or die(mysql_error()); } function primarykeycondition() { global $_POST; $pk = ""; $pk .= "(`id`"; if (@$_POST["xid"] == "") { $pk .= " IS NULL"; }else{ $pk .= " = " .sqlvalue(@$_POST["xid"], false); }; $pk .= ")"; return $pk; } ?> I'd really appreciate your help. Thanks in advance
  5. I'm trying to set up an e-mail notification as a reminder to let me know when a vehicle inspection is due, preferably a month in advance. When a date is one month prior to the date in the due_date inspection table, it should send the reminder. Your help would be greatly appreciated. I'm not sure how to code it to check the date and compare it to a date one month from now. I'm also not sure if I have the database schema set up correctly for the dates. I figure I could run a cron job once a day to run the script and to pull the reminder. Below is the php code and MySQL schema I have so far: <?php //calling PEAR Mailer require_once "Mail.php"; ?> //connect to the database <?php function connect() { require('includes/config.php'); return $conn; } ?> <?php // Make a MySQL query $query = "SELECT * FROM inspection"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); $from = "Server Database <admin@server.com>"; $to = "me <me@server.com>"; //$cc = "another person <another@server.com>"; $subject = "Vehicle Inspection Reminder"; $body = "echo "The following vehicle is due for inspection:; echo $row['vehicle']; if (!$conn) { die('Could not connect: ' . mysql_error()); } ?>"; $host = "mail.server.com"; $username = "username"; $password = "password"; $headers = array ('From' => $from, 'To' => $to, 'CC' => $cc, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> MySQL schema: `CREATE TABLE IF NOT EXISTS `inspection` ( `id` int(6) NOT NULL AUTO_INCREMENT, `vehicle` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `last_date` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `due_date` varchar(10) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `vehicle` (`vehicle`,`last_date`,`due_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;`
  6. We had them backwards, but it helped me understand more of what was going on, and got it working. Thank you, thank you, thank you. Here's the working code: <?php include 'config.php'; require_once 'Spreadsheet/Excel/Writer.php'; if ($QuitDate===false) { // Active employees $sql =" ( `QuitDate` is not null and trim(`QuitDate`) <> '' ) "; }else { // Terminated employees $sql =" ( `QuitDate` is null or trim(`QuitDate`) = '' ) "; } $query = "SELECT GevityNo, employee_name, Sex, nextel, ssNumber, BirthDate, Hire_Date, QuitDate, PayRate, street_address, City, state, zip_code, home_phone, cellphonenum FROM employees WHERE $sql ORDER BY `employee_name` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result);if($num_rows > 0) { $row_count = 1; while($row = mysql_fetch_array($result)){ if($row_count == 1) { // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); $format_bold =& $workbook->addFormat(); $format_bold->setBold(); // sending HTTP headers $workbook_name = $row['employees'] . 'phone_list.xls'; $workbook->send($workbook_name); // Creating a worksheet $worksheet =& $workbook->addWorksheet('phone_list'); // The actual data $worksheet->setColumn(0,0,30); $worksheet->setColumn(0,1,14); $worksheet->setColumn(0,2,14); $worksheet->setColumn(0,3,14); $worksheet->write(0, 0, 'Name', $format_bold); $worksheet->write(0, 1, 'Nextel', $format_bold, $format_left); $worksheet->write(0, 2, 'Home', $format_bold, $format_left); $worksheet->write(0, 3, 'Cell', $format_bold, $format_left); } $worksheet->write($row_count, 0, $row['employee_name']); $worksheet->write($row_count, 1, $row['nextel']); $worksheet->write($row_count, 2, $row['home_phone']); $worksheet->write($row_count, 3, $row['cellphonenum']); $row_count++; }} // Let's send the file $workbook->close(); //?>
  7. Can you help me with how to apply it to the initial query? Or adding logic inside the while loop, so this will work? Thanks for your help.
  8. I have a php script that will produce an Excel spread sheet from data stored in a mysql database. It works perfect. The problem I have is getting the script to not print or display a row if a certain field is empty. If a date is entered into the "Quitdate" field for an employee, then that employee is terminated, and we don't want to display his phone information on this spreadsheet. The code below is still producing the terminated employee's info. Here is the code I have so far: <?php include 'config.php'; require_once 'Spreadsheet/Excel/Writer.php'; $query = "SELECT GevityNo, employee_name, Sex, nextel, ssNumber, BirthDate, Hire_Date, QuitDate, PayRate, street_address, City, state, zip_code, home_phone, cellphonenum FROM employees ORDER BY `employee_name` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); if($num_rows > 0){ $row_count = 1; while($row = mysql_fetch_array($result)){ if($row_count == 1){ // if ($QuitDate===false) { // Active employees $sql .=" where ( `QuitDate` is null or trim(`QuitDate`) = '' ) "; } else { // Terminated employees $sql .=" where ( `QuitDate` is not null and trim(`QuitDate`) <> '' )"; } // if ($terminated===false // // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); $format_bold =& $workbook->addFormat(); $format_bold->setBold(); // sending HTTP headers $workbook_name = $row['employees'] . 'phone_list.xls'; $workbook->send($workbook_name); // Creating a worksheet $worksheet =& $workbook->addWorksheet('phone_list'); // The actual data $worksheet->setColumn(0,0,30); $worksheet->setColumn(0,1,14); $worksheet->setColumn(0,2,14); $worksheet->setColumn(0,3,14); $worksheet->write(0, 0, 'Name', $format_bold); $worksheet->write(0, 1, 'Nextel', $format_bold, $format_left); $worksheet->write(0, 2, 'Home', $format_bold, $format_left); $worksheet->write(0, 3, 'Cell', $format_bold, $format_left); } $worksheet->write($row_count, 0, $row['employee_name']); $worksheet->write($row_count, 1, $row['nextel']); $worksheet->write($row_count, 2, $row['home_phone']); $worksheet->write($row_count, 3, $row['cellphonenum']); $row_count++; } } // Let's send the file $workbook->close(); // ?>
  9. I'm running a php script I found for exporting Excel files, and have it working on one table on MySQL. I've formatted it to work with another table, and all I can get it to produce is gibberish on the screen. Here's the code in the script: <?php include 'includes/config.php'; require_once 'Spreadsheet/Excel/Writer.php'; $query = "SELECT date, 13-52, 13-53, 19-50, 19-54, 19-55, 19-56, 19-57, 19-58, 24-228, 24-237, 24-281 FROM equip_idle_grinders ORDER BY `date` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); if($num_rows > 0){ $row_count = 1; while($row = mysql_fetch_array($result)){ if($row_count == 1){ // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); $format_bold =& $workbook->addFormat(); $format_bold->setBold(); // sending HTTP headers $workbook_name = $row['equip_idle_grinders'] . 'grinders_idle_list.xls'; $workbook->send($workbook_name); // Creating a worksheet $worksheet =& $workbook->addWorksheet('equip_idle_grinders'); // The actual data $worksheet->setColumn(0,0,12); $worksheet->setColumn(1,1,10); $worksheet->setColumn(2,2,10); $worksheet->setColumn(3,3,10); $worksheet->setColumn(4,4,10); $worksheet->setColumn(5,5,10); $worksheet->setColumn(6,6,10); $worksheet->setColumn(7,7,10); $worksheet->setColumn(8,8,10); $worksheet->setColumn(9,9,10); $worksheet->setColumn(10,10,10); $worksheet->setColumn(11,11,10); $worksheet->write(0, 0, 'date', $format_bold); $worksheet->write(0, 1, '13-52', $format_bold); $worksheet->write(0, 2, '13-53', $format_bold); $worksheet->write(0, 3, '19-50', $format_bold); $worksheet->write(0, 4, '19-54', $format_bold); $worksheet->write(0, 5, '19-55', $format_bold); $worksheet->write(0, 6, '19-56', $format_bold); $worksheet->write(0, 7, '19-57', $format_bold); $worksheet->write(0, 8, '19-58', $format_bold); $worksheet->write(0, 9, '24-228', $format_bold); $worksheet->write(0, 10, '24-237', $format_bold); $worksheet->write(0, 11, '24-281', $format_bold); } $worksheet->write($row_count, 0, $row['date']); $worksheet->write($row_count, 1, $row['13-52']); $worksheet->write($row_count, 2, $row['13-53']); $worksheet->write($row_count, 3, $row['19-50']); $worksheet->write($row_count, 4, $row['19-54']); $worksheet->write($row_count, 5, $row['19-55']); $worksheet->write($row_count, 6, $row['19-56']); $worksheet->write($row_count, 7, $row['19-57']); $worksheet->write($row_count, 8, $row['19-58']); $worksheet->write($row_count, 9, $row['24-228']); $worksheet->write($row_count, 10, $row['24-237']); $worksheet->write($row_count, 11, $row['24-281']); $row_count++; } } // Let's send the file $workbook->close(); // ?> Here's a MySQL dump of the table: CREATE TABLE IF NOT EXISTS `equip_idle_excavator` ( `date` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL, `22-176` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-252` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-260` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-262` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-270` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-271` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-273` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-277` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-279` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-282` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, KEY `date` (`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Help would be greatly appreciated.
  10. Got it. It's working now. Thanks.
  11. I'm assuming you mean the line with the offending code? It's below: $sql = "SELECT * FROM (SELECT t1.`employee_name`, lp0.`employee_name` AS `lp_employee_name`, t1.`gevity_number`, lp1.`GevityNo` AS `lp_gevity_number`, t1.`reference_number`, t1.`claim_number`, t1.`date_entered`, t1.`accident_date`, t1.`accident_time`, t1.`accident_location`, lp7.`location_name` AS `lp_accident_location`, t1.`accident_description`, t1.`start_time_lost`, t1.`end_time_lost`, t1.`first_treat_physician`, t1.`first_treat_phy_phone`, t1.`first_treat_phy_address`, t1.`first_fax`, t1.`primary_treat_center`, t1.`primary_address`, t1.`primary_phone`, t1.`primary_fax`, t1.`claim_adj_name`, t1.`claim_adj_address`, t1.`claim_adj_phone`, t1.`claim_adj_email`, t1.`claim_adj_fax` FROM `accidents` AS t1 LEFT OUTER JOIN `employees` AS lp0 ON (t1.`employee_name` = lp0.) LEFT OUTER JOIN `employees` AS lp1 ON (t1.`gevity_number` = lp1.) LEFT OUTER JOIN `location` AS lp7 ON (t1.`accident_location` = lp7.)) subq"; Here is just the area of the above line showing up as the error: AS t1 LEFT OUTER JOIN `employees` AS lp0 ON (t1.`employee_name` = lp0.) LEFT OUTER JOIN `employees` AS lp1 ON (t1.`gevity_number` = lp1.) LEFT OUTER JOIN `location` AS lp7 ON (t1.`accident_location` = lp7.)) subq"; Here is the entire section of code: function sql_select() { global $conn; global $order; global $ordtype; global $filter; global $filterfield; global $wholeonly; $filterstr = sqlstr($filter); if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%"; $sql = "SELECT * FROM (SELECT t1.`employee_name`, lp0.`employee_name` AS `lp_employee_name`, t1.`gevity_number`, lp1.`GevityNo` AS `lp_gevity_number`, t1.`reference_number`, t1.`claim_number`, t1.`date_entered`, t1.`accident_date`, t1.`accident_time`, t1.`accident_location`, lp7.`location_name` AS `lp_accident_location`, t1.`accident_description`, t1.`start_time_lost`, t1.`end_time_lost`, t1.`first_treat_physician`, t1.`first_treat_phy_phone`, t1.`first_treat_phy_address`, t1.`first_fax`, t1.`primary_treat_center`, t1.`primary_address`, t1.`primary_phone`, t1.`primary_fax`, t1.`claim_adj_name`, t1.`claim_adj_address`, t1.`claim_adj_phone`, t1.`claim_adj_email`, t1.`claim_adj_fax` FROM `accidents` AS t1 LEFT OUTER JOIN `employees` AS lp0 ON (t1.`employee_name` = lp0.) LEFT OUTER JOIN `employees` AS lp1 ON (t1.`gevity_number` = lp1.) LEFT OUTER JOIN `location` AS lp7 ON (t1.`accident_location` = lp7.)) subq"; if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') { $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'"; } elseif (isset($filterstr) && $filterstr!='') { $sql .= " where (`lp_employee_name` like '" .$filterstr ."') or (`reference_number` like '" .$filterstr ."') or (`claim_number` like '" .$filterstr ."') or (`accident_date` like '" .$filterstr ."') or (`accident_time` like '" .$filterstr ."') or (`lp_accident_location` like '" .$filterstr ."') or (`accident_description` like '" .$filterstr ."') or (`start_time_lost` like '" .$filterstr ."') or (`end_time_lost` like '" .$filterstr ."') or (`first_treat_physician` like '" .$filterstr ."') or (`first_treat_phy_phone` like '" .$filterstr ."') or (`first_treat_phy_address` like '" .$filterstr ."') or (`first_fax` like '" .$filterstr ."') or (`primary_treat_center` like '" .$filterstr ."') or (`primary_address` like '" .$filterstr ."') or (`primary_phone` like '" .$filterstr ."') or (`primary_fax` like '" .$filterstr ."') or (`claim_adj_name` like '" .$filterstr ."') or (`claim_adj_address` like '" .$filterstr ."') or (`claim_adj_phone` like '" .$filterstr ."') or (`claim_adj_email` like '" .$filterstr ."') or (`claim_adj_fax` like '" .$filterstr ."')"; } if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`"; if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype); $res = mysql_query($sql, $conn) or die(mysql_error()); return $res; } Here is the sql for the two tables the code is trying to left outer join: -- Table structure for table `accidents` -- CREATE TABLE IF NOT EXISTS `accidents` ( `employee_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `gevity_number` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `reference_number` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_number` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `date_entered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `accident_date` date DEFAULT NULL, `accident_time` time DEFAULT NULL, `accident_location` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `accident_description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `start_time_lost` date DEFAULT NULL, `end_time_lost` date DEFAULT NULL, `first_treat_physician` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `first_treat_phy_phone` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `first_treat_phy_address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `first_fax` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `primary_treat_center` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `primary_address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `primary_phone` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `primary_fax` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_adj_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_adj_address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_adj_phone` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_adj_email` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `claim_adj_fax` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, UNIQUE KEY `employee_name` (`employee_name`), UNIQUE KEY `reference_number` (`reference_number`,`claim_number`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Dumping data for table `accidents` -- CREATE TABLE IF NOT EXISTS `employees` ( `GevityNo` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `employee_name` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL, `Sex` varchar(7) COLLATE utf8_unicode_ci NOT NULL, `MaritalStatus` varchar(11) CHARACTER SET latin1 NOT NULL DEFAULT '', `pr_deductions` varchar(13) CHARACTER SET latin1 DEFAULT NULL, `nextel` varchar(13) CHARACTER SET latin1 DEFAULT NULL, `ssNumber` varchar(13) CHARACTER SET latin1 DEFAULT NULL, `InsTypes` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `BirthDate` varchar(30) CHARACTER SET latin1 DEFAULT NULL, `Hire_Date` varchar(30) CHARACTER SET latin1 DEFAULT NULL, `QuitDate` varchar(30) CHARACTER SET latin1 DEFAULT NULL, `PayRate` varchar( COLLATE utf8_unicode_ci DEFAULT NULL, `eeoc` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL, `street_address` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `City` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `state` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `zip_code` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `home_phone` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `cellphonenum` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `dlnum` varchar(30) CHARACTER SET latin1 DEFAULT '', `Lic_expires` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `DOT_expiration` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `DLclass` varchar(12) CHARACTER SET latin1 DEFAULT NULL, `updatedon` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, `updatedby` varchar(255) CHARACTER SET latin1 DEFAULT '', UNIQUE KEY `GevityNo` (`GevityNo`), UNIQUE KEY `employee_name` (`employee_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Again, thanks.
  12. I'm working on building an employee database with php 5 and mysql 5.0. I'm getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LEFT OUTER JOIN `employees` AS lp1 ON (t1.`gevity_number` = lp1.) LEFT OUTER J' at line 1 Here is the code surrounding the offending error: $filterstr = sqlstr($filter); if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%"; $sql = "SELECT * FROM (SELECT t1.`employee_name`, lp0.`employee_name` AS `lp_employee_name`, t1.`gevity_number`, lp1.`GevityNo` AS `lp_gevity_number`, t1.`reference_number`, t1.`claim_number`, t1.`date_entered`, t1.`accident_date`, t1.`accident_time`, t1.`accident_location`, lp7.`location_name` AS `lp_accident_location`, t1.`accident_description`, t1.`start_time_lost`, t1.`end_time_lost`, t1.`first_treat_physician`, t1.`first_treat_phy_phone`, t1.`first_treat_phy_address`, t1.`first_fax`, t1.`primary_treat_center`, t1.`primary_address`, t1.`primary_phone`, t1.`primary_fax`, t1.`claim_adj_name`, t1.`claim_adj_address`, t1.`claim_adj_phone`, t1.`claim_adj_email`, t1.`claim_adj_fax` FROM `accidents` AS t1 LEFT OUTER JOIN `employees` AS lp0 ON (t1.`employee_name` = lp0.) LEFT OUTER JOIN `employees` AS lp1 ON (t1.`gevity_number` = lp1.) LEFT OUTER JOIN `location` AS lp7 ON (t1.`accident_location` = lp7.)) subq"; if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') { $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'"; } elseif (isset($filterstr) && $filterstr!='') { $sql .= " where (`lp_employee_name` like '" .$filterstr ."') or (`reference_number` like '" .$filterstr ."') or (`claim_number` like '" .$filterstr ."') or (`accident_date` like '" .$filterstr ."') or (`accident_time` like '" .$filterstr ."') or (`lp_accident_location` like '" .$filterstr ."') or (`accident_description` like '" .$filterstr ."') or (`start_time_lost` like '" .$filterstr ."') or (`end_time_lost` like '" .$filterstr ."') or (`first_treat_physician` like '" .$filterstr ."') or (`first_treat_phy_phone` like '" .$filterstr ."') or (`first_treat_phy_address` like '" .$filterstr ."') or (`first_fax` like '" .$filterstr ."') or (`primary_treat_center` like '" .$filterstr ."') or (`primary_address` like '" .$filterstr ."') or (`primary_phone` like '" .$filterstr ."') or (`primary_fax` like '" .$filterstr ."') or (`claim_adj_name` like '" .$filterstr ."') or (`claim_adj_address` like '" .$filterstr ."') or (`claim_adj_phone` like '" .$filterstr ."') or (`claim_adj_email` like '" .$filterstr ."') or (`claim_adj_fax` like '" .$filterstr ."')"; } if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`"; if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype); $res = mysql_query($sql, $conn) or die(mysql_error()); return $res; } Any help would be most appreciated. Thanks in advance.
  13. Thank you both very much for the quick replies. I tried yours MAdTechie, but still ended up with the same results. However, using Sasa's solution did the trick. Again, Thanks.
  14. I have a field used to display numerical data. I'm using it to display the amount of deductions used for payroll purposes. The field would require the numbers between 0 and 10. The problem I am running into is the field retaining and displaying zero once it's submitted through the form. All other numbers retain and display as they are supposed to. Example: In the field, I type in number 1 and submit. I go back to the same form, the field displays 1. If I go to the same form, and type in number 0 (zero), hit submit, the form comes back blank. I need the form to retain and display 0 (zero) if that's the number entered. Here is the code I am using: <td colspan="2"><input name="deduction" type="text" id="deduction" <?php if (!empty($deduction)) echo "value=\"$deduction\""; ?>><div class="highlight" id="inf_deduction"> The database field is set up as MySQL 5.0 - field, varchar 12, latin1_swedish_ci, no attributes, null, default null, no extras. Thanks in advance for your help.
  15. I have a problem when entering data into a field with a space in the middle, it only returns the first portion of the data. Example: I enter: any street The query returns: any I need it to return: any street Here is the code I'm using: <td colspan="2"><input name="street" type="text" id="street" <? if (!empty($street)) echo "value=$street" ?>> What else would I need to add to allow the entire data string to post to the database and be returned on the query? The mysql database field is set as varchar, (255), latin_1_swedish_ci, null set to yes, default set to null, with no extras. Thanks for your help in advance.
×
×
  • 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.