Jump to content

sql query question


blacknight

Recommended Posts

im tryingt to make an upgrade script for a database and need to see if spacific colums are present in the table i have tryed

[code]$sql_str = "SHOW COLUMNS FROM table_name LIKE 'approved'";
$this->setSqlDebug("checkcolumDb: $sql_str");
      $result = $wowdb->query($sql_str);
      if ($wowdb->num_rows($result) == 0){
      echo "no colum";
      $t++;
     
      }[/code]
but no column is allways echoed if it exists or not i need tit to not return if it does any one have any help?
Link to comment
https://forums.phpfreaks.com/topic/23806-sql-query-question/
Share on other sites

Here, this should work...

[code]<?php
$MyTableName = "username"; //Your table name goes here
$sql = "SHOW COLUMNS FROM table_name WHERE Field = '$MyTableName'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);

if ($count > 0){
  echo "The column name already exists";
}
else {
  echo "There is no column with that name";
}
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/23806-sql-query-question/#findComment-108368
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.