[snip]
Relatively new to PHP.  Having an issue trying to nest sql statements. 
Basically I am trying to pull a variable from SQL1, Pass it as a 
Variable/Bind or Parm to SQL2 and then Go back to SQL1 and pull the next

value and pass to SQL2 again for processing.

$result1 = mysql_query('show tables',$dbc);
   if ($myrow1 = mysql_fetch_array($result1))
    {
      // display list if there are records to display
      $tmptablename = sprintf("describe {$myrow1[0]}");
 do {
      $result2 = mysql_query($tmptablename,$dbc);
      echo "Table: {$myrow1[0]}";
[/snip]

You are not looping through $result1, so you will only get the first
return. Try this for your queries....(using error checking)

if(!($result1 = mysql_query("SHOW TABLES", $dbc))){
        echo mysql_error() . "\n";
        exit();
}

while($myrow = mysql_fetch_array($result1)){
        if(isset($myrow)){ //checks that the row is not empty
                $tmptablename = sprintf("describe $myrow[0]\n");
                echo "Table: " . $myrow[0] . "\n";
                $result2 = mysql_query($tmptablename, $dbc); //bad, no
error checking
                while($mycolumnarray = mysql_fetch_array($result2)){
                        echo "\t" . $mycolumnarray[0] . "\n";
                }
        }
}
This returns the following from a test database--

Table: maxTest
        id
        theData
Table: maxTest1
        id
        theData
Table: table1
        ID
        condition
Table: table2
        ID
        ID_table1
        value
Table: tblSOALocalMockup
        aid
        orderID
        orderDate
        dueDate
        custName
        custType
        orderStatus
        curOwner
        comments
        checkedOut



    

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to