Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Następny i poprzedni artykuł
Tidude
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 10.08.2011

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


Witam, mam skrypt artykułów.
Chciałem dodać do widoku artykułów możliwość przejścia do następnego i poprzedniego artykułu.

Kod php pliku zdjecie.php
Najlepiej gdybym mógł wstawić aby @następny do pliku tpl. @nastepny dotyczyłby adresu artykułu.

  1. <?php
  2. include('config.php');
  3.  
  4. //Create site settings variables
  5. $sitequery = 'select * from settings;';
  6. $siteresult = mysql_query($sitequery,$connection) or die(mysql_error());
  7. $siteinfo = mysql_fetch_array($siteresult);
  8. $siteurl = $siteinfo['url'];
  9.  
  10. $zdjecie = $_GET['id'];
  11.  
  12. if (!is_numeric($zdjecie)) {
  13. header('Location: '.$siteurl);
  14. }
  15.  
  16. else
  17.  
  18. {
  19.  
  20. $sitequery = 'select * from settings;';
  21. $siteresult = mysql_query($sitequery,$connection) or die(mysql_error());
  22.  
  23. //Create site settings variables
  24. $siteinfo = mysql_fetch_array($siteresult);
  25. $sitetitle = $siteinfo['title'];
  26. $siteurl = $siteinfo['url'];
  27. $sitecomments = $siteinfo['comments'];
  28. $commentmod = $siteinfo['commentmod'];
  29.  
  30. $query = "select * from zdjecia where status=0 and id = ".$zdjecie;
  31.  
  32. $zdjecieresults = mysql_query($query,$connection) or die(mysql_error());
  33. $num_results = mysql_num_rows($zdjecieresults);
  34. $zdjecieinfo = mysql_fetch_array($zdjecieresults);
  35.  
  36. if (!$num_results) {
  37. header('Location: '.$siteurl);
  38. }
  39.  
  40. //Get zdjecie info
  41. $id = $zdjecieinfo['id'];
  42. $authorid = $zdjecieinfo['authorid'];
  43. $date = strtotime($zdjecieinfo['date']);
  44. $artdate = date('m/d/y', $date);
  45. $fotografiaid = $zdjecieinfo['fotografiaid'];
  46. $title = stripslashes($zdjecieinfo['title']);
  47. $body = stripslashes($zdjecieinfo['body']);
  48. $resource = $zdjecieinfo['resource'];
  49.  
  50.  
  51. //Meta Info
  52. $cathead = 0;
  53. $metatitle = $title." - ";
  54. include('header.php');
  55. include('sidebar.php');
  56.  
  57.  
  58. if ($seourls == 1) { $scrubtitle = generate_seo_link($title); }
  59.  
  60.  
  61. // Setup the zdjecie template
  62. $zdjecietemp = new Template("templates/".$template."/zdjecie.tpl");
  63.  
  64. // get author info
  65. $authorquery = "select * from authors where id=".$authorid;
  66. $authorresult = mysql_query($authorquery,$connection) or die(mysql_error());
  67. $authorinfo = mysql_fetch_array($authorresult);
  68. $authorname = $authorinfo['displayname'];
  69. $authorbio = $authorinfo['bio'];
  70. $gravatar = $authorinfo['gravatar'];
  71. if ($seourls == 1) { $scrubauthor = generate_seo_link($authorname); }
  72.  
  73. // get fotografia info
  74. $catquery = "select * from fotografie where id=".$fotografiaid;
  75. $catresult = mysql_query($catquery,$connection) or die(mysql_error());
  76. $catinfo = mysql_fetch_array($catresult);
  77. $fotografianame = $catinfo['name'];
  78. $catparent = $catinfo['parentid'];
  79. if ($seourls == 1) { $scrubcatname = generate_seo_link($fotografianame); }
  80.  
  81. // if the fotografia doesn't have a parent
  82. if ($catparent == NULL) {
  83. if ($seourls == 1) { // With SEO URLS
  84. $displaycat = "<a href=\"".$siteurl."/fotografia/".$fotografiaid."/"
  85. .$scrubcatname."/\"><b>".$fotografianame."</b></a>";
  86. } else {
  87. $displaycat = "<a href=\"".$siteurl."/fotografia.php?id=".$fotografiaid
  88. ."\"><b>".$fotografianame."</b></a>";
  89. }
  90.  
  91. // if the fotografia DOES have a parent
  92. } else {
  93. $query = "select * from fotografie where id=".$catparent;
  94. $result = mysql_query($query,$connection) or die(mysql_error());
  95. $info = mysql_fetch_array($result);
  96. $parentname = $info['name'];
  97. if ($seourls == 1) { $scrubparent = generate_seo_link($parentname); }
  98.  
  99. if ($seourls == 1) { // With SEO URLS
  100. $displaycat = "<a href=\"".$siteurl."/fotografia/".$catparent."/"
  101. .$scrubparent."/\"><b>".$parentname."</b></a> >
  102. <a href=\"".$siteurl."/fotografia/".$fotografiaid."/"
  103. .$scrubcatname."/\"><b>".$fotografianame."</b></a>";
  104. } else {
  105. $displaycat = "<a href=\"".$siteurl."/fotografia.php?id=".$catparent
  106. ."\"><b>".$parentname."</b></a> >
  107. <a href=\"".$siteurl."/fotografia.php?id=".$fotografiaid
  108. ."\"><b>".$fotografianame."</b></a>";
  109. }
  110. }
  111.  
  112.  
  113. // Add a view to this zdjecie
  114. $query = "select * from zdjecieviews where zdjecieid = ".$zdjecie;
  115. $results = mysql_query($query,$connection) or die(mysql_error());
  116. $viewinfo = mysql_fetch_array($results);
  117. if ($viewinfo == NULL) {
  118. $sql = "INSERT INTO zdjecieviews VALUES (".$zdjecie.", 1)";
  119. $query = mysql_query($sql);
  120. } else {
  121. $totalviews = $viewinfo['views'];
  122. $totalviews++;
  123.  
  124. $sql = "UPDATE zdjecieviews SET views=".$totalviews." WHERE `zdjecieid`=".$zdjecie."";
  125. $query = mysql_query($sql);
  126. }
  127.  
  128. if ($seourls == 1) { // With SEO URLS
  129. $authorlink = "<a href=\"".$siteurl."/profile/".$authorid."/".$scrubauthor."/\"><b>".$authorname."</b></a>";
  130. } else {
  131. $authorlink = "<a href=\"".$siteurl."/profile.php?a=".$authorid."\"><b>".$authorname."</b></a>";
  132. }
  133.  
  134. // Setup all template variables for display
  135. $zdjecietemp->set("authorname", $authorname);
  136. $zdjecietemp->set("authorlink", $authorlink);
  137. $zdjecietemp->set("date", $artdate);
  138. $zdjecietemp->set("displaycat", $displaycat);
  139. $zdjecietemp->set("views", $totalviews);
  140. $zdjecietemp->set("title", $title);
  141. $zdjecietemp->set("body", $body);
  142. $zdjecietemp->set("gravatar", $gravatar);
  143. $zdjecietemp->set("resource", $resource);
  144.  
  145. // For the adcode
  146. $query = "select * from adboxes where id=1;";
  147. $result = mysql_query($query,$connection) or die(mysql_error());
  148. $info = mysql_fetch_assoc($result);
  149. $zdjecietemp->set("250adcode", stripslashes($info['adcode']));
  150.  
  151.  
  152. // Outputs the homepage template!
  153.  
  154. echo $zdjecietemp->output();
  155.  
  156.  
  157.  
  158. # Setup db config array #
  159. $db_config = array("db_name" => $db_name,
  160. "db_user" => $dbusername,
  161. "db_pass" => $dbpassword,
  162. "db_host" => $server );
  163.  
  164.  
  165.  
  166. include('rightsidebar.php');
  167.  
  168. }
  169.  
  170. ?>


oraz tabela która przetrzymuje owe artykuły.

  1. CREATE TABLE IF NOT EXISTS `zdjecia` (
  2. `id` int(16) NOT NULL AUTO_INCREMENT,
  3. `status` int(1) NOT NULL,
  4. `authorid` int(16) NOT NULL,
  5. `date` datetime NOT NULL,
  6. `obrazek` varchar(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  7. `title` varchar(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  8. `fotografiaid` int(8) NOT NULL,
  9. `parentid` int(8) DEFAULT NULL,
  10. `body` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  11. `resource` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  12. `problem` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
  13. PRIMARY KEY (`id`)
  14. ) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=75 ;



A sam link artykułu wyglada tak:
  1. http://adres.pl/zdjecie.php?id=74
Go to the top of the page
+Quote Post

Posty w temacie


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: 20.08.2025 - 10:00