php mySQL Problem

Reply

Join Date: Dec 2007
Posts: 4
Reputation: djcritch is an unknown quantity at this point 
Solved Threads: 0
djcritch djcritch is offline Offline
Newbie Poster

php mySQL Problem

 
0
  #1
Dec 19th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: php mySQL Problem

 
0
  #2
Dec 20th, 2007
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)

  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.

  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.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: jyshr is an unknown quantity at this point 
Solved Threads: 0
jyshr jyshr is offline Offline
Newbie Poster

Re: php mySQL Problem

 
0
  #3
Dec 20th, 2007
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
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC