473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to input content for particular topic to database in php?

36
I have recent topics displayed on my home page . When i click on any topic , it opens in a new page with full details of that topic . There is an option( a form ) where users can write review for that particular topic .

Question : How do i select number of reviews of a particular topic from table to display next to it on home page ?

This is my 1st table for Topics.
Expand|Select|Wrap|Line Numbers
  1. Topic_Id  -  1 , 2 , 3  
  2. Title  -  First Topic , Second Topic , Third Topic 
  3. Category_ID  -   3 , 1 , 1  
  4. Date  -   yyyy-mm-dd
  5.  
This is my 2nd table for Category.
Expand|Select|Wrap|Line Numbers
  1. Category_ID  -  1 , 2 , 3
  2. Category_name   -  PHP , MYSQL , PDO
  3.  
This is to input .
Expand|Select|Wrap|Line Numbers
  1. try 
  2.    {
  3.    $query = $conn->prepare("INSERT INTO `topics`     (title,category_id) VALUES  (:title,:category_id)");
  4.  
  5.    $query->execute(array(
  6.         'title'       => $_POST['title'],
  7.         'category_id' =>    $_POST['category_id'],
  8.                                     )); 
  9.         }
  10.  
  11.    catch (PDOException $e) 
  12.    {
  13.    error_log($e->getMessage());
  14.    die($e->getMessage());
  15.    }
  16.  
This is to display on home page .
Expand|Select|Wrap|Line Numbers
  1.    $sql = "SELECT * FROM review ORDER by pid DESC limit  0,3";
  2.  
  3.    $q    = $conn->query($sql);
  4.  
  5.    $q->setFetchMode(PDO::FETCH_ASSOC);
  6.  
  7.    while($row = $q->fetch()){
  8.       echo $row['title'];
  9.       echo $row['username'];
  10.    }
  11.  
  12.  
This is my 3rd table for inserting reviews .
Expand|Select|Wrap|Line Numbers
  1. Topic_ID  -  
  2. Rating  -  
  3. Review  -  
  4. User_ID  -
  5.  
Jan 24 '13 #1
1 1328
Rabbit
12,516 Expert Mod 8TB
You can run a count(*) query grouping by your topic and use that to output the number of reviews next to each topic.
Jan 24 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roderik | last post by:
Hi, When developing a website in general when should I choose to put content in a database. For menu options, settings, and listings like products it seems to be clear for me to put them in. But...
3
by: Dave | last post by:
I would like to create an application which gives the user a grid type interface for input, but is not connected to a database. I would save the grid contents to an array for manipulation. Is...
1
by: newhaven_lad | last post by:
Please could someone help, I have a Perl cgi script which works perfectly when run in a dos prompt, it connects to a database on my laptop and inserts a record. But when I use the internet browser...
1
by: Harry.PharmTouch | last post by:
My company is seeking a software solution for the following scenario. Please let me know if you have any suggestions. We are a small consulting company that services nursing homes. We need to...
2
by: shapper | last post by:
Hello, Is it possible to create a class in Asp.Net, give values to its properties and save it in a database for later retrieval? How can I do this? Thanks, Miguel
2
by: Phaelle | last post by:
hello I am doing a search engine for a library and I would like to offer the users the possibility of choosing a kind of document (video, audio, music sheet...) thanks to a check box . But the...
0
by: balean | last post by:
Hi guys, I need help. I am trying to extract data from XML file. I am using all the fucntions needed to parse the xml data every thing working fine, but what I am looking for is to take the string...
21
by: fjm | last post by:
Hello everyone. :) I knew it wouldn't be very long before I was back with another question. I just created a login box on my site and I am having an issue with trying to echo an error back to...
1
by: pompy | last post by:
I've cleared the MS Access data base and pasted something else in it, also closing the data base afterwords. Is there a possibility, to recover the cleared content after closing the MS Access?
2
by: arianule | last post by:
hallo I am a bit new with asP.net and I want to use a webservice to add information to a database. It is easy enough to establish a connection with the database using a Web Method but to add...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.