Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Funkcje co robię żle, 2 Funkcje odpowiedzialne za wyswietlanie stron
imashjan82
post 7.04.2010, 21:47:59
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


Ta funkcja która jest w stopce odpowiedzialna za wyswietlenie stopki strony
  1. function footer()
  2. {
  3. $link = "link";
  4. $ask = mysql_query
  5. ("SELECT * FROM footer");
  6. while ($wiersz = mysql_fetch_array($ask))
  7. {
  8. print" <a href='ask.php?=".$wiersz['link']."'>".$wiersz['tytul']."</a> |";
  9. }
  10. print"<br /><br /><br /> <br /><br />";
  11. }

Ta funkcja ma wyswietlic strone o danym tytule link wyglada tak www.strona.pl/ask.php?=o-nas
  1. function ask($link)
  2. {
  3. if (isset($_POST['$link']))
  4. {
  5. $pytanie =mysql_query
  6. ("SELECT tytul_strony , tresc FROM footer WHERE link='$link'");
  7. while ($kod = mysql_fetch_array($pytanie))
  8. {
  9. print"<b>".$kod['tytul_strony']."</b><br /><br />".$kod['tresc']."<br />";
  10. }}
  11. else{
  12. print"Podana strona nie istnieje";
  13. }
  14. }
  15.  

co robie nie tak? ze caly czas wyswietla mi Podana Strona nie istnieje? jakaś chocby mała podpowiedz.

Ten post edytował imashjan82 7.04.2010, 22:02:18
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 18)
darko
post 7.04.2010, 21:52:52
Post #2





Grupa: Zarejestrowani
Postów: 2 885
Pomógł: 463
Dołączył: 3.10.2009
Skąd: Wrocław

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


tu: if (isset($_POST['$link']))


--------------------
Nie pomagam na pw, tylko forum.
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 21:58:44
Post #3





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


