943,958 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 693
  • PHP RSS
Dec 19th, 2007
0

php mySQL Problem

Expand Post »
heres the deal, i have created a table called tvprograms on a mySQL database and have added the fields id, program and comments and have populated the database.

The first thing i need to do is list just the programs in a php form but not the comments.

I then need to allow the user to select one of these programs and then display programs comments.

And finaly i need to allow the user to add a new program and comment to the database.

Can anyone help me with this as my coding is pretty poor!

Thanks guys

Merry Christmas!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
djcritch is offline Offline
4 posts
since Dec 2007
Dec 20th, 2007
0

Re: php mySQL Problem

If you need multiple comments, use 2 tables. One for the program details, and one for the comments. Use an id tag (preferably the unique key from the program details)

PHP Syntax (Toggle Plain Text)
  1. CREATE TABLE tvprograms (
  2. p_id int(11) NOT NULL UNIQUE AUTO INCREMENT,
  3. p_name char(40),
  4. p_desc tinytext,
  5. p_misc tinytext
  6. );
  7.  
  8. CREATE tvprograms_comment(
  9. pc_id int(11) NOT NULL UNIQUE AUTO INCREMENT,
  10. p_id int(11) NOT NULL,
  11. pc_text text
  12. );
  13.  
  14. -- SQL QUERY MAY CONTAIN ERRORS

Use simple select queries to list the programs. Then use the p_id value to list single program and the comments for the program.

PHP Syntax (Toggle Plain Text)
  1. SELECT * FROM tvprograms ORDER BY p_id DESC LIMIT 5; -- to list last 5 programs
  2.  
  3. SELECT * FROM tvprograms WHERE p_id=' $X '; --- to select one program
  4.  
  5. SELECT * FROM tvprograms_comment WHERE p_id=' $X '; -- to select all the comments for a single program.


I hope you get the idea how the 2 tables are being used to do what you need. One stores all the program details and the second stores all the comments, with each comment being tagged with an id number from the program details table.
Last edited by FireNet; Dec 20th, 2007 at 12:45 am.
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Dec 20th, 2007
0

Re: php mySQL Problem

to get the programs
you can try this
$aq = " select * from tvprograms";
$sh = mysql_query($aq);

$n = mysql_numrows($sh);
for($i = 0; $i < $n; $i++)
{$pro = mysql_result($sh,$i,"fieldname");
//here give link
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyshr is offline Offline
2 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Select matching records
Next Thread in PHP Forum Timeline: Retriving value through url





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC