Jump to content

duplicating rows


canabatz

Recommended Posts

Hi ,im face little problem in duplicating rows.

 

it's not easy task wht i need:

 

i got this rows right now

 

id----------position-------------A_Q_ID

1---------------1--------------------5-----

2---------------2--------------------5-----

3---------------3--------------------5-----

4---------------1--------------------6-----

5---------------2--------------------6-----

6---------------3--------------------6-----

 

what i need is to duplicat all the rows and have them inserted after the rows i allready have  like that:

 

id------------position-------------A_Q_ID

7-----------------1--------------------7-----

8-----------------2--------------------7-----

9-----------------3--------------------7-----

10---------------1--------------------8-----

11---------------2--------------------8-----

12---------------3--------------------8-----

 

i tryed few ways without success .

any idea how to do that please? i cannot get the logic on doing it :(

 

thanks

Link to comment
Share on other sites

thats a funny answer :)

 

i felt bored so i ask this question :)

 

i need it my friedn , im duplicating few tables and this one is my problem.

 

im building a survey website ,and i want to build a ready made survey so people can duplicate ready made survey to there account.

 

everything is working fine , only this table is hard...

 

thanks

Link to comment
Share on other sites

im building a survey website ,and i want to build a ready made survey so people can duplicate ready made survey to there account.

 

that's not explaining what i need?

 

you dont need to help if you dont know how to do it.

 

 

people asking question when they need help.

 

if you see some websites i develop then you wont say poor design , you dont know who you talking to!!

 

thanks any way for your "help"

 

 

 

Link to comment
Share on other sites

1. People who help here do so out of courtesy and compassion

2. The particular person who has been attempting to help you DOES know what he is talking about

3. Rudeness does NOTHING to help you

4. When a question/request makes NO sense AND the person asking remains closed minded as to PROPER solutions, it makes it very very difficult for other to feel any compassion toward their situation.

 

Perhaps an apology to Thorpe and the community as a whole is in order (and maybe an attitude adjustment)

Link to comment
Share on other sites

Thanks litebearer, but I do have a tendency to be pretty blunt. Mostly due to frustration. I know I shouldn't bother.

 

To the op:

 

Think about it. Why would you need multiple copies of the same survey stored? You don't. Simple.

 

Duplicate data almost always points to poor design.

 

A better question seeing as you don't seem to understand how to do it well is. "How could I link multiple surveys to multiple accounts" or similar.

 

You basically need three tables. One to store all the questions, each row also needs a column linking it to the next table. The next table could store the name of the server and the id linking it to the previous table. You then use this same id to link each survey to a users account.

Link to comment
Share on other sites

Rudeness?

 

it's you!

 

i was asking a simple question to problem im trying to fix.

 

you said that it is poor desing!! not me.

 

dont judge people with what you know! probably you don't know everything.

 

and please , if you want to help do that.

Link to comment
Share on other sites

im stuck here:

 

i got this for example , this i s not the real table, the real table is very complicated.

i can copy the all table and it's fine, but the A_Q_ID is my problem.

 

what i try'd was to get the MAX(A_Q_ID) to add +1 to the duplicated data.

but there is 3 in this example with same id.

 

id----------position-------------A_Q_ID

1---------------1--------------------5-----

2---------------2--------------------5-----

3---------------3--------------------5-----

4---------------1--------------------6-----

5---------------2--------------------6-----

6---------------3--------------------6-----

 

what i need to have after the copy is like that:

 

result example:

 

id------------position-------------A_Q_ID

7-----------------1--------------------7-----

8-----------------2--------------------7-----

9-----------------3--------------------7-----

10---------------1--------------------8-----

11---------------2--------------------8-----

12---------------3--------------------8-----

 

 

how can i add +1 to the duplicated A_Q_ID for the result table in my example?

 

thanks

Link to comment
Share on other sites

i told you.

 

im building a survey site.

 

users can build surveys and send them to who they want.

 

the client who i made this site for him ,he want to build Template survey's so the users can copy them to they account and modify them

for what they need.

 

what i did was to create one account and build few templates and add a link to see surveys example .

on every example survey i will add a copy button so register users can copy the survey to they account.

 

each survey are using 3 different tables.

 

1 survey

2 survey question

3 survey answer

 

