Jump to content


Photo

Multiple Queries


  • Please log in to reply
2 replies to this topic

#1 Kaitosoto

Kaitosoto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 October 2006 - 11:34 AM

I found this, but I dont get how multiple queries work. Do all queries have to be stored in variables? If so, then how in the world do I execute an update query or replace? Can someone please tell me and if possible, show me an example?

<?php

function connectDb($user, $pass, $host, $db) {
    //this function connects to a mysql server
    $sock = mysql_connect($host, $user, $pass);
   
    //this function connects to a mysql database, once a server has been reached.
    if(isset($sock)) {
        if(!mysql_select_db($db, $sock)) {
            echo mysql_error();
        }
    }
    return $sock;
}


//simple use of the function
$socket = connectDb('bilbo','b@gg1ns','localhost','test');

//create an sql query
$sql = "SELECT *  FROM sample";

//perform the query and return a resource identifier to $query
$query = mysql_query($sql, $socket);

//show all the data via a while loop
while($data = mysql_fetch_assoc($query)) {
    //using foreach, list all the data that was returned in the $data array from mysql_fetch_assoc
    foreach($data as $key => $value) {
        echo $key.' = '.$value.'<br />';
    }
    echo '<br />';
}

?>


#2 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 18 October 2006 - 12:17 PM

This is a single query loading data into a variable array to be used later. The variable being $key
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:17 PM

Yes, you have to issue a separate call to mysql_query() for each query... I'm not sure what you're confused about.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users