Jump to content

show fields from table and php


russthebarber

Recommended Posts

I don't know what you mean by that. A more in depth answer would be helpful

 

while ($row = mysql_fetch_array($result)) {
$product_name = $row['product_name']; 
}

 

They are not rows so what goes in place of $row and in place of $row['product_name'] for example ???

Here is the last thing I tried. i'm getting closer but need to know what to put in place of xxxx in the while loop to get the field name.

 

$sql  = "SHOW FIELDS FROM apartmentoUsers";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
echo xxxxx;//what goes here?
}

Have you executed this query from within MySql to see what it might look like? Your query will return something like:

 

[pre]

+------------------+---------------------+------+-----+---------------------+----------------+

| Field            | Type                | Null | Key | Default            | Extra          |

+------------------+---------------------+------+-----+---------------------+----------------+

| id          | bigint(20) unsigned | NO  | PRI | NULL                | auto_increment |

| somefield        | varchar(255)        | NO  |    |                    |                |

+------------------+---------------------+------+-----+---------------------+----------------+

[/pre]

 

Armed with this information you can see to use:

 

$sql  = "SHOW FIELDS FROM apartmentoUsers";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      echo $row['Filed'] . '<br />';
      echo $row['Type'] . '<br />';
      echo $row['Null'] . '<br />';
      echo $row['Key'] . '<br />';
      echo $row['Default'] . '<br />';
      echo $row['Extra'] . '<br />';
    }
  }
}

 

Of course, $row is just an array, so you could also have looped through it also.

 

$sql  = "SHOW FIELDS FROM apartmentoUsers";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      foreach ($row as $val) {
        echo $val . '<br />';
      }
    }
  }
}

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.