This topic is locked

SQL QUERY HELP NEEDED!

6/11/2009 12:48:20 PM
PHPRunner General questions
A
Azeem author

Hello to all!
I am immediately in need to know the solution to the following scenario.

There are three tables

  1. clients 2. payments 3. plots
    There is customer application form in which there is a field in which plotID is selected from a drop down list from the plots table containing the plot number and plot category. There is a foreign key clientID in plots table. By the time form is submitted I want to store the clientID in the plots table relatibve to the plot ID selected.

    Can anybody advise please......
    I will be so thankful....

S
swanside 6/11/2009

If Plot is the main table, I would have PlotId as my Key.
I would then have PlotId on the other tables to link everything by.
I would still have ClientId as a key on the Clients Table, and PaymentId as a key on the payments table.
Then from Plot Add_new you would put in the details, I would have a field called clients and select the client from the clients table. This would generate an Id value of say 100001. As the Clients and Payments are linked by PlotId, From teh Plots table add_new, when you click on add new in the clients field, it would generate a cleintId in the clients table.
The payments table would contain links to plots and clients.

A
Azeem author 6/11/2009

If Plot is the main table, I would have PlotId as my Key.

I would then have PlotId on the other tables to link everything by.
I would still have ClientId as a key on the Clients Table, and PaymentId as a key on the payments table.
Then from Plot Add_new you would put in the details, I would have a field called clients and select the client from the clients table. This would generate an Id value of say 100001. As the Clients and Payments are linked by PlotId, From teh Plots table add_new, when you click on add new in the clients field, it would generate a cleintId in the clients table.
The payments table would contain links to plots and clients.



-------------------------------

Hello swanside,

Thank a lot for your reply...But i think clients table is the master table though logically you are right its plots table that should be the main table...I am writing here the database schema for you.Please tell me if u have some suggestions. Main scenario is such that a client can have more than one plots and we have to maintain the details of the payments as well...
-- phpMyAdmin SQL Dump

-- version 3.0.1.1

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Jun 11, 2009 at 06:17 PM

-- Server version: 5.1.30

-- PHP Version: 5.2.7
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;

/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;

/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;

/!40101 SET NAMES utf8 /;
--

-- Database: `phprunner`

--
-- --------------------------------------------------------
--

-- Table structure for table `clients`

