0

I am trying to insert into a MySQL database the results of these statements. The daatbase is setup correctly. When I insert into a database I get 3 dots "..." rather than what I am suppose to get. the last one for tel stores correctly, only the first two do not store into the database but only dots.

for($i = 0; $i < 5; $i++){

    foreach($html->find('span.listado_destacado',$i) as $e){
      if(!empty($e->plaintext)){
        $list[$i] = $e->plaintext;
        echo $list[$i];
      }
    }

    foreach($html->find('span.street-address',$i) as $e){
      if(!empty($e->plaintext)){
        $addr[$i] = $e->plaintext;
        echo $addr[$i];
      }
    }

    foreach($html->find('span.tel',$i) as $e){
      if(!empty($e->plaintext)){
        $tel[$i] = $e->plaintext;
        echo $tel[$i];
      }
    }

    }//for

    for($i = 0; $i < 5; $i++){
      $res=mysql_query("insert into datos (list,addr,tel) values('".$list[$i]."','".$addr[$i]."','".$tel[$i]."')");


    }

2 Answers 2

1

There is an error in for loop correct code is as follows:

for($i = 0; $i < 5; $i++){

foreach($html->find('span.listado_destacado',$i) as $e){
  if(!empty($e->plaintext)){
    $list[$i] = $e->plaintext;
    echo $list[$i];
  }
}

foreach($html->find('span.street-address',$i) as $e){
  if(!empty($e->plaintext)){
    $addr[$i] = $e->plaintext;
    echo $addr[$i];
  }
}

foreach($html->find('span.tel',$i) as $e){
  if(!empty($e->plaintext)){
    $tel[$i] = $e->plaintext;
    echo $tel[$i];
  }
}

}//for

for($i = 0; $i < 5; $i++){
  $res=mysql_query("insert into datos (list,addr,tel) values('".$list[$i]."','".$addr[$i]."','".$tel[$i]."')");


}
Sign up to request clarification or add additional context in comments.

2 Comments

I was going to say that
sorry I had those in variables so I changed them to numbers for better understanding.
0

Give a try to DALMP - multipleinsert or Dalmp - AutoExecute

That can give you an idea of how to insert an array or multiple arrays in one shot.

Basically you prepare your array and later just insert it to the database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.