First, be sure to use a Many-to-many table (called "yourPrimaryTable_has_questions" in my below schema) between your questions table and the primary table which represents the page.
Then cycle through the questions, and add a row for each in your many-to-many table. If you use a name with brackets but no value in the brackets, it will auto-increment when your PHP server receives the data.
if (isset($_POST) && $_POST && $_POST['questions'])
{
echo("<form name='xxx'>");
foreach($_POST['questions'] as $question)
{
//Insert record with answer into your many to many table
}
echo("</form>");
}
else
{
for ($i = 1; $i <= $count; $i++) {
echo("Question {i} <input name='question[] type='text' /><br>");
}
}
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`questions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`questions` (
`id` INT NOT NULL AUTO_INCREMENT ,
`otherData` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`yourPrimaryTable`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`yourPrimaryTable` (
`id` INT NOT NULL AUTO_INCREMENT ,
`otherData` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`yourPrimaryTable_has_questions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`yourPrimaryTable_has_questions` (
`yourPrimaryTable_id` INT NOT NULL ,
`questions_id` INT NOT NULL ,
`answer` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`yourPrimaryTable_id`, `questions_id`) ,
INDEX `fk_yourPrimaryTable_has_questions_questions1_idx` (`questions_id` ASC) ,
INDEX `fk_yourPrimaryTable_has_questions_yourPrimaryTable_idx` (`yourPrimaryTable_id` ASC) ,
CONSTRAINT `fk_yourPrimaryTable_has_questions_yourPrimaryTable`
FOREIGN KEY (`yourPrimaryTable_id` )
REFERENCES `mydb`.`yourPrimaryTable` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_yourPrimaryTable_has_questions_questions1`
FOREIGN KEY (`questions_id` )
REFERENCES `mydb`.`questions` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;