Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Match variables? Jak sprawdzać czy input jest taki sam jak var
masterbeat
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 22.09.2014

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


Witajcie, chciałbym się dowiedzieć jak zrobić skrypt który powiedzmy ma 20 var'ów

Przykład:
  1. 1980 - around 4.5 billion
  2. 1981 - around 4.5 billion
  3. 1982 - around 4.5 billion
  4. 1983 - around 4.5 billion
  5. 1984 - around 4.5 billion
  6. 1985 - around 4.5 billion
  7. 1986 - around 4.5 billion
  8. 1987 - around 4.5 billion
  9. 1988 - around 4.5 billion
  10. 1989 - around 4.5 billion
  11. 1990 - around 5 billion
  12. 1991 - around 5 billion
  13. 1992 - around 5 billion
  14. 1993 - around 5 billion
  15. 1994 - around 5 billion
  16. 1995 - around 5 billion
  17. 1996 - around 5 billion
  18. 1997 - around 5 billion
  19. 1998 - around 5 billion
  20. 1999 - around 5 billion
  21. 2000 - around 6 billion
  22. 2001 - around 6 billion
  23. 2002 - around 6 billion
  24. 2003 - around 6 billion
  25. 2004 - around 6 billion
  26. 2005 - around 6 billion
  27. 2006 - around 6 billion
  28. 2007 - around 6 billion
  29. 2008 - around 6 billion
  30. 2009 - around 6 billion
  31. 2010 - around 7 billion
  32. 2011 - around 7 billion
  33. 2012 - around 7 billion
  34. 2013 - around 7 billion
  35. 2014 - around 7 billion


i chciałbym aby użytkownik wpisywał w
  1. <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Year">


np 2008 i by mu się wyświetlił tekst= " around 6 billion"
Go to the top of the page
+Quote Post
ixpack
post
Post #2





Grupa: Zarejestrowani
Postów: 248
Pomógł: 55
Dołączył: 1.06.2010
Skąd: mam to wiedzieć?

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


prosciej przypisz wartosci do np. tablicy...
  1. $tablica = array(
  2. '1980' => 'around 4.5 billion',
  3. '1981' => ...
  4. );


Nastepnie mozesz dac szybki if statement...

  1. $kupa = $_POST['nameInputa']; //to ma byc rok np. 1980
  2. echo (isset($tablica[$kupa]) ? $tablica[$kupa] : 'Nie ma takiego roku';


... Bez przeladowania uzyj js

Ten post edytował ixpack 21.10.2014, 22:54:06
Go to the top of the page
+Quote Post
masterbeat
post
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 22.09.2014

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


  1. <form action="" method=post>
  2. <input type="text" class="form-control" name="inputuno" placeholder="Year">
  3. <button type="submit" name="inputuno" value="Submit" class="btn btn-theme">Check!</button>
  4. </form>
  5.  
  6. <?php
  7.  
  8. $table = array(
  9. '1980' => 'around 4.5 billion',
  10. );
  11.  
  12. echo (isset($_POST['inputno']) && in_array($table, $_POST['inputno']) ? $table[$_POST['inputno']] : 'No info message...');
  13. ?>


trochę pokombinowałem i wykombinowałem to. z małą pomocą. Lecz cały czas wyswietla mi się 'No info message...' na stronie

strona: http://quantamo.eu/geo/
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


inputuno != inputno

Serio z czymś takim na forum trzeba leciec...?

Apropo in_array() - przeczytaj w manuala gdzie powinna być wartość poszukiwana, a gdzie tablica.

Ten post edytował Turson 22.10.2014, 06:44:44
Go to the top of the page
+Quote Post

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: 19.12.2025 - 03:52