--
CREATE TABLE `clients` (

`client_id` int(11) NOT NULL AUTO_INCREMENT,

`plot_ID` int(11) NOT NULL,

`status` int(10) NOT NULL,

`path` varchar(100) NOT NULL,

`path2` varchar(100) NOT NULL,

`date_issue` date DEFAULT NULL,

`date_enter` date DEFAULT NULL,

`username` varchar(20) DEFAULT NULL,

`fhname` varchar(30) NOT NULL,

`gender` varchar(10) NOT NULL,

`nic_no` varchar(30) NOT NULL,

`nicop_no` varchar(30) NOT NULL,

`passport_no` varchar(40) NOT NULL,

`place_issue` varchar(40) NOT NULL,

`present_address` varchar(40) NOT NULL,

`pak_address` varchar(40) NOT NULL,

`phone_off` varchar(25) NOT NULL,

`fax` varchar(25) NOT NULL,

`email` varchar(30) NOT NULL,

`phone_res` varchar(25) NOT NULL,

`cpp_name` varchar(30) NOT NULL,

`cpp_phone` varchar(30) NOT NULL,

`cpp_address` varchar(40) NOT NULL,

`nic_copy` varchar(10) NOT NULL,

`nicop_copy` varchar(10) NOT NULL,

`pass_copy` varchar(10) NOT NULL,

PRIMARY KEY (`client_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;
-- --------------------------------------------------------
--

-- Table structure for table `payments`

--
CREATE TABLE `payments` (

`Payment_ID` int(11) NOT NULL AUTO_INCREMENT,

`client_id` varchar(10) NOT NULL,

`PMethod` varchar(50) DEFAULT NULL,

`No_Istallments` varchar(50) DEFAULT NULL,

`Amount_Paid` varchar(50) DEFAULT NULL,

`Amount_Due` varchar(50) DEFAULT NULL,

`Payment_Terms` mediumtext,

`Cheque_No` varchar(50) DEFAULT NULL,

`Notes` mediumtext,

`Date` date DEFAULT NULL,

`Bank_No` varchar(20) DEFAULT NULL,

PRIMARY KEY (`Payment_ID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
-- --------------------------------------------------------
--

-- Table structure for table `plots`

--
CREATE TABLE `plots` (

`plot_ID` int(11) NOT NULL AUTO_INCREMENT,

`plot_no` varchar(45) NOT NULL,

`plot_cat` varchar(10) NOT NULL,

PRIMARY KEY (`plot_ID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=198 ;
Thanks for your assistance...

A
Azeem author 6/11/2009



-------------------------------

Hello swanside,

Thank a lot for your reply...But i think clients table is the master table though logically you are right its plots table that should be the main table...I am writing here the database schema for you.Please tell me if u have some suggestions. Main scenario is such that a client can have more than one plots and we have to maintain the details of the payments as well...
-- phpMyAdmin SQL Dump

-- version 3.0.1.1

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Jun 11, 2009 at 06:17 PM

-- Server version: 5.1.30

-- PHP Version: 5.2.7
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;

/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;

/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;

/!40101 SET NAMES utf8 /;
--

-- Database: `phprunner`

--
-- --------------------------------------------------------
--

-- Table structure for table `clients`

--
CREATE TABLE `clients` (

`client_id` int(11) NOT NULL AUTO_INCREMENT,

`plot_ID` int(11) NOT NULL,

`status` int(10) NOT NULL,

`path` varchar(100) NOT NULL,

`path2` varchar(100) NOT NULL,

`date_issue` date DEFAULT NULL,

`date_enter` date DEFAULT NULL,

`username` varchar(20) DEFAULT NULL,

`fhname` varchar(30) NOT NULL,

`gender` varchar(10) NOT NULL,

`nic_no` varchar(30) NOT NULL,

`nicop_no` varchar(30) NOT NULL,

`passport_no` varchar(40) NOT NULL,

`place_issue` varchar(40) NOT NULL,

`present_address` varchar(40) NOT NULL,

`pak_address` varchar(40) NOT NULL,

`phone_off` varchar(25) NOT NULL,

`fax` varchar(25) NOT NULL,

`email` varchar(30) NOT NULL,

`phone_res` varchar(25) NOT NULL,

`cpp_name` varchar(30) NOT NULL,

`cpp_phone` varchar(30) NOT NULL,

`cpp_address` varchar(40) NOT NULL,

`nic_copy` varchar(10) NOT NULL,

`nicop_copy` varchar(10) NOT NULL,

`pass_copy` varchar(10) NOT NULL,

PRIMARY KEY (`client_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;
-- --------------------------------------------------------
--

-- Table structure for table `payments`

--
CREATE TABLE `payments` (

`Payment_ID` int(11) NOT NULL AUTO_INCREMENT,

`client_id` varchar(10) NOT NULL,

`PMethod` varchar(50) DEFAULT NULL,

`No_Istallments` varchar(50) DEFAULT NULL,

`Amount_Paid` varchar(50) DEFAULT NULL,

`Amount_Due` varchar(50) DEFAULT NULL,

`Payment_Terms` mediumtext,

`Cheque_No` varchar(50) DEFAULT NULL,

`Notes` mediumtext,

`Date` date DEFAULT NULL,

`Bank_No` varchar(20) DEFAULT NULL,

PRIMARY KEY (`Payment_ID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
-- --------------------------------------------------------
--

-- Table structure for table `plots`

--
CREATE TABLE `plots` (

`plot_ID` int(11) NOT NULL AUTO_INCREMENT,

`plot_no` varchar(45) NOT NULL,

`plot_cat` varchar(10) NOT NULL,

PRIMARY KEY (`plot_ID`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=198 ;
Thanks for your assistance...


__
I am sorry for the last repy the correct db is as follows:
-- phpMyAdmin SQL Dump

-- version 3.0.1.1

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Jun 11, 2009 at 11:36 PM

-- Server version: 5.1.30

-- PHP Version: 5.2.7
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;

/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;

/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;

/!40101 SET NAMES utf8 /;
--

-- Database: `phprunner`

--
-- --------------------------------------------------------
--

-- Table structure for table `clients`

--
CREATE TABLE `clients` (

`client_id` int(11) NOT NULL AUTO_INCREMENT,

`date_issue` datetime NOT NULL,

`username` varchar(20) DEFAULT NULL,

`fhname` varchar(30) NOT NULL,

`gender` varchar(10) NOT NULL,

`img_path` varchar(100) NOT NULL,

`scan_copy_path` varchar(100) NOT NULL,

`nic_no` varchar(30) NOT NULL,

`nicop_no` varchar(30) NOT NULL,

`passport_no` varchar(40) NOT NULL,

`place_issue` varchar(40) NOT NULL,

`present_address` varchar(40) NOT NULL,

`pak_address` varchar(40) NOT NULL,

`phone_off` varchar(25) NOT NULL,

`fax` varchar(25) NOT NULL,

`email` varchar(30) NOT NULL,

`phone_res` varchar(25) NOT NULL,

`cpp_name` varchar(30) NOT NULL,

`cpp_phone` varchar(30) NOT NULL,

`cpp_address` varchar(40) NOT NULL,

`no_of_installments` int(10) NOT NULL,

`amount_per_installment` int(100) NOT NULL,

PRIMARY KEY (`client_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;
-- --------------------------------------------------------
--

-- Table structure for table `payments`

--
CREATE TABLE `payments` (

`payment_id` int(11) NOT NULL AUTO_INCREMENT,

`client_id` varchar(10) NOT NULL,

`method` varchar(50) DEFAULT NULL,

`cheque#` varchar(50) DEFAULT NULL,

`notes` mediumtext,

`date` datetime DEFAULT NULL,

`bank_acc#` varchar(20) DEFAULT NULL,

PRIMARY KEY (`payment_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
-- --------------------------------------------------------
--

-- Table structure for table `plots`

--
CREATE TABLE `plots` (

`plot_id` int(11) NOT NULL AUTO_INCREMENT,

`plot_no` varchar(45) NOT NULL,

`plot_cat` varchar(10) NOT NULL,

`client_id` int(11) NOT NULL,

`cost` int(100) NOT NULL,

`status` int(10) NOT NULL DEFAULT '0',

PRIMARY KEY (`plot_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=198 ;

A
Azeem author 6/13/2009

The scenario was like I had a customer apllication form for plots. Mostly getting the customer data and it has a droopdown field showing the available plots from the plots table where plots.clients_id='NULL' and status='Null'.
Now after the customer has selected a plot i want to store the client_id from the session variable into the plots.client_id (a foreign key from clients table) where plots.plot_id=selected plot id from the form.
The query i am trying to run does not store the value of the client id into the plots table. The query is as follows:
<?php

include("connect2db.php");

$plot_id=$_POST['plot_select'];

//echo $plot_id; //the value is printed

$client_id= $_SESSION['id'];

//echo $client_id;

$query="INSERT INTO plots(client_id) VALUES ($client_id) where plots.plot_id='$plot_id'";

$result=mysql_query($query);

?>
Please help...thanks is advance...

AZEEM

J
Jane 6/16/2009

Hi,
I recommend you to publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages. I'll try to help you.