im stuck with the survey question.

 

normaly when you add new question it gives it a question ID.

 

in my example ,a question have 3 answer options.

 

so you have question position for the 3 answer ,and question id is the same.

 

what i need is to duplicate survey with more questions .

 

so if A_Q_ID have 1 1 1 2 2 2 the copy i need is 3 3 3 4 4 4.

 

thats it ,sorry for my bad explanation and my bad English

 

thanks

 

Link to comment
Share on other sites

here is the code im using right now to just copy from other survey, only the answer option.

 

$sqlSURVEY_A=mysql_query("SELECT `admin_id`, `ans_id`, `ans_caption`, `ans_position`, `ans_su_id`   FROM `xp_survey_answer`  where ans_su_id='".$_GET['SUR_ID']."'")or die(mysql_error());


while ($rowSURVEY_A=mysql_fetch_assoc($sqlSURVEY_A))
{

$ans_caption=     $rowSURVEY_A['ans_caption'];
$ans_position=    $rowSURVEY_A['ans_position'];
$ans_su_id=       $rowSURVEY_A['ans_su_id'];
$ans_q_id=       $rowSURVEY_A['ans_q_id']; // the one i need to get the MAX() and add +1 , if you got 3 answers then it's the same id

$copy_AM=mysql_query("INSERT INTO `xp_survey_answer`

(`admin_id`, `ans_id`, `ans_caption`, `ans_position`, `ans_su_id`, `ans_q_id`) 

VALUES 

('$adminid','','$ans_caption','$ans_position','$suid','$ans_q_id')")or die(mysql_error());


}

Link to comment
Share on other sites

Thanks all for the help.

 

i did it by my self and im happy.

maybe it's not the best way but i did some good combinations.

$sqlSURVEY_AnsSUid=mysql_query("SELECT *  FROM `xp_survey_answer` ")or die(mysql_error());

while ($rowSURVEY_Ans=mysql_fetch_array($sqlSURVEY_AnsSUid))
{
$ans_su_id[]=$rowSURVEY_Ans['ans_su_id'];
}

$str2 = implode(',',array_unique($ans_su_id));
$zz4= count(explode(",",$str2));

echo $zz4."<br>";

$sqlSURVEY_Amax=mysql_query("SELECT max(ans_q_id) as maxq  FROM `xp_survey_answer` ")or die(mysql_error());
$rooo=mysql_fetch_assoc($sqlSURVEY_Amax);

$maxq=$rooo['maxq'];




$sqlSURVEY_Ac=mysql_query("SELECT *   FROM `xp_survey_answer`  where ans_su_id='".$_GET['SUR_ID']."'")or die(mysql_error());
$a=0;

while ($rowSURVEY_Ac=mysql_fetch_array($sqlSURVEY_Ac))
{
$ans_q_id[]=$rowSURVEY_Ac['ans_q_id'];
echo $ans_q_id[$a]."<br>";

$a++;
}

$str1 = implode(',',array_unique($ans_q_id)); // add quote to seprate number of strings
echo "<br>".$str1; // 33,34
$zz= count(explode(",",$str1)); // count the number to add plus
echo "<br>".$zz; // 2

$zz1=explode(",",$str1);


$sqlSURVEY_A=mysql_query("SELECT *   FROM `xp_survey_answer`  where ans_su_id='".$_GET['SUR_ID']."'")or die(mysql_error());
while ($rowSURVEY_A=mysql_fetch_assoc($sqlSURVEY_A))
{


$ans_caption=     $rowSURVEY_A['ans_caption'];
$ans_position=    $rowSURVEY_A['ans_position'];
$ans_su_id=       $rowSURVEY_A['ans_su_id'];


$ans_q_id=$rowSURVEY_A['ans_q_id'];

for ($i=0; $i<=$zz; $i++)
{
if ($ans_q_id==$zz1[$i]){$ans_q_id=($ans_q_id+($maxq / $zz) )+ $zz4;}

}



$copy_AM=mysql_query("INSERT INTO `xp_survey_answer`

(`admin_id`, `ans_id`, `ans_caption`, `ans_position`, `ans_su_id`, `ans_q_id`) 

VALUES 

('$adminid','','$ans_caption','$ans_position','$suid','$ans_q_id')")or die(mysql_error());




}

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.