JustRandomGuy
JustRandomGuy

Reputation: 41

SQL returns 2 of the 3 rows

I'm trying to select something from a table and insert that information into another table For example I've 3 rows in table A which I want to insert into table B, he only inserts 2 of the 3.

I got this: I've tried it with fetch_array() but I get only the error non-object

EDIT: THE PART OF THE SCRIPT

    $log = $db->query("SELECT itemname FROM log_mitem WHERE mobname = '".$mobname."' AND game = '".$game."'") or die($db->error);
    if($log1 = $log->fetch_object());
    {
        while($loco = $log->fetch_object())
    {

Upvotes: 0

Views: 42

Answers (1)

dynamic
dynamic

Reputation: 48101

You shouldn't have that first if, just do:

$log = $db->query("SELECT itemname FROM log_mitem WHERE mobname = '".$mobname."' AND game = '".$game."'") or die($db->error);
while($loco = $log->fetch_object()) {
 // do something
}

Also note that you don't need a while loop for this trivial task, you can use INSERT INTO ... SELECT syntax

INSERT INTO table1 ( column1 )
SELECT  col1
FROM    table2  
WHERE   cond1

Upvotes: 5

Related Questions