Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Data to new table!

Status
Not open for further replies.

CrazyCrack

Technical User
Mar 9, 2007
3
CA
I having a little problem with that script!
I explain:
The script do half of work, the script dublicate succesfully the data from copy the row in the _hosting_order_data. But I dont understand why it dont copy the new row in the _hosting_order_option.


This is the script:

Copy data from <br><form action="admin.php?op=Order&amp;action=CopyData&amp;id=<? echo $_GET['id']; ?>" method="post">
<select name="CopyData">
<? $sql = "SELECT id, name FROM ".$prefix."_hosting_order";
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
?> <option value="<? echo $row['id'];?>"><? echo $row['name'];?></option>
<? }
?> </select><Br><input type="submit" name="submit" value="Go"></form>






function CopyData()
{
global $db, $prefix;
$sql = "SELECT id, description, type, required FROM ".$prefix."_hosting_order_data WHERE pid = '".$_POST['CopyData']."'";
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$sql = "INSERT INTO ".$prefix."_hosting_order_data SET description='".$row['description']."', type='".$row['type']."',
required='".$row['required']."', pid='".$_GET['id']."'";
$db->sql_query($sql);
if($row['type'] == 'Option')
{
$sql2 = "SELECT id FROM ".$prefix."_hosting_order_data WHERE pid = '".$_GET['id']."' ORDER BY id ASC";
$result2 = $db->sql_query($sql2);
while($row2 = $db->sql_fetchrow($result2))
$insertid = $row2['id'];

$sql2 = "SELECT description, price FROM ".$prefix."_hosting_order_options WHERE pid = '".$row['id']."'";
$result2 = $db->sql_query($sql2);
while($row2 = $db->sql_fetchrow($result2))
{
$sql = "INSERT INTO ".$prefix."_hosting_order_options SET description='".$row2['description']."', price='".$row2['price']."',
pid='".$insertid."'";
$db->sql_query($sql);
}
}
}
header("Location: admin.php?op=Order&action=editOrder&id=".$_GET['id']);
}
 
Possibly this query returns no rows.
Code:
SELECT description, price 
FROM ".$prefix."_hosting_order_[COLOR=red]options[/color] 
WHERE pid = '".$row['id']."'";

Is it possible you meant this?
Code:
SELECT description, price 
FROM ".$prefix."_hosting_order_[COLOR=red]data[/color] 
WHERE pid = '".$row['id']."'";
 
No its not that. Its suppose to take the value in order_data (ID) and add it on order_options (PID)
 
Right. Which table is $sql2 taking values from?
 
Its suppose to take the value in order_data (ID) and add it on order_options (PID).
So it take the valu from order_data table! Im suppose is what you want to know!
 
Your code defines two different queries for $sql2
Code:
...
$sql2 = "SELECT id FROM ".$prefix."_hosting_order_data WHERE pid = '".$_GET['id']."' ORDER BY id ASC";
            $result2 = $db->sql_query($sql2);
            while($row2 = $db->sql_fetchrow($result2))
                $insertid = $row2['id'];

            $sql2 = "SELECT description, price FROM ".$prefix."_hosting_order_options WHERE pid = '".$row['id']."'";
            $result2 = $db->sql_query($sql2);
...

The first one obtains a value for id from the order_data table.
The second one obtains values for description and price from the order_options table.

But there is not yet any row in the order_options table with that id.

At least that is how I read your code.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top