Jump to content

Archived

This topic is now archived and is closed to further replies.

blacknight

sql query question

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?

Share this post


Link to post
Share on other sites
$id = 3;
$select = "SELECT * FROM userinfo WHERE id = '$id';";
$query = mysql_query($select);
if ($row = mysql_fetch_array($query)) {
echo "I apologize but that record already exists";
}else {
// insert, or update here
}

Is this what you mean.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.