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? Link to comment https://forums.phpfreaks.com/topic/23806-sql-query-question/ Share on other sites More sharing options...
blacknight Posted October 13, 2006 Author Share Posted October 13, 2006 ? Link to comment https://forums.phpfreaks.com/topic/23806-sql-query-question/#findComment-108343 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. Link to comment https://forums.phpfreaks.com/topic/23806-sql-query-question/#findComment-108345 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 Link to comment https://forums.phpfreaks.com/topic/23806-sql-query-question/#findComment-108368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.