我有一个名为'catalog'的数据库和一个名为'categories'的表.该表按此顺序有3列:categoryId,categoryName,parentCategory.我正在尝试为具有parentCategory ='root'的每一行抓取categoryId和categoryName.我认为这是一个简单的查询,但我显然做错了,因为我一直收到消息 - 无法执行查询 - 但没有显示mysql错误.我在下面发布了我的代码.任何人都能直接指出我吗?
PS我的值已分配给$ db变量; 我只是没有把这些包括在内.
<?php
$connect = mysqli_connect($db_host,$db_user,$db_password,$db_database)
or die ("Couldn't connect to server: ".mysqli_error());
function display_children($parent) {
$query = "SELECT categoryId, categoryName FROM `categories` WHERE parentCategory=".$parent;
$result = mysqli_query($connect,$query)
or die ("Couldn't execute query: ".mysqli_error());
echo "<ul>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<li>".$row['categoryName']."</li>";
display_children($row['categoryId']);
}
echo "</ul>";
mysqli_close($connect);
}
?>
<div class="menu">
<?php
/* Menu Write */
display_children("root");
?>
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个窗口的 CGWindowID 和我的 Mac 的所有 CGDirectDisplayID。然后我想知道哪个显示窗口。我尝试获取窗口的 CGWindowInfo?但找不到有用的信息。
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, windowID);
CFArrayApplyFunction(windowList, CFRangeMake(0, CFArrayGetCount(windowList)), &WindowListApplierFunction, this);
CFRelease(windowList);
Run Code Online (Sandbox Code Playgroud) 正如我的老师告诉我的那样,数组声明不能接受地址作为赋值.
int a[]={1,2};
int b[2]=a;
Run Code Online (Sandbox Code Playgroud)
这显示错误为初始化程序无效.但我正在玩这样的东西,并发现了如下的奇怪的例子.
int a[][3] = {1, 2, 3, 4, 5, 6};
int (*ptr)[3] = a;
Run Code Online (Sandbox Code Playgroud)
这也是一个数组的声明,其地址与ptr指针一起保存,并且接受2维数组a的地址,但这显示没有错误.为什么,有人可以用简单的语言解释我吗?提前致谢.
我正在尝试创建我的第一个组件,但我一直在收到错误.这导致网站上根本没有显示按钮元素.这是我的文件:
ERROR in ./src/js/components/presentational/Button1.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (3:13)
1 | import React, { Component } from "react";
2 | class Button1 extends React.Component {
> 3 | handleClick = () => {
| ^
4 | console.log("dupa");
5 | };
6 | render() {
Run Code Online (Sandbox Code Playgroud)
./src/js/components/presentational/Button1.js
import React, { Component } from "react";
class Button1 extends React.Component {
handleClick = () => {
console.log("dupa");
};
render() {
return (
<button onclick={this.props.handleClick}>
Button
</button>
);
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个带有构造函数的类,该构造函数带有两个参数并将字段设置为这些值。我还希望通过在传递给构造函数的块内显式设置字段来初始化此类的对象。
构造函数:
class Grammar
attr_reader :rules, :start, ...
def initialize(rules, start)
@rules = rules
@start = start
...
end
end
Run Code Online (Sandbox Code Playgroud)
传递给构造函数的参数涉及创建几个对象,这些对象仅用作参数的中间构建块rules,start并且将这些对象的存在限制为传递给构造函数的块是有意义的。在此块中,我希望首先构建中间对象,然后直接设置新对象的字段。
我希望能够Grammar像这样实例化:
grammar = Grammar.new { |g|
...
# build rules and start
...
g.start = start
g.rules = rules
}
Run Code Online (Sandbox Code Playgroud)
我应该如何修改构造函数以允许两种初始化方法?
#include <iostream>
struct X
{
bool isNull() { return this == nullptr; }
bool isNullConst() const { return this == nullptr; }
};
bool isNull(X& x) { return &x == nullptr; }
bool isNullConst(const X& x) { return &x == nullptr; }
// always false or exception.
bool isNullCopy(X x) { return &x == nullptr; }
int main()
{
X* x = nullptr;
std::cout << x->isNull() << '\n';
std::cout << (*x).isNull() << '\n';
std::cout << isNull(*x) << '\n';
// std::cout …Run Code Online (Sandbox Code Playgroud) 我正在尝试用 C++ 编写一个缩小的 FizzBuzz 程序,因为我现在正在学习它。我想知道是否有一种速记方式可以说“如果此字符串存在,则返回此字符串,否则,返回下一部分”
在 JavaScript 中,使用||运算符的工作方式与我想的一样:
function fizzbuzz() {
const maxNum = 20; // Simplified down to 20 just for example
for (let i = 1; i <= maxNum; i++) {
let output = "";
if (i % 3 == 0) output += "Fizz";
if (i % 5 == 0) output += "Buzz";
console.log(output || i); // If the output has something, print it, otherwise print the number
}
}
fizzbuzz();Run Code Online (Sandbox Code Playgroud)
当我在 C++ 中尝试这个时,
#include <iostream> …Run Code Online (Sandbox Code Playgroud) 我以为我在运行此代码之前了解内存的工作原理,内存是否倒退?或者我错过了什么?
代码:
#include <stdio.h>
int main()
{
int a = 0x12345678;
char *c = (char *)&a;
for (int i = 0; i < 4; i++)
{
printf("c[%d]=%x \n", i, *(c + i));
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
c[0]=78
c[1]=56
c[2]=34
c[3]=12
Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要将指针传递给我的函数并使用“write”将其显示在我的函数中。
#include <unistd.h>
#include <stdio.h>
void ft_ft(int *nbr){
//printf("%d\n", *nbr);
char c = *nbr;
write(1, &c, 1);
}
int main(){
int nbr = 42;
ft_ft(&nbr);
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我试图将 int 值转换为 char ,因为从参数中获取指针是行不通的。另一方面,这也不是,所以你能帮助我吗?
错误消息:
[正在运行] (((所在文件夹))) && gcc (((文件名)))... 输出:* [完成] 在 0.046 秒内退出,代码=0
所以它实际上运行了代码,但它不是我想要的输出,我错过了什么?
printf() 工作正常,但我无法让“write”工作。
提前致谢