szukałem w google i dalej nie wiem co? :-(
Go to the top of the page
+Quote Post
Kshyhoo
post 7.04.2010, 22:00:31
Post #4





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




darko już Ci napisał. Popatrz, co przekazujesz w $_POST.


--------------------
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 22:05:52
Post #5





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


Przekazuje $link czyli to : ask.php=$link ? jak usunel znaczek $ to nie dziala wogole i pokazuje blad.
Go to the top of the page
+Quote Post
janiek_j
post 7.04.2010, 22:17:30
Post #6





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 31.07.2008

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


if (isset($_POST['$link']))

poprawa na

if (isset($_POST[$link]))
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 22:24:22
Post #7





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


to tez nie to dalej pokazuje ze strona nie istnieje
Go to the top of the page
+Quote Post
janiek_j
post 7.04.2010, 22:34:31
Post #8





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 31.07.2008

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


a href='ask.php?TU=".$wiersz['link']."'>".$wiersz['tytul']."</a> |";


tam gdzie ci napisałem "TU" powinno coś być, smile.gifsmile.gif zgadnij co, bo to zbyt proste smile.gif
Go to the top of the page
+Quote Post
mortus
post 7.04.2010, 22:37:01
Post #9





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Pierwszy kod linia 8
  1. print "<a href='ask.php?link=" . $wiersz['link'] . "'>" . $wiersz['tytul'] . "</a> |";
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 23:05:01
Post #10





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


nie dziala
  1. print" <a href='ask.php?=".$_POST[$link]."'>".$wiersz['tytul']."</a> |";

nie dziala
  1. print" <a href='ask.php?=".$_POST['$link']."'>".$wiersz['tytul']."</a> |";

nie dziala
  1. print" <a href='ask.php?=".$_POST['link']."'>".$wiersz['tytul']."</a> |";

nie dziala
  1. print" <a href='ask.php?=".$_POST[link]."'>".$wiersz['tytul']."</a> |";


i za kadzym razem adres wyglada tak : ask.php= i tyle

dodam ze to wszystko jest w jednym pliku, plik stopki jest includowany

Ten post edytował imashjan82 7.04.2010, 23:05:44
Go to the top of the page
+Quote Post
mortus
post 7.04.2010, 23:18:46
Post #11





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Pierwszy kod linia 8 w funkcji footer powinna wyglądać tak:
  1. print "<a href='ask.php?link=" . $wiersz['link'] . "'>" . $wiersz['tytul'] . "</a> |";
Nie wiem, czy ja po chińsku piszę?

Funkcja druga (ask) linia 3:
  1. if(isset($_POST['link']))
Jak to nie zadziała, to wklej cały kod.
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 23:20:43
Post #12





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


NIe piszesz po chińsku. Zrobiłem tak ale dalej jest to samo.
Go to the top of the page
+Quote Post
mortus
post 7.04.2010, 23:26:15
Post #13





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Skoro wszystko jest w jednym pliku, to wklej tutaj kod. Ciekaw jestem, jak Ty tę funkcję ask wywołujesz.
Go to the top of the page
+Quote Post
imashjan82
post 7.04.2010, 23:50:03
Post #14





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


tak wywoluje
plik z funkcjami
  1. function menu_lewe()
  2. {
  3. $ask = mysql_query
  4. ("SELECT * FROM menu_lewe ORDER BY id LIMIT 0,15");
  5. while ($wiersz = mysql_fetch_array($ask))
  6. {
  7. print"<a href='http://worcester.pl/".$wiersz['link']."'>".$wiersz['tytul']."</a><br />";
  8. }
  9. }
  10. /////////////////////////////////////// WIADOMOSCI NA GLOWNEJ STRONIE ////////////
  11. function news_home()
  12. {
  13. print"<div class='title'>Wiadomość z UK & Worcestershire</div> <br />";
  14.  
  15. $ask = mysql_query
  16. ("SELECT * FROM news ORDER BY ID DESC LIMIT 0,7");
  17. while ($wiersz = mysql_fetch_array($ask))
  18. {
  19. print"<a href='news/".$wiersz['ID'].",".$wiersz['link'].".html'>".$wiersz['tytul']."</a><br />";
  20. }
  21. print"<a href='http://www.worcester.pl/news/'>Archiwum Aktualnosci</a>";
  22. }
  23. /////////////////////////////////////// STOPKA WSZEDZIE ////////////////////////////
  24. function footer()
  25. {
  26. $link = "link";
  27. $ask = mysql_query
  28. ("SELECT * FROM footer");
  29. while ($wiersz = mysql_fetch_array($ask))
  30. {
  31. print" <a href='ask.php?link=" .$wiersz['link']. "'>" .$wiersz['tytul']. "</a> |";
  32. }
  33. print"<br /><br /><br /><br /><br />";
  34. }
  35. //////////////////////////////////// GALERIA NA GŁOWNEJ STRONIE//////////////////////
  36. function gallery_home()
  37. {
  38. $ask = mysql_query
  39. ("SELECT * FROM gallery ID LIMIT 0,5");
  40. while ($wiersz = mysql_fetch_array($ask))
  41. {
  42. print"<a href='gallery/=".$wiersz['ID']."'><img src='gallery/worcester/".$wiersz['ID'].".JPG' width='151' border='0' height='75'></a>";
  43. }
  44. }
  45. ////////////////////////////////// o serwisie ///////////////////////////////////////
  46. function ask($link)
  47. {
  48. if (isset($_POST[$link]))
  49. {
  50. $pytanie =mysql_query
  51. ("SELECT tytul_strony , tresc FROM footer WHERE link='$link'");
  52. while ($kod = mysql_fetch_array($pytanie))
  53. {
  54. print"<b>".$kod['tytul_strony']."</b><br /><br />".$kod['tresc']."<br />";
  55. }}
  56. else{
  57. print"Podana strona nie istnieje";
  58. }
  59. }
  60.  


plik ask

  1.  
  2. require_once('function/function.php');
  3.  
  4. lacz_bd();
  5.  
  6. $page_title = 'tytul strony';
  7. include "templates/header.html";
  8.  
  9. include "templates/header_top.html";
  10. print"<tr><td>";
  11. ?>
  12. <script language='JavaScript' type='text/javascript' src='http://www.iiads.eu/adx.js'></script>
  13. <script language='JavaScript' type='text/javascript'>
  14. <!--
  15. if (!document.phpAds_used) document.phpAds_used = ',';
  16. phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
  17.  
  18. document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
  19. document.write ("http://www.iiads.eu/adjs.php?n=" + phpAds_random);
  20. document.write ("&amp;what=zone:1");
  21. document.write ("&amp;exclude=" + document.phpAds_used);
  22. if (document.referrer)
  23. document.write ("&amp;referer=" + escape(document.referrer));
  24. document.write ("'><" + "/script>");
  25. //-->
  26. </script><noscript><a href='http://www.iiads.eu/adclick.php?n=a9320cbb' target='_blank'><img src='http://www.iiads.eu/adview.php?what=zone:1&amp;n=a9320cbb' border='0' alt=''></a></noscript>
  27. <?
  28. print"</tr></td>";
  29.  
  30. include"templates/top_spacer.html";
  31.  
  32. print"<tr>
  33. <td width='15' bgcolor='#e8e7e2'>&nbsp;</td>
  34. <td width='204' bgcolor='#dbdbcf' class='left_column' valign='top'>"; menu_lewe();
  35. print"</td><td width='336' class='news_home' bgcolor='#e8e7e2'>"; ask($link);
  36. print"</td><td width='204' class='right_column' bgcolor='#dbdbcf'></td>
  37. <td width='22' bgcolor='#e8e7e2'>&nbsp;</td>
  38. </tr></table>";
  39. include"templates/footer.html";
  40. print"</body></html>";
  41.  


plik stopki

  1. <table width="781" cellpadding="0" cellspacing="0" align="center" bgcolor="#e8e7e2">
  2. <tr>
  3. <td width="775" align="center">
  4.  
  5. <? footer(); ?>
  6.  
  7. </td>
  8. </tr>
  9.  



Ten post edytował imashjan82 8.04.2010, 00:04:39
Go to the top of the page
+Quote Post
AdIoS_Neo
post 8.04.2010, 02:29:10
Post #15





Grupa: Zarejestrowani
Postów: 159
Pomógł: 43
Dołączył: 8.03.2009

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


Zaraz zaraz exclamation.gif Przecież jeśli on chce pobrać zmienną z linku [www.strona.pl/ask.php?link=o-nas] to to $_GET[] jest a nie $_POST[]... oO btw. nie ma to jak szczegółowo opisać na czym polega problem ...
Go to the top of the page
+Quote Post
mortus
post 8.04.2010, 07:19:29
Post #16





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Cytat(AdIoS_Neo @ 8.04.2010, 03:29:10 ) *
Zaraz zaraz exclamation.gif Przecież jeśli on chce pobrać zmienną z linku [www.strona.pl/ask.php?link=o-nas] to to $_GET[] jest a nie $_POST[]... oO btw. nie ma to jak szczegółowo opisać na czym polega problem ...

To i tak nic nie da. Do powyższego kodu trzeba zastosować dwie zmiany:
1. w pliku ask.php w linii 35 zamiast ask($link); powinno być ask($_GET['link']);,
2. w funkcji ask() w trzeciej linijce powinno być if(isset($_GET['link']) && $_GET['link'] == $link) zamiast if(isset($_POST['link'])).

Poza tym mam zastrzeżenia co do przeplatania kodu PHP i (X)HTML w pliku ask.php, ale to odrębna kwestia i mniej znacząca.
Go to the top of the page
+Quote Post
imashjan82
post 8.04.2010, 08:39:09
Post #17





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


Proszę proszę pisać o tych zastrzeżeniach co do pliku ask.php. Nie powinieniem go drukować w printach tak?
Go to the top of the page
+Quote Post
mortus
post 8.04.2010, 08:56:59
Post #18





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Cytat(imashjan82 @ 8.04.2010, 09:39:09 ) *
Proszę proszę pisać o tych zastrzeżeniach co do pliku ask.php. Nie powinieniem go drukować w printach tak?
Nie o to chodzi, że nie powinieneś, ale skoro już przeplatasz kod (X)HTML i PHP to możesz to robić znacznie bardziej czytelnie (bez używania print). To chyba nie jest cały plik ask.php, bo nigdzie nie widzę znaczników rozpoczynających <html>, sekcji <head></head> itp. rzeczy, ale podany fragment można zapisać w taki sposób:
  1. <?php
  2. require_once('function/function.php');
  3.  
  4. lacz_bd();
  5.  
  6. $page_title = 'tytul strony';
  7.  
  8. include "templates/header.html";
  9.  
  10. include "templates/header_top.html";
  11. ?>
  12. <tr>
  13. <td>
  14. <script language='JavaScript' type='text/javascript' src='http://www.iiads.eu/adx.js'></script>
  15. <script language='JavaScript' type='text/javascript'>
  16. <!--
  17. if(!document.phpAds_used) document.phpAds_used = ',';
  18. phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
  19.  
  20. document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
  21. document.write ("http://www.iiads.eu/adjs.php?n=" + phpAds_random);
  22. document.write ("&amp;what=zone:1");
  23. document.write ("&amp;exclude=" + document.phpAds_used);
  24. if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
  25. document.write ("'><" + "/script>");
  26. //-->
  27. </script>
  28. <noscript>
  29. <a href='http://www.iiads.eu/adclick.php?n=a9320cbb' target='_blank'>
  30. <img src='http://www.iiads.eu/adview.php?what=zone:1&amp;n=a9320cbb' border='0' alt=''>
  31. </a>
  32. </noscript>
  33. </td>
  34. </tr>
  35. <?php include"templates/top_spacer.html"; ?>
  36. <tr>
  37. <td width='15' bgcolor='#e8e7e2'>&nbsp;</td>
  38. <td width='204' bgcolor='#dbdbcf' class='left_column' valign='top'><?php menu_lewe(); ?></td>
  39. <td width='336' class='news_home' bgcolor='#e8e7e2'><?php ask($link); ?></td>
  40. <td width='204' class='right_column' bgcolor='#dbdbcf'></td>
  41. <td width='22' bgcolor='#e8e7e2'>&nbsp;</td>
  42. </tr>
  43. </table>
  44. <?php include"templates/footer.html"; ?>
  45. </body>
  46. </html>
Bynajmniej nie chodzi tu o formatowanie, ale o samo wywoływanie skryptów (funkcji) PHP. Po prostu wstawiamy odpowiedni kod PHP w miejscach, w których jest to absolutnie konieczne.
Go to the top of the page
+Quote Post
imashjan82
post 8.04.2010, 09:09:24
Post #19





Grupa: Zarejestrowani
Postów: 71
Pomógł: 2
Dołączył: 2.12.2009

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


To jest cały plik. poprostu znaczniki są w pliku header.html potem góra strony jest w header_top.html. I już wiedzę co muszę zmienić. część z iiads.eu musze dodac to pliku header_top.html bo to jest część strony która się nie zmienia. Tak samo boczne menu znaczy lewa strona. Zmienne jest tylko centrum strony i prawe menu. Bardzo dziękuję za poradę.
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 Wersja Lo-Fi Aktualny czas: 24.07.2025 - 16:47