Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old December 2nd, 2002, 08:12 PM
ncts_dodge_man ncts_dodge_man is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 8 ncts_dodge_man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to ncts_dodge_man Send a message via Yahoo to ncts_dodge_man
Modified News w/PHP and MySQL problem..

I'm trying to modify the PHP/MySQL News with comments tutorial (http://codewalkers.com/tutorials.php?show=19) The few modifications that I have put in are: 1) I don't use the comments, and 2) I only display the title, poster (added to the database), and date normally, then they click on the linked Title and it (is supposed to) display all the news info.

My problem is that whenever I click on the link for the displaying each individual news item, it does not work (example code: http://www.ehcwfed.com/test/mainsite.php )

php Code:
Original - php Code
  1.  
  2. <?PHP
  3. /* user config variables */
  4. $max_items = 8; /* max number of news items to show */
  5.  
  6. /* make database connection */
  7. $db = mysql_connect ('localhost','xxxx','xxxx');
  8. mysql_select_db ('news',$db);
  9.  
  10. function displayNews($all = 0) {
  11.     /* bring in two variables
  12.      * $db is our database connection
  13.      * $max_items is the maximum number
  14.      * of news items we want to display */
  15.     global $db, $max_items;
  16.    
  17.     /* query for news items */
  18.     if ($all == 0) {
  19.         /* this query is for up to $max_items */
  20.         $query = "SELECT id,poster,title," .
  21.                  "DATE_FORMAT(postdate, '%m-%d-%Y') as date " .
  22.                  "FROM newsdata ORDER BY postdate DESC LIMIT $max_items";
  23.     } else {
  24.         /* this query will get all news */
  25.         $query = "SELECT id,poster,title,newstext," .
  26.                  "DATE_FORMAT(postdate, '%m-%d-%Y') as date " .
  27.                  "FROM newsdata ORDER BY postdate DESC";
  28.     }
  29.     $result = mysql_query ($query);
  30.     while ($row = mysql_fetch_assoc ($result)) {
  31.         /* display news in a simple table */
  32.  
  33.  
  34.         /* place table row data in
  35.          * easier to use variables.
  36.          * Here we also make sure no
  37.          * HTML tags, other than the
  38.          * ones we want are displayed */
  39.         $date = $row['date'];
  40.         $title = htmlentities ($row['title']);
  41.         $poster = $row['poster'];
  42.         $id = $row['id'];
  43.        
  44.         /* display the data */
  45.         echo "<TR align="center"><TD id="tabblue"><a href="{$_SERVER['PHP_SELF']}" .
  46.              "?action=show&id=$id">$title</a> posted by $poster, on $date</TD></tr>n";
  47.     }
  48.    
  49. }
  50.  
  51. function displayOneItem($id) {
  52.     global $db;
  53.    
  54.     /* query for item */
  55.         $query = "SELECT id,poster,title,newstext," .
  56.                  "DATE_FORMAT(postdate, '%m-%d-%Y') as date " .
  57.                  "FROM newsdata " .
  58.                  "WHERE id=$id " .
  59.                  "ORDER BY postdate DESC";
  60.     $result = mysql_query ($query);
  61.    
  62.     /* if we get no results back, error out */
  63.     if (mysql_num_rows ($result) == 0) {
  64.         echo "Invalid news ID number.n";
  65.         return;
  66.     }
  67.     $row = mysql_fetch_array($result);
  68.     /* easier to read variables and
  69.      * striping out tags */
  70.     $date = $row['date'];
  71.     $poster = $row['poster'];       
  72.     $title = htmlentities ($row['title']);
  73.     $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>'));
  74.        
  75.     /* display the data */
  76.     echo "<TR align="center"><TD id="tabblue"><b>$title</b> posted by $poster, on $date</TD></tr>n";
  77.     echo "<tr align="center"><TD id="tabblue">$news</TD></TR>n";
  78. }
  79.  
  80. /* this is where the script decides what do do */
  81.  
  82. echo "<CENTER>n";
  83. switch($_GET['action']) {
  84.    
  85.     case 'show':
  86.     displayOneItem($_GET['id']);       
  87.         break;
  88.     case 'all':
  89.         displayNews(1);
  90.         break;
  91.     default:
  92.         displayNews();
  93.  
  94. }
  95. echo "</CENTER>n";
  96.  
  97. echo "</table>";
  98. echo "<br><a href="{$_SERVER['PHP_SELF']}" .
  99.        "?action=all">View all news</a>n";
  100. ?>

Reply With Quote
  #2  
Old December 3rd, 2002, 10:33 PM
ncts_dodge_man ncts_dodge_man is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 8 ncts_dodge_man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to ncts_dodge_man Send a message via Yahoo to ncts_dodge_man
RE: Modified News w/PHP and MySQL problem..

Bah.. Figured it out.. Couldn't use the $_GET on my server.. had to use $HTTP_GET_VARS..

Reply With Quote
  #3  
Old December 18th, 2002, 06:16 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Modified News w/PHP and MySQL problem..

Hi,
I'm new to php, and i'm having trouble creating a form to be able to post the news.
can anyone help me or give me the code to be able to do this?
-Jon

Reply With Quote
  #4  
Old December 18th, 2002, 06:23 AM
hermawan's Avatar
hermawan hermawan is offline
Superman is not dead
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Jakarta, Indonesia
Posts: 531 hermawan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 45 m 29 sec
Reputation Power: 2
Send a message via ICQ to hermawan Send a message via AIM to hermawan Send a message via Yahoo to hermawan Send a message via Google Talk to hermawan Send a message via Skype to hermawan
RE: Modified News w/PHP and MySQL problem..

Well Mr. Anonymous, we had to make sure what is wrong with your code. Before that, we really can't help much. Try to post your code and php engine specification.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Modified News w/PHP and MySQL problem..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway