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
最满意答案
虽然存在解析解,但通常很难计算它(对于少量输入变量(
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^n
个f'
变体。 然后,最佳值是(通常是四个)参数之一,其中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^n
个f
变化,每个变化需要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)
, whereli
is the length andphii
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 with2^n
variants off'
. The optimum is then one of the (usually four) arguments wheref'(phi)=0
. This can be calculated as follows. I denote withsi
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 largen
. You need2^n
variations off
and each variation requiresO(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).
相关问答
更多-
在C ++中获取指向复杂向量的实部和虚部的指针(Getting pointers to the real and imaginary parts of a complex vector in C++)[2022-09-25]
(C ++ 03)标准没有定义std::complex的内部结构,但通常它由2个双精度组成,实部在虚部之前。 因此,给定std::complex 的数组(或std::vector ),你不能获得指向所有实部的数组的指针,以及指向所有虚部的数组的另一个指针:实部和虚部是交错。 如果你真的需要拆分它们,你就不能在不复制所有元素的情况下完成它(就像你已经做的那样)。 但是你为什么要把它们分开呢? 将它们传递给某些库的某些例程? 也许该库也支持交错格式? 在这种情况下,您可以执行rei ... -
这段代码可以帮助你,这是很自明的: #include
/* Standard Library of Input and Output */ #include /* Standard Library of Complex Numbers */ int main() { double complex z1 = 1.0 + 3.0 * I; double complex z2 = 1.0 - 4.0 * I; printf( ... -
这样做: >>> factarr*cplxarr.real + (1j)*cplxarr.imag array([ 0.5+2.j, 1.8+1.j, 1.4-2.j]) 不知道这是不是最好的方式。 事实证明,对我来说至少(OS-X 10.5.8,python 2.7.3,numpy 1.6.2)这个版本大约是使用np.vectorize的其他版本的np.vectorize : >>> from timeit import timeit >>> timeit('factarr*cplxarr.real ...
-
不。 你可以从std::complex<>派生,并继承构造函数并添加一个重载的operator[] ,但我会建议不要这样做。 Nope. You could derive from std::complex<> and inherit constructors and add an overridden operator[], but I would advise against it.
-
将复数NumPy数组转换为(n,2) - 实部和虚部阵列(Convert complex NumPy array into (n, 2)-array of real and imaginary parts)[2022-08-27]
没有任何替代方案是native或保存在重塑,转置等。 例如,内部column_stack将其输入转换为2d'列'数组。 它实际上是在做 In [1171]: np.concatenate((np.array(u.real,ndmin=2).T,np.array(u.imag,ndmin=2).T),axis=1) Out[1171]: array([[ 1., 2.], [ 2., 4.], [ 3., 6.], [ 4., 8.]]) vstack通过 ... -
函数complex只能处理标量。 您可以将第二列转换为虚数乘以1j ,然后求和: df['wspd'] + df['wdir'] * 1j 样品 : df = pd.DataFrame({'wspd':[10.23,2.4,30.6], 'wdir':[2.3,7.8,4]}) df['com'] = df['wspd'] + df['wdir'] * 1j print (df) wspd wdir com 0 10.23 2.3 (10.23+2.3j) 1 2 ...
-
目前, Numeric不是@specialized 。 所以使用它的通用版本将受到装箱和拆箱的影响,性能将大大降低。 这是一篇很好的博客文章,其中包含性能测量: http://www.azavea.com/blogs/labs/2011/06/scalas-numeric-type-class-pt-2/ 但是,您可以直接编写复杂数字类的@specialized版本,而无需使用Numeric并获得所有好处。 从严格务实的角度来看,我不确定用整数部分来理解复数的用法是什么...... For the mome ...
-
虽然存在解析解,但通常很难计算它(对于少量输入变量( 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 ...
-
直到舍入误差,这些结果是相等的。 由于诸如不同的求和顺序或用于表示中间结果的不同精度水平之类的因素,结果具有略微不同的舍入误差。 Up to rounding error, these results are equal. The results have slightly different rounding error due to factors such as different summation order or different levels of precision used to rep ...
-
Cython中complex.real和creal(复杂)之间的区别(Difference between complex.real and creal(complex) in Cython)[2023-11-17]
当然默认的C库( complex.h )对你有用 。 但是,与c.real c.imag方法相比,似乎这个库不会给你任何显着的改进。 通过将代码放在with nogil: block的代码中,您可以检查您的代码是否已经不调用Python API: cdef double complex c1, c2, c3 with nogil: c1 = 1.0 + 1.2j c2 = 2.2 + 13.4j c3 = c2.real + c1*c2.imag 我使用的是Windows 7和Py ...