473,748 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any GURU help for "related news" script

2 New Member
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 1669

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

Similar topics

0
1416
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 considered related to Aspect Orientated Programming (AOP)?
0
1990
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 permanent basis in Pittsburgh PA. Requirements Bachelor's degree, or equivalent experience in computer science or
0
1106
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 it will retrieve related tables like CustTransaction and CustHistory and so on (so long as the relations are defined to RDX) Is there a way to use the output of this RDX to load the UDB tables on the LAN? Is there another product that will do...
0
3206
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. I've got a fairly complex (a lot more complex than originally intended) database with three main tables. The database is designed to track information about certain files. The tables are set up with one to one relationships, primarily because...
8
3377
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 5.0 cc complier I get "BUS ERROR" only when I execute the binary which builds
2
1591
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 for would be "SEE ALSO:" section at http://news.bbc.co.uk/2/hi/asia-pacific/3592928.stm Bottom line: 1, how can we get related links of an article? 2, what this
5
5004
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 SOMETIMES. I am getting "You cannot add or change a record because a related record is required in table "tbl_Entrianment". The only thing that relates the two tables in question is the Entrainment_ID WHICH I CAN SEE ON MY FORM. Let me back...
4
2050
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"> <option id="thisone" class="message">THANK YOU</option> </select>
1
1387
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
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.