Jump to content

elwoody

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

elwoody's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks - you got me over the hump!  The following code takes a query and outputs the column names and row data, in a table, without explicitly identifying the column names.  Handy thing for me. [code]<?php $query  = "DESCRIBE mastercities"; $columnNames = mysql_query($query) or Die("query failed"); echo "<table border='1' cellspacing='1' cellpadding='1'><tr>"; while ($row = mysql_fetch_array($columnNames)) { echo "<td>".$row['Field']."</td>"; } echo "</tr><tr>";   $query1  = "SELECT * FROM mastercities";   $result1 = mysql_query($query1) or Die("query 1 failed");   while ($row = mysql_fetch_assoc($result1))   { echo "<tr>";     foreach ($row AS $val)     { echo "<td>"."$val"."&nbsp;</td>";     }     echo '</tr>';   }   echo "</table>"; ?>[/code]
  2. I'm trying to use mySQL directive DECRIBE to lsit the column names in a query result, then use that data to output the results to a page, without explicitly specifying the column names.  I've gotten this far, without success: <?php    //... get initial city data $city = "NYC"; $query1  = "SELECT * FROM mastercities WHERE CityCode ='" .$city ."'"; $result1 = mysql_query($query1) or Die("query 1 failed"); $query2  = "DESCRIBE mastercities"; $result2 = mysql_query($query2) or Die("query 2 failed"); while($row1 = mysql_fetch_array($result1)) { while ($row2 = mysql_fetch_array($result2)) { $currentRow = "'".$row2['Field']."'"; echo "<break>".$row1[$currentRow].",  "; } echo "<para>"; } ?> I know these queries work independently, but as a novice php person, I'm stuck - any guidance would be appreciated... Thanks, Elwoody
×
×
  • 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.