Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Funkcja w foreach pobierająca wyniki
o2w5n778
post
Post #1





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

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


Witam!
Mam taki oto kod:
  1. function have_pages(){
  2. $query = mysql_query("SELECT * FROM " . DBPREFIX . "pages");
  3. $values = array();
  4. while($show = mysql_fetch_array($query)){
  5. $values[] = $show;
  6. }
  7. return($values);
  8. }
  9.  
  10. function the_title($values = $page['page_title']){
  11. print_r($values);
  12. }

I chcę za pomocą funkcji the title z wartością domyślną wyświetlać w pętli foreach wyniki:
  1. <?php foreach(have_pages() as $page): ?>
  2. <?php the_title(); ?>
  3. <?php endforeach; ?>

Niestety nie działa, jak to zrobić poprawnie?

Ten post edytował o2w5n778 30.04.2012, 10:04:19
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
o2w5n778
post
Post #2





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

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


Niestety Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\web\project1\includes\pages-functions.php on line 18
Funkcja nie działa. Ale czy to niebędzie zbyt mało optymalnie nie dość że w have_pages jest pętla while to jeszcze w każdej innej funkcji tworzyć foreach?
Nie wiesz może jak zrobić coś podobnego do systemu szablonów w wordpressie?
  1. <?php if (have_posts()) : ?>
  2. <?php while (have_posts()) : the_post(); ?>
  3. <h3><?php the_title(); ?></h3>
  4. <div id="add_to"></div>
  5. <?php the_content('Czytaj całość &raquo;'); ?>
  6. <div id="info_i">Dodał <?php the_author(); ?> dnia <?php the_date(); ?> | <?php comments_popup_link('Komentarzy: 0', 'Komentarzy: 1', 'Komentarzy: %'); ?></div>
  7. <?php comments_template( '', true ); ?>
  8. <?php endwhile; ?>
  9.  
  10. <?php else : ?>
  11.  
  12. <?php endif; ?>

Chodzi mi o to jakim cudem funkcje umieszczone w pętli while pobierają wartości z have_posts() lub the_post()?

Ten post edytował o2w5n778 30.04.2012, 11:23:29
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: 13.10.2025 - 23:27