Jump to content

brandon66

Members
  • Posts

    23
  • Joined

  • Last visited

brandon66's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. When you send the image back try sending it like this, not familiar with jpgraph yet $image = $graph->stroke(); echo $image;
  2. you should look into jquery ajax its fairly easy. heres an example. Other suggestions for you is to use PDO or MySQLi for your php <?php // check that $_GET["str"] exists (ajax request has started) if(isset($_GET["str"])) { mysql_connect('localhost', 'root', ''); mysql_select_db("sample"); $str = mysql_real_escape_string($_GET['str']); $sql= "SELECT * FROM user WHERE id = '".$str."'"; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close(); exit; //We only need to echo out the data we need for the request (this will be the response) } ?> <html> <head> <script src="//code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $('#users').change(function(){ var user = $('#users').val(); showUser(user); }); }); function showUser(str){ if (str === "") { //hide the div $('#txtHint').hide(); }else{ //send str to php and get back data $.post('getuser.php', {str: str}, function(data) { //output data into the empty div //this could also be your txthint div $('div#table').html(data); }); } } </script> </head> <body> <form> <select name="users" id="users"> <option value="">Select a person:</option> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select> </form> <br/> <div id="txtHint"> <b>Person info will be listed here.</b> </div> <div id="table"></div> </body> </html>
  3. could you post the garbled text that your getting?
  4. If you like to read this is a great book to begin with (PHP & MySQL: Novice to Ninja) by sitepoint.
  5. Try this maybe? <?php if(isset($_POST['host'])) { $host = htmlspecialchars($_POST['host']); echo "My hostname is" . $host; }else{ echo "Not receiving POST variable"; } ?> Otherewise it seems like your locahost or host variable is not getting set.
  6. So you want to refresh the page with Ajax instead of the meta tag? maybe something like this <script type="text/javascript">// <![CDATA[ $(document).ready(function() { $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh setInterval(function() { $('#divToRefresh').load('/image/path/here'); }, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds. }); // ]]></script>
  7. How about something like this <promo1>D123OO</promo1> <promo2>M876TT</promo2> <promo3>B765DC</promo3> <promo4>LO122M</promo4> I beleive it can be done like this also <promo>D123OO</promo> <promo>M876TT</promo> <promo>B765DC</promo> <promo>LO122M</promo> //Then you can reference it like $xml->customers->promo[1]; $xml->customers->promo[2]; $xml->customers->promo[3]; $xml->customers->promo[4];
  8. Alright i am using PHP,Jquery, and MySql for this application its like an employee in/out status board with notes. I threw it together pretty quick just wondering if any would optimize it for me or tell me how i can optimize it. (like i said i just threw it together it works but the code its ugly!!) attached is the database i use for it and the application Will be very thankful for the help. Status backup 11-20-2013.zip
  9. ended up fixing it with this!! <?php //connect to database include '../../Model/DBAdapter.php'; $aColumns = array( 'RMA_Number', 'Person_Calling', 'Company_Name', 'Unit_Serial_Number', 'CONCAT(e.Employee_First_Name, " ", e.Employee_Last_Name)', 'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install', 'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name'); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "RMA_Number"; /* DB table to use */ $sTable = "RMA"; //Join to use $sJoin = ' JOIN Companies ON RMA.Company_ID = Companies.Company_ID'; $sJoin .= ' JOIN Employees e ON RMA.Employee_ID = e.Employee_ID'; /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". intval( $_GET['iDisplayLength'] ); } /* * Ordering */ $sOrder = ""; if ( isset( $_GET['iSortCol_0'] ) ) { $sOrder = "ORDER BY "; for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) { if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", "; } } $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { $sOrder = ""; } } /* * Filtering * NOTE this does not match the built-in DataTables filtering which does it * word by word on any field. It's possible to do here, but concerned about efficiency * on very large tables, and MySQL's regex functionality is very limited */ $sWhere = ""; if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) { $sWhere = "WHERE ("; for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" ) { $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars( $_GET['sSearch'] )."%' OR "; } } $sWhere = substr_replace( $sWhere, "", -3 ); $sWhere .= ')'; } /* Individual column filtering */ for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' ) { if ( $sWhere == "" ) { $sWhere = "WHERE "; } else { $sWhere .= " AND "; } $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars($_GET['sSearch_'.$i])."%' "; } } /* * SQL queries * Get data to display */ $sQuery = " SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . " FROM $sTable $sJoin $sWhere $sOrder $sLimit "; try { $rResult = $connection->query($sQuery); } catch (PDOException $e) { $error = 'Error getting data: ' . $e->getMessage(); echo $error; exit(); } /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; try{ $rResultFilterTotal = $connection->query($sQuery); $aResultFilterTotal = $rResultFilterTotal->fetch(); $iFilteredTotal = $aResultFilterTotal[0]; }catch (PDOException $e) { $error = 'Error getting found rows: ' . $e->getMessage(); echo $error; exit(); } /* Total data set length */ $sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable "; $rResultTotal = $connection->query($sQuery); $aResultTotal = $rResultTotal->fetch(); $iTotal = $aResultTotal[0]; /* * Output */ $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); while ( $aRow = $rResult->fetch()) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if (!empty($aColumns[$i]) ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $output['aaData'][] = $row; } echo json_encode($output);
  10. i am now getting undefined index error when trying to run this c. company_name otherwise the json is good <?php //connect to database include '../../Model/DBAdapter.php'; $aColumns = array( 'RMA_Number', 'Person_Calling', 'c.Company_Name', 'Unit_Serial_Number', 'CONCAT(e.Employee_First_Name, " ", e.Employee_Last_Name)', 'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install', 'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name'); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "RMA_Number"; /* DB table to use */ $sTable = "RMA"; //Join to use $sJoin = 'JOIN Companies c ON RMA.Company_ID = c.Company_ID'; $sJoin .= ' JOIN Employees e ON RMA.Employee_ID = e.Employee_ID'; /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". intval( $_GET['iDisplayLength'] ); } /* * Ordering */ $sOrder = ""; if ( isset( $_GET['iSortCol_0'] ) ) { $sOrder = "ORDER BY "; for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) { if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", "; } } $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { $sOrder = ""; } } /* * Filtering * NOTE this does not match the built-in DataTables filtering which does it * word by word on any field. It's possible to do here, but concerned about efficiency * on very large tables, and MySQL's regex functionality is very limited */ $sWhere = ""; if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) { $sWhere = "WHERE ("; for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" ) { $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars( $_GET['sSearch'] )."%' OR "; } } $sWhere = substr_replace( $sWhere, "", -3 ); $sWhere .= ')'; } /* Individual column filtering */ for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' ) { if ( $sWhere == "" ) { $sWhere = "WHERE "; } else { $sWhere .= " AND "; } $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars($_GET['sSearch_'.$i])."%' "; } } /* * SQL queries * Get data to display */ $sQuery = " SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . " FROM $sTable $sJoin $sWhere $sOrder $sLimit "; try { $rResult = $connection->query($sQuery); } catch (PDOException $e) { $error = 'Error getting data: ' . $e->getMessage(); echo $error; exit(); } /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; try{ $rResultFilterTotal = $connection->query($sQuery); $aResultFilterTotal = $rResultFilterTotal->fetch(); $iFilteredTotal = $aResultFilterTotal[0]; }catch (PDOException $e) { $error = 'Error getting found rows: ' . $e->getMessage(); echo $error; exit(); } /* Total data set length */ $sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable "; $rResultTotal = $connection->query($sQuery); $aResultTotal = $rResultTotal->fetch(); $iTotal = $aResultTotal[0]; /* * Output */ $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); while ( $aRow = $rResult->fetch()) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( $aColumns[$i] != ' ' ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $output['aaData'][] = $row; } echo json_encode( $output ); ?>
  11. This is what i came up with for the code but i get a json error when trying to run it <?php //connect to database include 'Model/DBAdapter.php'; $aColumns = array( 'RMA_Number', 'Person_Calling', 'c.Company_Name', 'Unit_Serial_Number', 'Employee_Name', 'Call_Date','Received_Date','RMA_Status','Reason_For_Return','Notes','New_Install', 'New_Unit_Serial_Number', 'Terminal_ID','Account_Number','Account_Name'); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "RMA_Number"; /* DB table to use */ $sTable = "RMA"; //Join to use $sJoin = 'JOIN Companies c ON RMA.Company_ID = Companies.Company_ID'; $sJoin .= ' JOIN Employees e ON RMA.Employee_ID = Employees.Employee_ID'; /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". intval( $_GET['iDisplayLength'] ); } /* * Ordering */ $sOrder = ""; if ( isset( $_GET['iSortCol_0'] ) ) { $sOrder = "ORDER BY "; for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) { if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", "; } } $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { $sOrder = ""; } } /* * Filtering * NOTE this does not match the built-in DataTables filtering which does it * word by word on any field. It's possible to do here, but concerned about efficiency * on very large tables, and MySQL's regex functionality is very limited */ $sWhere = ""; if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) { $sWhere = "WHERE ("; for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" ) { $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars( $_GET['sSearch'] )."%' OR "; } } $sWhere = substr_replace( $sWhere, "", -3 ); $sWhere .= ')'; } /* Individual column filtering */ for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' ) { if ( $sWhere == "" ) { $sWhere = "WHERE "; } else { $sWhere .= " AND "; } $sWhere .= $aColumns[$i]." LIKE '%". htmlspecialchars($_GET['sSearch_'.$i])."%' "; } } /* * SQL queries * Get data to display */ $sQuery = " SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . " FROM $sTable $sJoin $sWhere $sOrder $sLimit "; try { $rResult = $connection->query($sQuery); } catch (PDOException $e) { $error = 'Error getting data: ' . $e->getMessage(); echo $error; exit(); } /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; try{ $rResultFilterTotal = $connection->query($sQuery); $aResultFilterTotal = $rResultFilterTotal->fetchAll(); $iFilteredTotal = $aResultFilterTotal[0]; }catch (PDOException $e) { $error = 'Error getting found rows: ' . $e->getMessage(); echo $error; exit(); } /* Total data set length */ $sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable "; $rResultTotal = $connection->query($sQuery); $aResultTotal = $rResultTotal->fetchAll(); $iTotal = $aResultTotal[0]; /* * Output */ $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); while ( $aRow = $rResult->fetchAll()) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( $aColumns[$i] != ' ' ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $output['aaData'][] = $row; } echo json_encode( $output ); ?>
  12. The part where im stuck is that im using PDO and im also joining table, just not sure where i should start with that.
  13. Hello i was wondering if anyone could help convert my datatable over to the server side datatables. I attached my full code for the datatable php //connect to database include 'Model/DBAdapter.php'; //create sql statement $sql = "SELECT RMA_Number, Person_Calling, Company_Name, Unit_Serial_Number, CONCAT(Employee_First_Name,' ',Employee_Last_Name) AS Employee_Name, Call_Date,Received_Date,RMA_Status, Reason_For_Return, Notes, New_Install, New_Unit_Serial_Number, Terminal_ID, Account_Number, Account_Name FROM RMA JOIN Companies ON RMA.Company_ID = Companies.Company_ID JOIN Employees ON RMA.Employee_ID = Employees.Employee_ID"; //Retrieve data $result = $connection->query($sql); //process results if ($result) { //loop through data while ($view = $result->fetch()) { $views[] = $view; } //display include 'View/View.html.php'; } else { //error message $output = "No RMA found in database."; include 'View/Template.html.php'; } <body> <div id="wrapper"> <h1 id="tableTitle">RMA's Submitted</h1> <table id="table"> <thead> <tr> <th>RMA Number</th> <th>Person Calling</th> <th>Company ID</th> <th>ISN</th> <th>Employee</th> <th>Call Date</th> <th>Received Date</th> <th>RMA Status</th> <th>Reason for Return</th> <th>Notes</th> <th>New Install</th> <th>New Serial Number</th> <th>Terminal ID</th> <th>Account Number</th> <th>Account Name</th> </tr> </thead> <tbody> <?php foreach ($views as $view): ?> <tr> <td><?php echo $view['RMA_Number']; ?></td> <td><?php echo $view['Person_Calling']; ?></td> <td><?php echo $view['Company_Name']; ?></td> <td><?php echo $view['Unit_Serial_Number']; ?></td> <td><?php echo $view['Employee_Name']; ?></td> <td><?php echo $view['Call_Date']; ?></td> <td><?php echo $view['Received_Date']; ?></td> <td><?php echo $view['RMA_Status']; ?></td> <td><?php echo $view['Reason_For_Return']; ?></td> <td><?php echo $view['Notes']; ?></td> <td><?php echo $view['New_Install']; ?></td> <td><?php echo $view['New_Unit_Serial_Number']; ?></td> <td><?php echo $view['Terminal_ID']; ?></td> <td><?php echo $view['Account_Number']; ?></td> <td><?php echo $view['Account_Name']; ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </body> here is an example of the server-side with datatables but im using pdo. http://www.datatables.net/release-datatables/examples/data_sources/server_side.html View.html.zip
×
×
  • 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.