Jump to content

mysqli_multi_query ...trouble streamlining


fivestringsurf

Recommended Posts

Good afternoon, I've been trying to slim some of my code down (mysql 5/php 5) by using mysqli_multi_query.  I'm stumped on the retrieval of what I need:  with mysqli_query() i've always done the usual and retrieved data by using the mysql_fetch_array...because i like being able to refer to field names in my retrieval

 

When using fetch array with mysqli_multi_query() function  i get errors unless i wrap each array key in an if statement like this:

if(array_key_exists('author',$row)){
               		printf("%s\n", $row['author']);
}
             if(array_key_exists('content',$row)){
               		printf("%s\n", $row['author']);
}
        

That seems like an unecessay pain in the you know what...checking for array keys each time

here's the full code  (just as one would get from php.net with my additions)

$query  = " SELECT author FROM author ; ";
$query .= "SELECT content,title, part, partTotal,datePublished FROM content";
/* execute multi query */
if (mysqli_multi_query($link, $query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_array($result)) {
                if(array_key_exists('author',$row)){
               		printf("%s\n", $row['author']);
}          
       }
            mysqli_free_result($result);
        }
        /* print divider */
        if (mysqli_more_results($link)) {
            printf("-----------------\n");
        }
    } while (mysqli_next_result($link));
}

 

There's got to be a smoother way to retrieve all data according to the fields i select in this multi query?

Link to comment
https://forums.phpfreaks.com/topic/194185-mysqli_multi_query-trouble-streamlining/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.