首页 \ 问答 \ SQL ERROR ='where子句'中的未知列'Backpack'...提示?(SQL ERROR = Unknown column 'Backpack' in 'where clause'…tips?)

SQL ERROR ='where子句'中的未知列'Backpack'...提示?(SQL ERROR = Unknown column 'Backpack' in 'where clause'…tips?)

我正在上PHP和mySQL的介绍类。 当我从同一数据库中使用较少信息的表单击链接时,正在编写的代码正在尝试从数据库返回更多信息。 出于某种原因,经过无数个小时的研究和测试后,我无法使代码工作。 我非常感谢任何帮助或提示。

SQL:

#stops table from being duplicated
 DROP TABLE IF EXISTS stuff;
 #create table for stuff
 CREATE TABLE IF NOT EXISTS stuff (
  id INT primary key auto_increment, 
  location_id INT not null,
  name TEXT not null,
  description TEXT not null,
  create_date DATETIME not null,
  update_date DATETIME not null,
  room TEXT,
  owner TEXT,
  finder TEXT,
  status SET('found','lost','claimed') not null
);

INSERT INTO stuff (location_id, name, description, create_date, update_date, room, owner, finder, status)
    VALUES(2, "Cell phone", "Black iPhone 5s, scratches on screen with a black otterbox", now(), now(), "", "Zach Tsouprakos", "", 'Lost'),
    (16, "Backpack", "Black and blue Under Armour backpack, with keychain hanging off the front zipper", now(), now(), "Room 2023", "", "Casimer DeCusatis", 'Found'),
    (32, "Sunglasses", "Tortoise print Ray Ban sunglasses", now(), now(), "", "", "Rachel Ulicni", 'Found');

PHP:

    #Creates individual table for each hotlink(row) 
        while ( $row = mysqli_fetch_array( $results , MYSQLI_ASSOC ) )
        {
            $alink = '<A HREF=linkystuff.php?name=' . $row['name']. '>' . $row['name'] . '</A>' ;
            echo '<TR>' ;            
            echo '<TD>' . $row['id'] . '</TD>' ;
            echo '<TD>' . $row['create_date'] . '</TD>' ;
            echo '<TD>' . $row['status'] . '</TD>' ;
            echo '<TD ALIGN=right>' . $alink . '</TD>' ;
            echo '</TR>' ;
        }

        #End the table
        echo '</TABLE>';

        #Free up the results in memory
        mysqli_free_result( $results ) ;
    }
}

#Shows the records in presidents
function show_record($dbc, $name) {
    #Create a query to get the name and price sorted by price
    $query = 'SELECT id, location_id, name, description, create_date, update_date, room, owner, finder, status FROM stuff WHERE name = ' . $name ;

I am taking an intro class to PHP and mySQL. This code am writing is trying to return more information from a database when I click on a link from a table with less information from the same database. For some reason I cannot get the code to work after endless hours of research and testing. I would greatly appreciate any help or tips.

SQL:

#stops table from being duplicated
 DROP TABLE IF EXISTS stuff;
 #create table for stuff
 CREATE TABLE IF NOT EXISTS stuff (
  id INT primary key auto_increment, 
  location_id INT not null,
  name TEXT not null,
  description TEXT not null,
  create_date DATETIME not null,
  update_date DATETIME not null,
  room TEXT,
  owner TEXT,
  finder TEXT,
  status SET('found','lost','claimed') not null
);

INSERT INTO stuff (location_id, name, description, create_date, update_date, room, owner, finder, status)
    VALUES(2, "Cell phone", "Black iPhone 5s, scratches on screen with a black otterbox", now(), now(), "", "Zach Tsouprakos", "", 'Lost'),
    (16, "Backpack", "Black and blue Under Armour backpack, with keychain hanging off the front zipper", now(), now(), "Room 2023", "", "Casimer DeCusatis", 'Found'),
    (32, "Sunglasses", "Tortoise print Ray Ban sunglasses", now(), now(), "", "", "Rachel Ulicni", 'Found');

PHP:

    #Creates individual table for each hotlink(row) 
        while ( $row = mysqli_fetch_array( $results , MYSQLI_ASSOC ) )
        {
            $alink = '<A HREF=linkystuff.php?name=' . $row['name']. '>' . $row['name'] . '</A>' ;
            echo '<TR>' ;            
            echo '<TD>' . $row['id'] . '</TD>' ;
            echo '<TD>' . $row['create_date'] . '</TD>' ;
            echo '<TD>' . $row['status'] . '</TD>' ;
            echo '<TD ALIGN=right>' . $alink . '</TD>' ;
            echo '</TR>' ;
        }

        #End the table
        echo '</TABLE>';

        #Free up the results in memory
        mysqli_free_result( $results ) ;
    }
}

