Is there any way that I can change data from different columns but leave it in one variable?

Asked

Viewed 21 times

0

Summarizing.... Use multiple updates in one variable

Type: $query = 'update..... ; update.........'

Is there any way?

  • I think you better try to better formulate your question, at least me I don’t understand what you’re trying to do,

  • I understood your question (it was not easy) but to formulate the answer, I would have to know which driver you use: mysqli? PDO?

  • Excuse me..... I use mysqli

  • Wouldn’t be of different lines?

  • What the sgbd using?

  • This might help: http://stackoverflow.com/questions/6821184/how-do-you-do-multiple-sql-statments-in-one-mysql-query

Show 1 more comment

1 answer

2

You must be using the mysql_query, but accepts only one query. Try using mysqli::multi_query. An example;

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* verifica conexão */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query  = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";

/* executa a sua multi query */
if ($mysqli->multi_query($query)) {
    do {
        /* Faz print separado do resultado de cada query */
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->free();
        }
        /* separa cada resultado por traços */
        if ($mysqli->more_results()) {
            printf("-----------------\n");
        }
    } while ($mysqli->next_result());
}

/* fecha conexão */
$mysqli->close();
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.