blacknight Posted October 12, 2006 Share Posted October 12, 2006 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? Quote Link to comment Share on other sites More sharing options...
blacknight Posted October 13, 2006 Author Share Posted October 13, 2006 ? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 13, 2006 Share Posted October 13, 2006 $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. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 13, 2006 Share Posted October 13, 2006 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]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.