Jump to content

ncurran217

Members
  • Posts

    83
  • Joined

  • Last visited

Everything posted by ncurran217

  1. I have a form before this page where the user will select the dates from a datepicker, or by default today's date is in the two fields. As for the query, everything that is in the code is showing up when printed out and is how it should look, so I am not sure of the non-printing characters you are talking about. I changed my query statement in the code to this with double quotes as you said and still no results: $query = " SELECT Reps.Rep, SUM(Logs.Num_Payments) AS 'Num_Payments' FROM Logs INNER JOIN Reps ON Logs.ForteID = Reps.ForteID GROUP BY Reps.Rep, Logs.Date Having Date BETWEEN '$Start_Date' AND '$End_Date' AND SUM(Logs.Num_Payments) > '0'";
  2. No putting the extra \ in there doesn't do anything. All my other pages works with just the one \ in there as well.
  3. It has to be in single quotes for SQL Server. This is how it is printed out from my echo $query; SELECT Reps.Rep, SUM(Logs.Num_Payments) AS 'Num_Payments' FROM Logs INNER JOIN Reps ON Logs.ForteID = Reps.ForteID GROUP BY Reps.Rep, Logs.Date Having Date BETWEEN '12/28/2012' AND '12/28/2012' AND SUM(Logs.Num_Payments) > '0' And that works perfectly fine in SQL.
  4. I put in some of the error reporting for PHP that you had in your signature and nothing came up either Jessica!
  5. I put that in and still no errors popped up. As for the single quotes, which part are you talking about? Jessica, which errors are you talking about?
  6. here is the full php code: <?php /*print_r($_POST);*/ $serverName = 'localhost\SQLEXPRESS'; $connectionInfo = array('Database'=>'test', 'UID'=>'cslogslogin', 'PWD'=>'123456','ReturnDatesAsStrings'=>true,); $connection = sqlsrv_connect($serverName, $connectionInfo); $Start_Date = $_GET['start_date']; $End_Date = $_GET['end_date']; $query = ' SELECT Reps.Rep, SUM(Logs.Num_Payments) AS \'Num_Payments\' FROM Logs INNER JOIN Reps ON Logs.ForteID = Reps.ForteID GROUP BY Reps.Rep, Logs.Date Having Date BETWEEN \''.$Start_Date.'\' AND \''.$End_Date.'\' AND SUM(Logs.Num_Payments) > \'0\''; $result = sqlsrv_query($connection,$query); echo $query; if (!$result) { return 'ERROR: ' . sqlsrv_errors(); } echo "<table border='1px' cellpadding='5' style='border:3px solid black; text-align: center;'> <tr> <th style='border:3px solid black;'>Rep</th> <th style='border:3px solid black;'>Pmts Collected</th> </tr>"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { print_r($row); /*echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>";*/ } echo "</table>"; sqlsrv_free_stmt ($result); sqlsrv_close( $connection); ?> Well i am pretty sure the SQL is fine, because if I do the echo $query; and put what the output is into SSMS it returns values perfectly fine. The PHP code is where it is going wrong but I am not sure what is wrong. mthanks again for the help though hopefully with the full php code there will help out more!
  7. I get nothing still. I will try something else with the print in a bit when i get back to my desktop. thanks for helping though!
  8. Yes, when I copy the query into SSMS it runs and returns the proper results, and with the current query results should return 2 rows.
  9. I am using full tags. The code tag, I accidently copied into there. while adding the other code part, that isn't actually in my code so disregard that This is what it was supposed to be: echo "<table border='1px' cellpadding='5' style='border:3px solid black; text-align: center;'> <tr> <th style='border:3px solid black;'>Rep</th> <th style='border:3px solid black;'>Pmts Collected</th> </tr>"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>"; } echo "</table>"; sqlsrv_free_stmt ($result); sqlsrv_close( $connection); ?>
  10. I have other things that work, but for some reason when trying this one is does not want to put the results into the table. Here is my code: echo "<table border='1px' cellpadding='5' style='border:3px solid black; text-align: center;'> <tr> <th style='border:3px solid black;'>Rep</th> <th style='border:3px solid black;'>Pmts Collected</th> </tr>"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { [code] echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>"; } echo "</table>"; sqlsrv_free_stmt ($result); sqlsrv_close( $connection); ?> [/code] When I view source of the page this part is not in there: echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>"; So I know I have the while part of the code wrong in the table somehow but not sure how to make it work. Let me know if I need to provide more information. Thanks in advance!
  11. Ok, well that gives me a start on how I would accomplish this.
  12. I am not sure what that does, as I am using SQL Server not mysql. But when they hit the submit button the form, I want a box to popup with the reference number column that is in the database, hopefully that clears it up.
  13. Right now I have a page with a form and when you hit the submit button it then, that goes to my php page that has all the SQL Server post commands and inserts all the information typed into the form into the database. When all the information is entered into the database there is another column that auto-increments for a Reference Number. I want to have that Reference Number popup on the screen after the user hits Submit on the form page, but not sure how to go about this. Please let me know if I need to explain more. Thanks in advance for the help!
  14. I thought you could do it that way, but I was missing something before and couldn't get it to work! Thanks again!!!
  15. Wow, thank you that is ALOT cleaner looking as well!!!!
  16. I would like to have my option value a different column then the display part of the option. I would like the value part to be the column ForteID and the display part to be the Rep column of my SQL Query. Is this possible? <?php $serverName = 'SRB-Nick_Desktop\SQLEXPRESS'; $connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection = sqlsrv_connect($serverName, $connectionInfo); $query = ' SELECT ForteID, Rep FROM Reps ORDER BY Rep'; $result = sqlsrv_query($connection,$query); if (!$result) { $message = 'ERROR: ' . sqlsrv_errors(); return $message; } else { $i = 0; while ($i < sqlsrv_num_rows($result)) { $meta = sqlsrv_fetch($result, $i); echo '' . $meta->name . ''; $i = $i + 1; } echo '<select name="ForteID" id="ForteID">'; while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) { $count = count($row); $y = 0; while ($y < $count) { $c_row = current($row); echo '<option value="[color=#ff0000]' .$c_row. '[/color]";>[color=#00ff00]' .$c_row.'[/color]</option>'; next($row); $y = $y + 1; } } echo '</select>'; sqlsrv_free_stmt ($result); } sqlsrv_close( $connection); ?>
  17. Wow, I have been trying that except for the </select>. Thank you so much!!!
  18. I have this code and I have finally got the results in a select drop down box, but each row is in a separate drop down box, not it one with multiple ones. Here is my code: <h1>View Log</h1> <?php $timezone = "America/Chicago"; date_default_timezone_set($timezone); $today = date("m/d/Y"); ?> <form method="get" action="getlog.php"> <table width="1500" border="0"> <tr> <td>Forte ID:</td> <td> <?php $serverName2 = 'SRB-Nick_Desktop\SQLEXPRESS'; $connectionInfo2 = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection2 = sqlsrv_connect($serverName2, $connectionInfo2); $query2 = ' SELECT ForteID FROM Reps'; $result2 = sqlsrv_query($connection2,$query2); if (!$result2) { $message2 = 'ERROR: ' . sqlsrv_errors(); return $message2; } else { $i2 = 0; while ($i2 < sqlsrv_num_rows($result2)) { $meta2 = sqlsrv_fetch($result2, $i2); echo '' . $meta2->name . ''; $i2 = $i2 + 1; } while ( $row2 = sqlsrv_fetch_array( $result2, SQLSRV_FETCH_ASSOC )) { $count2 = count($row2); $y2 = 0; while ($y2 < $count2) { $c_row2 = current($row2); echo '<select name="test" id="test">'; echo '<option name="Forte_ID" id="Forte_ID" value="' .$c_row2. '";>' .$c_row2.'</option>'; next($row2); $y2 = $y2 + 1; } echo '</select>'; } sqlsrv_free_stmt ($result2); } sqlsrv_close( $connection2); ?> </td> </tr> <tr> <td>Start Date:</td> <td><input name="start_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> <tr> <td>End Date:</td> <td><input name="end_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> </table> <br> <input type="submit" name="getLog" value="Get Log"><br><br> <input type="button" value="Back to Form" onclick="window.location.href='index.php';"> <br> </form> Let me know if a picture of what it looks like would help! Thanks in advance!
  19. Thank you for your help so much! I am learning as well so you have been more than helpful!
  20. So do I have this part wrong? while ( $row = sqlsrv_fetch( $result, SQLSRV_FETCH_ASSOC )) { $resultAsArray = $row; }
  21. I am up to suggestions on another route to get this to work as well.
  22. Yes $resultAsArray is empty, because it starts out empty. I put my query in to SQL and it pulled my list. My connection to the Database I know works, because I have the same thing for another page and it works fine. But getting this to put into a drop down box does not work. I had something else, but it only worked in Chrome but not IE and that was because I had a table nested into the select, which I have found out is wrong. So someone from another forum suggested this route for the select, but was psuedocode and I had to match up what he had in psuedocode to MSSQL code.
  23. I put it in and I get this: Array ( )
  24. Parse error: syntax error, unexpected '{' in C:\wamp\www\cslogs\test.php on line 41 Is what I get, which is this part of my file: <option name="Forte_ID" id="Forte_ID" value="<?php echo {$row['ForteID']};?>"><?php echo $row['ForteID']; ?></option> Doesn't like the {}
×
×
  • 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.