Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyświetlanie wydarzeń każdego dnia - problem
kadela
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 16.05.2012

Ostrzeżenie: (0%)
-----


witam

Mam problem z utworzeniem ( wydaje mi się ) prostego skryptu w php.
Mianowicie mam 365 różnych dat - wydarzeń. I skrypt ma po prostu pierwszego
stycznia wyświetlić tylko datę którą do niego przypiszemy. Drugi, trzeci stycznia
itd wyświetla to co podamy w tym skrypcie.. I tyle, jak to ogarnąć ?

Oczywiście te 365 dat będzie najpierw trzeba wprowadzić ręcznie, ale mój
poziom php jest raczkujący (IMG:style_emoticons/default/sad.gif)

Z góry
dziękuje za pomoc!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
woxala123
post
Post #2





Grupa: Zarejestrowani
Postów: 361
Pomógł: 12
Dołączył: 9.01.2010

Ostrzeżenie: (10%)
X----


Witam!
Nie ma sensu wprowadzać 365 dat. Wystarczy jak zrobisz sobie pole tekstowe z formułą data type DATE I WTEDY WPROWADZASZ DATE JAKA CHCESZ I PRZYPISUJESZ ZDARZENIE.
  1. CCREATE TABLE `wydarzenia` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `data` DATE NOT NULL,
  4. `zdarzenie` VARCHAR(255) NULL DEFAULT NULL,
  5. PRIMARY KEY (`id`)
  6. )
  7. COLLATE='utf8_general_ci'
  8. ENGINE=InnoDB
  9. AUTO_INCREMENT=3
  10. ;
  11.  
  12. ;
  13.  
  14.  

  1. <?php require_once('../Connections/local.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8. }
  9.  
  10. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13. case "text":
  14. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15. break;
  16. case "long":
  17. case "int":
  18. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19. break;
  20. case "double":
  21. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22. break;
  23. case "date":
  24. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25. break;
  26. case "defined":
  27. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28. break;
  29. }
  30. return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40. $insertSQL = sprintf("INSERT INTO wydarzenia (`data`, zdarzenie) VALUES (%s, %s)",
  41. GetSQLValueString($_POST['dataform'], "date"),
  42. GetSQLValueString($_POST['wydform'], "text"));
  43.  
  44. mysql_select_db($database_local, $local);
  45. $Result1 = mysql_query($insertSQL, $local) or die(mysql_error());
  46.  
  47. $insertGoTo = "zdarzenie.php";
  48. if (isset($_SERVER['QUERY_STRING'])) {
  49. $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  50. $insertGoTo .= $_SERVER['QUERY_STRING'];
  51. }
  52. header(sprintf("Location: %s", $insertGoTo));
  53. }
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  56. <html xmlns="http://www.w3.org/1999/xhtml">
  57. <head>
  58. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  59. <title>Dokument bez tytułu</title>
  60. </head>
  61.  
  62. <body>
  63. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  64. <p>
  65. <label for="dataform"></label>
  66. <input type="text" name="dataform" id="dataform" />
  67. </p>
  68. <p>
  69. <label for="wydform"></label>
  70. <textarea name="wydform" id="wydform" cols="45" rows="5"></textarea>
  71. <input type="submit" name="wydbutton" id="wydbutton" value="Wyślij" />
  72. </p>
  73. <input type="hidden" name="MM_insert" value="form1" />
  74. </form>
  75. </body>
  76. </html>

a potem zrobić sobie tylko wyszukiwarkę z poziomu select data i bedziesz miał problem z głowy.
i masz już tu wyszukiwarkę po dacie
search.php
  1. <?php require_once('../Connections/local.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8. }
  9.  
  10. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13. case "text":
  14. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15. break;
  16. case "long":
  17. case "int":
  18. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19. break;
  20. case "double":
  21. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22. break;
  23. case "date":
  24. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25. break;
  26. case "defined":
  27. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28. break;
  29. }
  30. return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_local, $local);
  35. $query_Recordset1 = "SELECT * FROM wydarzenia";
  36. $Recordset1 = mysql_query($query_Recordset1, $local) or die(mysql_error());
  37. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  38. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml">
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  44. <title>Dokument bez tytułu</title>
  45. </head>
  46.  
  47. <body>
  48. <form id="form1" name="form1" method="post" action="">
  49. <table border="1">
  50. <tr>
  51. <td>data</td>
  52. </tr>
  53. <tr>
  54. <td>Wydarzenie
  55. <label for="select"></label>
  56. <select name="select" id="select">
  57. <?php
  58. do {
  59. ?>
  60. <option value="<?php echo $row_Recordset1['zdarzenie']?>"><?php echo $row_Recordset1['data'];echo'- '; echo $row_Recordset1['zdarzenie']?></option>
  61. <?php
  62. } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  63. $rows = mysql_num_rows($Recordset1);
  64. if($rows > 0) {
  65. mysql_data_seek($Recordset1, 0);
  66. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  67. }
  68. ?>
  69. </select></td>
  70. </tr>
  71. </table>
  72. </form>
  73. </body>
  74. </html>
  75. <?php
  76. mysql_free_result($Recordset1);
  77. ?>
  78.  


Ten post edytował woxala123 15.01.2017, 11:00:54
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 9.10.2025 - 16:25