boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help creating a simple article management system

 
Post new topic   Reply to topic    boardom Forum Index -> PHP help
View previous topic :: View next topic  
Author Message
Saus



Joined: 29 Mar 2002
Posts: 25

PostPosted: Thu May 15, 2003 6:37 am    Post subject: Need help creating a simple article management system Reply with quote

I need some help creating a simple article manager.

I just created a table with these properties.

Code:

CREATE TABLE phppull_mmarticlecats (
  catid int(2) unsigned NOT NULL auto_increment,
  catname varchar(80) default NULL,
  PRIMARY KEY  (catid)
) TYPE=MyISAM COMMENT='Article categories';


CREATE TABLE phppull_mmarticles (
  id int(6) unsigned NOT NULL auto_increment,
  artcategory int(2) NOT NULL default '0',
  artcreationdate datetime NOT NULL default '0000-00-00 00:00:00',
  artauthor varchar(30) NOT NULL default '',
  artauthoremail varchar(30) NOT NULL default '',
  arttitle varchar(80) NOT NULL default '',
  arttext longtext NOT NULL,
  arthits int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (id)
) TYPE=MyISAM COMMENT='Article info and body';


I have put 1 entry in this table.


I am now using this code to display the contents on a php page.


Code:

<?php

# Database server to connect to
$dbhost      =   "localhost";
# Database to use
$db      =   "myMaindatabase";
# Database username
$dbuser      =   "me";
# Database password
$dbpasswd   =   "password";
# Table to use
$table      =   "phppull-mmarticles";


// retrieve data from database

mysql_connect("$dbhost","$dbuser","$dbpasswd")
   or die("Unable to connect to SQL server!");
@mysql_select_db("$db")
   or die("Unable to select database!");

// place all database entries in $result
$query="SELECT * FROM $table";
$result=mysql_query($query);


// find out how many rows in database
$num=mysql_numrows($result);

mysql_close();


// loop to display raw data ----------------------------------------------------------------------------------------------------

if ($num==0) {
echo "$num rows in database. The database contains no info yet";
}


$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$artcategory=mysql_result($result,$i,"artcategory");
$artcreationdate=mysql_result($result,$i,"artcreationdate");
$artauthor=mysql_result($result,$i,"artauthor");
$artauthoremail=mysql_result($result,$i,"artauthoremail");
$arttitle=mysql_result($result,$i,"arttitle");
$arttext=mysql_result($result,$i,"arttext");
$arthits=mysql_result($result,$i,"arthits");

echo "<b>ID: $id</b><br>Category: $artcategory<br>Creation date: $artcreationdate<br>Author: $artauthor ( $artauthoremail )<br>Title: $arttitle<br>Text: $arttext<br>Hits: $arthits<br><hr><br>";

++$i;
}

?>




However, I get this error.

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/hsphere/local/home/cmwong/singaporeanimenews.net/mm-article.php on line 269
rows in database. The database contains no info yet


Notice that the number of rows in the database is not even filled in. I'm very sure there's 1 entry in the dbase coz I can view it with phpmyadmin. Does anyone know what's causing the error?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> PHP help All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group