#Shows the records in presidents
function show_record($dbc, $name) {
    #Create a query to get the name and price sorted by price
    $query = 'SELECT id, location_id, name, description, create_date, update_date, room, owner, finder, status FROM stuff WHERE name = ' . $name ;

原文:https://stackoverflow.com/questions/33848355
更新时间:2021-11-23 08:11

最满意答案

虽然存在解析解,但通常很难计算它(对于少量输入变量( n )可能是可行的)。 我将首先讨论这个解决方案,然后提出替代方案。

分析解决方案

给定输入数字(l1, phi1), (l2, phi2), ... (ln, phin) ,其中li是长度, phii是数字的角度,你想要找到:

arg max_phi Sum_i abs(li cos(phii + phi))

您只有一个自变量。 因此,我们首先推导出与phi的函数:

f'(phi) = Sum_i (-li cos(phii + phi) * abs'(l cos(phii + phi))

abs'(x)+1-1 。 由于它的不连续性,我们不会尝试每种组合。 所以你最终会得到2^nf'变体。 然后,最佳值是(通常是四个)参数之一,其中f'(phi)=0 。 这可以如下计算。 我用si表示第i个术语的符号,你需要修改它:

numerator = Sum_i si li cos(phii)
denominator = (Sum_i li^2) + (Sum_i Sum_{j>i} 2 * li * lj * si * sj 

cos(phii - phij))

然后,四个候选解决方案是:

phi*    = -arc cos( numerator / sqrt(denominator))
phi**   = -arc cos(-numerator / sqrt(denominator))
phi***  =  arc cos( numerator / sqrt(denominator))
phi**** =  arc cos(-numerator / sqrt(denominator))

查找每个变体的所有候选项,并获取最大f(phi)候选项。 但是,如上所述,这种方法不适合大n 。 您需要2^nf变化,每个变化需要O(n^2)时间来构建解。

数值解

另一种方法是数值优化方法。 挑战在于你的功能不凸。 因此,如果您找到局部最大值,则无法确定它是否为全局最大值。 大多数算法需要良好的初始 您可以通过对phi的域进行采样并选择最佳点来找到初始点。 然后,尝试一些标准方法(Newton,Levenberg-Marquardt,BFGS)。


Although there exists an analytic solution, it is usually too hard to calculate it (may be feasible for a small number of input variables (n)). I'll first go over this solution, then suggest alternatives.

Analytic solution

Given the input numbers (l1, phi1), (l2, phi2), ... (ln, phin), where li is the length and phii the angle of the number, you want to find:

arg max_phi Sum_i abs(li cos(phii + phi))

You only have one independent variable. So, we start by deriving the function with respect to phi:

f'(phi) = Sum_i (-li sin(phii + phi) * abs'(l cos(phii + phi))

abs'(x) is either +1 or -1. Due to its discontinuity, we won't get around trying every combination. So you end up with 2^n variants of f'. The optimum is then one of the (usually four) arguments where f'(phi)=0. This can be calculated as follows. I denote with si the sign of the i-th term, which you need to modify:

numerator = Sum_i si li sin(phii)
denominator = (Sum_i li^2) + (Sum_i Sum_{j>i} 2 * li * lj * si * sj 

cos(phii - phij))

Then, the four solution candidates are:

phi*    = -arc cos( numerator / sqrt(denominator))
phi**   = -arc cos(-numerator / sqrt(denominator))
phi***  =  arc cos( numerator / sqrt(denominator))
phi**** =  arc cos(-numerator / sqrt(denominator))

Find all candidates for every variation and take the one with maximum f(phi). However, as mentioned, this approach is not suitable for large n. You need 2^n variations of f and each variation requires O(n^2) time to construct the solution.

Numerical solution

An alternative is a numerical optimization approach. The challenge is that your function is not convex. Hence, if you find a local maximum, you cannot say if it is the global one. Most algorithms require good initialization. You could find the initial point by sampling the domain of phi and picking the best one. Then, try some of the standard approaches (Newton, Levenberg-Marquardt, BFGS).

相关问答

更多

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的