Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] wywołanie funkcji
-php beginner-
post
Post #1





Goście







Witam,


Chce użyć funkcji ale nie wiem jak sie do tego zabrać.

Mam funkcje :
  1. function player()
  2. {
  3. $sql_player=mysql_query("SELECT * FROM player WHERE id_player='$get_player'");
  4. }


tutaj mam wywołanie funkcji ale efektu brak

  1. if ($get_player>0)
  2. {
  3. $sql = player();
  4. while ($player=mysql_fetch_array($sql))
  5. {
  6. $id=$player['id_player'];
  7. $nazwa_player=$player['nazwa_player'];
  8. <OPTION VALUE=\"$id_player\">$nazwa_player</option>";
  9. }
  10. }


i niestety nie działa.

Proszę o pomoc bo używam funkcji pierwszy raz.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
melkorm
post
Post #2





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


Cytat
Proszę o pomoc bo używam funkcji pierwszy raz.

To do tutoriala i się uczyć.

Hint: return


PS. O reszcie kodu nawet nie wspomnę .... .

Ten post edytował melkorm 4.10.2011, 21:44:13


--------------------
Go to the top of the page
+Quote Post
Kamil Pietrzak
post
Post #3





Grupa: Zarejestrowani
Postów: 213
Pomógł: 10
Dołączył: 7.01.2010
Skąd: Lublin

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


http://webmade.org/kursy-online/funkcje-kurs-php.php
przeczytaj caly

i zacznij od czegos prostrzego
najpierw naucz sie obslugi funkcji, a pozniej dopiero ich uzywaj
Go to the top of the page
+Quote Post
-Gość-
post
Post #4





Goście







z return juz dawałem i też nie działało.
ps co masz na mysli z kodem ?
Go to the top of the page
+Quote Post
Kamil Pietrzak
post
Post #5





Grupa: Zarejestrowani
Postów: 213
Pomógł: 10
Dołączył: 7.01.2010
Skąd: Lublin

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


jak chcesz miec

  1. $sql1 = player();

to nie ma innej opcji, niz return
musisz zrozumiec co robi return, inaczej nie ma mowy o funkcjach

masz kod PHP, a nagle wchodzi
  1. <OPTION VALUE...


podstawy PHP - php otwiera sie "<?" || "<?php" && zamyka "?>"

Ten post edytował Kamil Pietrzak 4.10.2011, 22:28:13
Go to the top of the page
+Quote Post
-Gość-
post
Post #6





Goście







ja tam mam znaczniki php smile.gif
dam cały kod :

  1. <?php
  2. ini_set('display_errors','0');
  3. include("index.php");
  4. $txt='';
  5. //pobierz typ
  6. $get_typ = isset($_GET['typ']) ? $_GET['typ'] : 'wydaj';
  7. //pobierz akcja
  8. $get_akcja = isset($_GET['akcja']) ? $_GET['akcja'] : '';
  9. //lista playerów
  10. $get_player = isset($_GET['player']) ? $_GET['player'] : 0;
  11.  
  12. function player($get_player)
  13. {
  14. $sql=mysql_query("SELECT * FROM player WHERE id_player='$get_player'");
  15. return $sql;
  16. }
  17.  
  18.  
  19. <FORM method=\"GET\" enctype=\"multipart/form-data\" onsubmit=\"return rozszerzenie(this)\" action=\"obsluga.php?typ=wydaj&akcja=dodaj&player=$id_player\")>
  20. <SELECT NAME=\"player\" CLASS=\"wyslij_formularz\" style=\"width: 180px; align: center; margin-top: 15px; margin-left: 15px\" onchange=\"wyborplayer_wydaj(this.value);\">";
  21. if ($get_player>0)
  22. {
  23. $sql_player= player();
  24. while ($player=mysql_fetch_array($sql_player))
  25. {
  26. $id_player=$player['id_player'];
  27. $nazwa_player=$player['nazwa_player'];
  28. $txt.="<OPTION VALUE=\"$id_player\">$nazwa_player</option>";
  29. }
  30. }
  31. else
  32. {
  33. $txt.="<OPTION VALUE=\"0\">Wybierz playera</option>";
  34. }



funkcja
function wyborplayer_wydaj(id)
{
document.location.href = "obsluga.php?typ=wydaj&player=" + id;
}

i dalej nie działa ;/
Go to the top of the page
+Quote Post
nospor
post
Post #7





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Zastosuj się do tego tematu
Temat: Jak poprawnie zada pytanie
dużo pomoże

Pomijam już tak "drobny szczegół", że funkcję player
$sql_player= player();
odpalasz bez argumentu, podczas gdy w funkcji korzustasz z tego argumentu


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
-Gość-
post
Post #8





Goście







dziękuje ten drobny szczegół chyba rozwiązał problem smile.gif
Go to the top of the page
+Quote Post
-Gość-
post
Post #9





Goście







chciałem dodac taki warunek do funkcji i nie działa przy get_inkasent=0

function inkasent($get_inkasent)
{
if ($get_inkasent==0)
$sql = "SELECT * FROM konwojent";
else
$sql = "SELECT * FROM konwojent WHERE id_konwojent='$get_inkasent'";

//$sql=mysql_query("SELECT * FROM konwojent $where");
$sql_query=mysql_query($sql);
return $sql_query;
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




A czymżesz objawia się to nie działanie?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
-Gość-
post
Post #11





Goście







w przypadku kiedy get_inkasent jest >0 nie wykonuje się pogrubiony kod

<SELECT NAME=\"inkasent\" CLASS=\"wyslij_formularz\" style=\"width: 180px; align: center; margin-top: 15px; margin-left: 15px\" onchange=\"wyborinkasent_wydaj(this.value);\">";
if ($get_inkasent>0)
{
$sql_inkasent= inkasent($get_inkasent);
while ($inkasent=mysql_fetch_array($sql_inkasent))
{
$id_inkasent=$inkasent['id_konwojent'];
$nazwa_inkasent=$inkasent['nazwa_konwojent'];
$txt.="<OPTION VALUE=\"$id_inkasent\">$nazwa_inkasent</option>";
}
}
else
{
$txt.="<OPTION VALUE=\"0\">Wybierz inkasenta</option>";
}
#--pobierz inkasent
$inkasent_sql= inkasent($get_inkasent);

while ($inkasent=mysql_fetch_array($inkasent_sql))
{
$id_inkasent=$inkasent['id_konwojent'];
$nazwa_inkasent=$inkasent['nazwa_konwojent'];
$txt.="<OPTION VALUE=\"$id_inkasent\">$nazwa_inkasent</option>";
}
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 09:29