开发者

Function to check to see if a field in a MySQL table equals 1

For the MySQL table below, what PHP function would simply test to see if 'subc开发者_JS百科heck' equals 1?

Thanks in advance,

John

`submission` (
  `submissionid` int(11) unsigned NOT NULL auto_increment,
  `loginid` int(11) NOT NULL,
  `title` varchar(1000) NOT NULL,
  `slug` varchar(1000) NOT NULL,
  `url` varchar(1000) NOT NULL,
  `displayurl` varchar(1000) NOT NULL,
  `datesubmitted` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `subcheck` tinyint(1) NOT NULL,
  PRIMARY KEY  (`submissionid`)
) 


You haven't provided much needed information such as the table name, your conditions for checking, so I'm just going to give you a simple query for you to work with...

$query = mysql_query('SELECT subcheck FROM your_table WHERE subcheck = "1"');

if ($query)
{
//your subcheck is 1
}
else
{
//your subcheck is not 1 / nothing was found
}

If you need to select only ones with a certain submissionid it would be best to change it to the following:

$submissionid = 809;
$query = mysql_query('SELECT subcheck
                      FROM your_table
                      WHERE submissionid = "' . $submissionid . '"');

if ($row = mysql_fetch_row($query))
{
    if ($row[0] == 1) { } //your subcheck is one
    else { } //your subcheck is not one
}
else { } //no matching records found

Remember to escape $submissionid if it's going to be based from an unsafe source such as user input!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