473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Any GURU help for "related news" script

2
Dear all,

Greeding from Thailand. Need help for my news script. I am trying to display news which keywords match the current page keywords. I am using Dreamweaver 8 and PhpMyAdmin to manage MySQL. May I explain you what I have done. My database and data in that look like this.

//* Data Base
Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 2.6.2-pl1
  3. -- http://www.phpmyadmin.net
  4. -- 
  5. -- Host: localhost
  6. -- Generation Time: Nov 29, 2006 at 03:45 AM
  7. -- Server version: 4.1.14
  8. -- PHP Version: 5.0.5
  9. -- 
  10. -- Database: `news`
  11. -- 
  12.  
  13. -- --------------------------------------------------------
  14.  
  15. -- 
  16. -- Table structure for table `news`
  17. -- 
  18.  
  19. CREATE TABLE `news` (
  20.   `news_id` int(6) unsigned NOT NULL auto_increment,
  21.   `cat` int(6) unsigned NOT NULL default '0',
  22.   `keywords` text collate utf8_bin NOT NULL,
  23.   `title` text collate utf8_bin NOT NULL,
  24.   `brief` text collate utf8_bin NOT NULL,
  25.   `story` text collate utf8_bin NOT NULL,
  26.   `created` datetime NOT NULL default '0000-00-00 00:00:00',
  27.   `published` datetime default NULL,
  28.   PRIMARY KEY  (`news_id`)
  29. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=9 ;
  30.  
  31. -- 
  32. -- Dumping data for table `news`
  33. -- 
  34.  
  35. INSERT INTO `news` VALUES (1, 11, 0x4a6f686e, 0x4a6f686e2076697369742047617264656e, 0x4a6f686e2076697369742047617264656e206f6e2053756e6461792e, 0x4a6f686e2076697369742047617264656e206f6e2053756e64617920776974682068697320667269656e64732e20, '2006-11-29 01:30:20', '2006-11-29 01:30:20');
  36. INSERT INTO `news` VALUES (2, 11, 0x4a6f686e, 0x4a6f686e206c696b657320466f6f7462616c6c, 0x4a6f686e206973204d616e2d552066616e2e20, 0x4a6f686e206c696b657320466f6f7462616c6c20616e642061204d616e2d552066616e2e20, '2006-11-29 01:48:12', '2006-11-29 01:48:12');
  37. INSERT INTO `news` VALUES (3, 12, 0x4d617279, 0x4d617279, 0x4d61727920697320612073747564656e742e, 0x4d61727920697320612073747564656e7420616e64207072657474792e20, '2006-11-29 02:54:45', '2006-11-29 02:54:45');
  38. INSERT INTO `news` VALUES (4, 12, 0x4d617279, 0x4d61727920627579206375702e, 0x4d617920627579206120726564206375702e, 0x4d617920627579206120726564206375702e20, '2006-11-29 02:56:26', '2006-11-29 02:56:26');
  39. INSERT INTO `news` VALUES (5, 11, 0x4368726973, 0x4368726973, 0x4368726973206973206120626f792e, 0x4368726973206c696b6520706c6179696e672067616d65732e20, '2006-11-29 03:02:40', '2006-11-29 03:02:40');
  40. INSERT INTO `news` VALUES (6, 11, 0x546f6d, 0x546f6d, 0x546f6d206861766520616e206170706c652e20, 0x546f6d20697320656174696e6720616e206170706c652e20, '2006-11-29 03:03:39', '2006-11-29 03:03:39');
  41. INSERT INTO `news` VALUES (7, 12, 0x4a656e6e79, 0x4a656e6e79, 0x4a656e6e79206973206120746561636865722e, 0x4a656e6e79207465616368657320456e676c69736820746f2073747564656e74732e, '2006-11-29 03:13:21', '2006-11-29 03:13:21');
  42. INSERT INTO `news` VALUES (8, 12, 0x4c697a, 0x4c697a, 0x4c697a20697320612073696e6765722e20, 0x4c697a2073696e6773206120706f7020736f6e672e, '2006-11-29 03:14:33', '2006-11-29 03:14:33');
  43.  
------

This is my index.php page to show all published news.
------
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/db.php'); ?>
  2. <?php
  3. $maxRows_news = 10;
  4. $pageNum_news = 0;
  5. if (isset($_GET['pageNum_news'])) {
  6.   $pageNum_news = $_GET['pageNum_news'];
  7. }
  8. $startRow_news = $pageNum_news * $maxRows_news;
  9.  
  10. mysql_select_db($database_news, $news);
  11. $query_news = "SELECT * FROM news WHERE published is not null ORDER BY news.published DESC";
  12. $query_limit_news = sprintf("%s LIMIT %d, %d", $query_news, $startRow_news, $maxRows_news);
  13. $news = mysql_query($query_limit_news, $news) or die(mysql_error());
  14. $row_news = mysql_fetch_assoc($news);
  15.  
  16. if (isset($_GET['totalRows_news'])) {
  17.   $totalRows_news = $_GET['totalRows_news'];
  18. } else {
  19.   $all_news = mysql_query($query_news);
  20.   $totalRows_news = mysql_num_rows($all_news);
  21. }
  22. $totalPages_news = ceil($totalRows_news/$maxRows_news)-1;
  23. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  27. <title>News</title>
  28. </head>
  29. <body>
  30. <h2>INDEX PAGE</h2>
  31. <h3>Latest News</h3>
  32. <?php do { ?>
  33. <strong>Title: </strong><?php echo $row_news['title']; ?><br />
  34. <strong>Date: </strong><?php echo $row_news['created']; ?><br />
  35. <strong>Brief: </strong><?php echo $row_news['brief']; ?><br />
  36. <a href="view.php?news_id=<?php echo $row_news['news_id']; ?>&cat=<?php echo $row_news['cat']; ?>">Detail</a><br /><br />
  37. <?php } while ($row_news = mysql_fetch_assoc($news)); ?>
  38. </body>
  39. </html>
  40. <?php
  41. mysql_free_result($news);
  42. ?>
  43.  
------------

This is the view.php code to display News' detail, latest news and related news.
-----------
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/db.php'); ?>
  2. <?php
  3. mysql_select_db($database_news, $news);
  4. $query_regional = "SELECT * FROM news WHERE news_id=$news_id AND cat=$cat ORDER BY news.published";
  5. $regional = mysql_query($query_regional, $news) or die(mysql_error());
  6. $row_regional = mysql_fetch_assoc($regional);
  7. $totalRows_regional = mysql_num_rows($regional);
  8.  
  9. $maxRows_head = 3;
  10. $pageNum_head = 0;
  11. if (isset($_GET['pageNum_head'])) {
  12.   $pageNum_head = $_GET['pageNum_head'];
  13. }
  14. $startRow_head = $pageNum_head * $maxRows_head;
  15.  
  16. mysql_select_db($database_news, $news);
  17. $query_head = "SELECT * FROM news WHERE news_id!=$news_id ORDER BY news.published DESC";
  18. $query_limit_head = sprintf("%s LIMIT %d, %d", $query_head, $startRow_head, $maxRows_head);
  19. $head = mysql_query($query_limit_head, $news) or die(mysql_error());
  20. $row_head = mysql_fetch_assoc($head);
  21.  
  22. if (isset($_GET['totalRows_head'])) {
  23.   $totalRows_head = $_GET['totalRows_head'];
  24. } else {
  25.   $all_head = mysql_query($query_head);
  26.   $totalRows_head = mysql_num_rows($all_head);
  27. }
  28. $totalPages_head = ceil($totalRows_head/$maxRows_head)-1;
  29.  
  30. $maxRows_kw = 3;
  31. $pageNum_kw = 0;
  32. if (isset($_GET['pageNum_kw'])) {
  33.   $pageNum_kw = $_GET['pageNum_kw'];
  34. }
  35. $startRow_kw = $pageNum_kw * $maxRows_kw;
  36.  
  37. mysql_select_db($database_news, $news);
  38. $query_kw = "SELECT * FROM `news` WHERE news_id!=$news_id AND cat=$cat AND keywords LIKE '%$kw%' ORDER BY news.published DESC";
  39. $query_limit_kw = sprintf("%s LIMIT %d, %d", $query_kw, $startRow_kw, $maxRows_kw);
  40. $kw = mysql_query($query_limit_kw, $news) or die(mysql_error());
  41. $row_kw = mysql_fetch_assoc($kw);
  42.  
  43. if (isset($_GET['totalRows_kw'])) {
  44.   $totalRows_kw = $_GET['totalRows_kw'];
  45. } else {
  46.   $all_kw = mysql_query($query_kw);
  47.   $totalRows_kw = mysql_num_rows($all_kw);
  48. }
  49. $totalPages_kw = ceil($totalRows_kw/$maxRows_kw)-1;
  50. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  51. <html xmlns="http://www.w3.org/1999/xhtml">
  52. <head>
  53. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  54. <title>News</title>
  55. </head>
  56.  
  57. <body>
  58. <h2>NEWS DETAIL PAGE    </h2>
  59. <h3>News</h3>
  60. <strong>Title: </strong><?php echo $row_regional['title']; ?><br />
  61. <strong>Date: </strong><?php echo $row_regional['created']; ?><br />
  62. <strong>Story: </strong><?php echo $row_regional['story']; ?><br />
  63. <h4>Other latest News </h4>
  64. <?php do { ?>
  65.   <a href="view.php?news_id=<?php echo $row_head['news_id']; ?>&cat=<?php echo $row_head['cat']; ?>"><?php echo $row_head['title']; ?></a><br />
  66.   <?php } while ($row_head = mysql_fetch_assoc($head)); ?><br /><br />
  67. <h4>Related News</h4>
  68. <?php do { ?>
  69.   <a href="view.php?news_id=<?php echo $row_kw['news_id']; ?>&cat=<?php echo $row_kw['cat']; ?>"><?php echo $row_kw['title']; ?></a><br />
  70.   <?php } while ($row_kw = mysql_fetch_assoc($kw)); ?> <br /><br />
  71. <br /> 
  72. <a href="index.php">HOME 
  73. </a>
  74. </body>
  75. </html>
  76. <?php
  77. mysql_free_result($regional);
  78.  
  79. mysql_free_result($head);
  80.  
  81. mysql_free_result($kw);
  82. ?>
  83.  
----------

What I am trying to do is that If I am viewing a page that contain John, at the related news I just want the other Title that contain the keywords John to be shown. But in my case that appear all news which cat is the same.

Please have a look at my code and correct. Do I write query wrong or Do I build my database table for keywords wrong or How do I do????????????

Your help is much appreciate
Thanks in advance
Gawn
Nov 28 '06 #1
0 1630

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bill | last post by:
I have only a cursory knowledge of Microsoft's Application Blocks, which seem like they might be pretty cool. I'm wondering if any of these (such as the Exception Handling Application Block) can be...
0
by: Gary N | last post by:
Sr. Database Administrator Permanent Position/Pittsburgh Pa $70-95K with full benefits Description A client of A.C.Coy's is looking for a Senior Database Administrator to join their team on a...
0
by: Hanuman | last post by:
Hi, On the IBM host we use a product called RDX that lets us copy "related" table data from the QA and prod environments to our UT environments. For example if we provide a CustomerID as input...
0
by: elvin | last post by:
Okay - apologize in advance for the length, but I want to make sure all you knowledgeable and helpful people have all the details you need to hopefully point my newbie rear in the right direction....
8
by: Chul Min Kim | last post by:
Hi, I got a BUS ERROR from one of my company's program. Let me briefly tell our environment. Machine : Sun E3500 (Ultra Sparc II 400Mhz CPU 4EA) OS : Solaris7 Compiler : Sun Workshop...
2
by: Danial Juka | last post by:
Hi All, I am making a content management system in asp.net. I want to show max 5 related links to other articles that somehow relate to the current article. An example of what I am looking...
5
AccessIdiot
by: AccessIdiot | last post by:
Argh! Just when I think everything is working and I am doing one final test before showing it to the guys I built the db for, Access throws out a weird message and won't let me add a record. But only...
4
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect">...
1
by: all chek all | last post by:
hello dear how are you ? i want script news for download plaese answer me. salim akrami 'iran'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.