Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wywyływanie artykułu z bazy, Pierwszy działa, drugi już nie
Lethys
post
Post #1





Grupa: Zarejestrowani
Postów: 642
Pomógł: 2
Dołączył: 9.03.2006

Ostrzeżenie: (30%)
XX---


Postanowiłem że zrobię sobie skrypt gdzie bede umieszczał artykuły. Wymagań dużych nie mam, chodzi o to żeby nie tworzyć pliku HTML dla każdego artykułu a po prostu pobierać je z bazy danych.

I tak przykładowo w bazie mam 3 artykuły:

(IMG:http://img138.imageshack.us/img138/7720/15367614.png)


Artykuły działają z takich adresów:

name.php?name=balls
name.php?name=furniture
name.php?name=test

Skrypt:

  1. <?php
  2. include "config.php";
  3. $name = mysql_fetch_array(mysql_query("select * from articles where name='$name'"));
  4. $articles = mysql_fetch_array(mysql_query("select * from articles"));
  5.  
  6. if ($name[name] != $articles[name]){
  7.  
  8. print "We don't have this article. You have wrote propably wrong website adress.";
  9.  
  10. }else{
  11. mysql_query("update articles set visits=visits+1 where id=$name[id]");
  12.  
  13. $ip=$_SERVER['REMOTE_ADDR'];
  14.  
  15.  
  16. $test = mysql_num_rows(mysql_query("select * from ip where id='$name[id]' and ip='$ip'"));
  17. if ($test > 0) {
  18.  
  19. }else{
  20.  
  21.  
  22. mysql_query("update articles set uu=uu+1 where id=$name[id]");
  23. mysql_query("insert into ip (id, ip) values('$name[id]','$ip')");
  24. }
  25.  
  26.  
  27. print "Name:$name[article]<br>$name[article]";
  28.  
  29. }
  30.  
  31.  
  32.  
  33. ?>


I teraz najlepsze, działa tylko i wyłącznie wywołanie pierwsze czyli: name.php?name=balls, przy reszcie wyskakuje "We don't have this article. You have wrote propably wrong website adress."

Dam jeszcze plik .htaccess który może mieć wpływ na to dziwne zachowanie.

  1. php_flag register_globals on
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^mojastrona.com
  4. RewriteRule (.*) <a href="http://www.mojastrona.com/$1" target="_blank">http://www.mojastrona.com/$1</a> [R=301,L]
  5. RewriteBase /
  6. RewriteRule ^(.*)/$ name.php?name=$1 [NC]
  7.  



Wie ktoś dlaczego działa wywołanie tylko pierwszego artykułu ?

Jak już nie mam pojęcia co jest nie tak (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


po co dwa razy pobierasz te same dane? mówię o:
  1. $name = mysql_fetch_array(mysql_query("select * from articles where name='$name'"));
  2. $articles = mysql_fetch_array(mysql_query("select * from articles"));


wystarczy samo $articles..
  1. <?php
  2. include "config.php";
  3.  
  4. $name = mysql_real_escape_string($_GET['name']);
  5.  
  6. $query = mysql_query("select * from articles where name='$name'");
  7. $articles = mysql_fetch_array($query);
  8.  
  9. if (!mysql_num_rows($query)){
  10.  
  11. print "We don't have this article. You have wrote propably wrong website adress.";
  12.  
  13. }else{
  14. echo $articles['name'];
  15. //..........


Ten post edytował CuteOne 10.01.2011, 09:44:37
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: 4.10.2025 - 11:11