syedasimmeesaq
asked on
How to insert this data in one new table
I am showing the data to my visitors by selecting it from different tables. Now what I want to do is to transfer this data into one table exactly as it is presented to the visitors. How can I do that. Please find my code below to show the data to visitors. Thanks
<?php include('column.php') ?>
<body>
<table width="1954" border="2">
<tr>
<td width="213"> </td>
<td width="248">Question1</td>
<td width="289">Question2</td>
<td width="289">Question3</td>
<td width="289">Question4</td>
<td width="289">Question5</td>
<td width="289">Question6</td>
</tr>
<tr>
<td><strong>17266408</stro ng></td>
<td>
<?php $qu = "Select 79666X451X4679 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?> </td>
<td><?php $qu = "Select 79666X451X4680 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4681 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4682 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4683 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4684 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
</tr>
<tr>
<td><strong>18704956</stro ng></td>
<td><?php $qu = "Select 64468X447X4655 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4656 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4657 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4658 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4659 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4660 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result) )
{
echo "{$row[0]} <br>" ;
}
?></td>
</tr>
Thanks in advance
<?php include('column.php') ?>
<body>
<table width="1954" border="2">
<tr>
<td width="213"> </td>
<td width="248">Question1</td>
<td width="289">Question2</td>
<td width="289">Question3</td>
<td width="289">Question4</td>
<td width="289">Question5</td>
<td width="289">Question6</td>
</tr>
<tr>
<td><strong>17266408</stro
<td>
<?php $qu = "Select 79666X451X4679 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?> </td>
<td><?php $qu = "Select 79666X451X4680 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4681 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4682 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4683 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 79666X451X4684 from survey_79666";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
</tr>
<tr>
<td><strong>18704956</stro
<td><?php $qu = "Select 64468X447X4655 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4656 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4657 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4658 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4659 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
<td><?php $qu = "Select 64468X447X4660 from survey_64468";
$result = mysql_query($qu);
while($row = mysql_fetch_array($result)
{
echo "{$row[0]} <br>" ;
}
?></td>
</tr>
Thanks in advance
As an example something like this!
INSERT INTO new_table (Question1,Question2,Quest ion3,Quest ion4,Quest ion5,Quest ion6)
SELECT 79666X451X4679,79666X451X4 680,79666X 451X4681,7 9666X451X4 682,79666X 451X4683,7 9666X451X4 684 FROM survey_79666;
You will pretty much have the same query for your second lot in your example.
Hope you understand my example?
INSERT INTO new_table (Question1,Question2,Quest
SELECT 79666X451X4679,79666X451X4
You will pretty much have the same query for your second lot in your example.
Hope you understand my example?
ASKER
I tried to do this and this didn't insert any data
<?php
include('column.php');
$query = "INSERT INTO newdata (id,submitdate,startlangua ge,q1,q2,q 3,q4,q5,q6 ,q3,q4,q5, q6,q7,q8,q 9,q10,q11, q12,q13,q1 4,q15,q16, q17,q18,q1 9,q20,q21, q22,q23,q2 4,q25,q26, q27,q28,q2 9,q30,q31, q32,q33,q3 4,q35,q36, q37,q38,q3 9,q40,q41, q42,q43,q4 4,q45,q46, q47,q48,q4 9,q50,q51, q52,q53,q5 4,q55,q56, q57,q58,q5 9,q60,q61, q62,q63,q6 4,q65,q66, q67,q68,q6 9,q70,q71, q72,q73,q7 4,q75,q76, q77,q78,q7 9,q80,q81, q82,q83,q8 4,q85,q86, q87,q88,q8 9,q90,q91, q92,q93,q9 4,q95,q96, q97,q98,q9 9,q100,q10 1,q102,q10 3,q104,q10 5,q106,q10 7,q108,q10 9) SELECT * FROM survey_36145";
?>
Thanks
<?php
include('column.php');
$query = "INSERT INTO newdata (id,submitdate,startlangua
?>
Thanks
um what are you trying to do?
your table should only have 6 questions so ultimately each row has 6 columns (thus the 6 questions) and inserting into the new table there should be a lot of rows with 6 columns only. What you are trying to enter is a ot of questions, but when you select * from survey_36145 there is only 6 columns.
I hope you undrstand what I am getting at.
your table should only have 6 questions so ultimately each row has 6 columns (thus the 6 questions) and inserting into the new table there should be a lot of rows with 6 columns only. What you are trying to enter is a ot of questions, but when you select * from survey_36145 there is only 6 columns.
I hope you undrstand what I am getting at.
ASKER
no survey_36145 has exactly same rows as the newdata table now. The 6 rows was for other question that we are working on. This one is 113 rows
Thanks
Thanks
ASKER
I mean 113 columns
ASKER
should the column number be mattered if survey_36145 has exactly same columns as newdata all it should do is put all the data that is in survey_36145 into the newdata.
right?
Thanks
right?
Thanks
ASKER
any idea?
yes if the new table has the same amount of columns as the old table, all you have to do is:
INSERT into new_table SELECT * FROM old_table
As simple as that! :)
INSERT into new_table SELECT * FROM old_table
As simple as that! :)
ASKER
I tried that. It didn't work
The new and the old table STRUCTURE must be exactly the same, and yes, I tried it it does work so you must verify the structures are the same.
The easiest way is to create a new table like this:
CREATE TABLE new_table LIKE original_table;
then do the insert statement above:
INSERT into new_table SELECT * FROM old_table
All should work.
The easiest way is to create a new table like this:
CREATE TABLE new_table LIKE original_table;
then do the insert statement above:
INSERT into new_table SELECT * FROM old_table
All should work.
ASKER
ok the structure is exactly same. Only thing different(as you know) is the field names. I will recheck one more time and will let you know here shortly. The old table has 7 rows of data in it, do u think that could be a problem.
Thanks
Thanks
The structure has to be the same, i assume including field names (column names) and the number of columns there are. Rows do not matter, but columns are the important ones.
ASKER
Nizmo the field names are different. Thats why I need a fix for that so I don't have to enter field names everytime. Do you think there is a solution for that.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was hoping to use some kind of update query or insert query.
Thanks