IBM developerWorks
           Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
IBM developerWorks
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
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old April 15th, 2004, 08:53 PM
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
mysql_fetch_assoc(): problem in the news/comments tutorial

ok then. im trying to learn some php. i took matt wades code from the tutorial and i messed with it a whole bunch, only to see this:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource... on line 29

i thought that it was my tinkering that did it, so i went and copied the thing right from the tutorial, pasted it, uploaded it, and the same thing occured.

php Code:
Original - php Code
  1.  
  2.     if ($all == 0) {
  3.         /* this query is for up to $max_items */
  4.         $query = "SELECT id,title,newstext," .
  5.                  "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
  6.                  "FROM news ORDER BY postdate DESC LIMIT $max_items";
  7.     } else {
  8.         /* this query will get all news */
  9.         $query = "SELECT id,title,newstext," .
  10.                  "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
  11.                  "FROM news ORDER BY postdate DESC";
  12.     }
  13.     $result = mysql_query ($query);
  14.     while ($row = mysql_fetch_assoc ($result)) {
  15.         /* line 29 ^ this is causing the error*/
  16.         echo "<TABLE border="1" width="300">n";
  17.  
  18.         /* place table row data in
  19.          * easier to use variables.
  20.          * Here we also make sure no
  21.          * HTML tags, other than the
  22.          * ones we want are displayed */
  23.         $date = $row['date'];       
  24.         $title = htmlentities ($row['title']);
  25.         $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>'));


im seriously confused. im a newb. ive been sitting in front of this for a while, and ive tried different things. someone please throw me a bone. thanks a lot. maybe one day i can help people as lost as i am.

PHP v4.3.3
OS Linux

Reply With Quote
  #2  
Old April 15th, 2004, 10:35 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: mysql_fetch_assoc(): problem in the news/comments tutorial

There must be a problem with your query.

Add this after "$result = ..." and before "while(...":
php Code:
Original - php Code
  1.  
  2. if(!$result) die(mysql_error());


That should output whatever the error is.

Reply With Quote
  #3  
Old April 29th, 2004, 07:46 PM
sajuko sajuko is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Germany
Posts: 5 sajuko 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 sajuko
RE: mysql_fetch_assoc(): problem in the news/comments tutorial

i had the same problem, used the mysql_error() function and found out that i simply made a spelling mistake in the database the script selects

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > mysql_fetch_assoc(): problem in the news/comments tutorial


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


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





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