1

This didn't return any helpful google results, so I'll just ask it here:

Is it possible in PHP to start another query inside another query's fetch statement after executing() the first query?

e.g.

if ($stmt=mysqli->prepare(query)) {
    $stmt->bind_param('s', $variable);
    $stmt->execute();
    $stmt->store_result();
    while ($stmt->fetch()) {
         if ($stmt2=mysqli->prepare(query2)) {
              $stmt2->bind_param('s', $othervariable);
              $stmt2->execute();
              $stmt2->store_result();
              while ($stmt2->fetch()) {
                  store result or something
              }
         }
    }
}
user2415992
  • 481
  • 7
  • 22
  • It's possible, but it should better be created as one single join query. Database administrators and web hosting companies HATE people who cannot optimize their database queries a bit. – Sven Aug 08 '13 at 21:52
  • what do you mean by "single join query"- could you just write a basic example about what a JOIN query looks like? – user2415992 Aug 08 '13 at 21:57
  • It makes no sense to have one query, and per result execute another query that has no connection with the first and will simply be done again and again without and differences. Usually a result from the first query will affect the second query. And this should be avoided and resolved by using a `JOIN` to combine more than one table in a query. `SELECT stuff FROM table1 LEFT JOIN table2 ON table1.id = table2.subid` ... – Sven Aug 08 '13 at 22:11
  • k thank you- i'll work on implementing this in my program – user2415992 Aug 08 '13 at 22:51

0 Answers0