水溶

文章 评论 浏览 30

水溶 2025-02-20 22:51:50

您需要从表单中发送持久记录的ID字段,以便告诉Rails该对象已经在DB中。

def post_params
  params.permit(:title, :content, tags_attributes: [:id, :name])
end 

另外,如果您希望用户具有删除标签的能力,则可以像这样修改代码。

class Post < ApplicationRecord
  belongs_to :user
  has_many :post_tags, dependent: :destroy
  has_many :tags, through: :post_tags

  accepts_nested_attributes_for :tags, allow_destroy: true
end

在您的控制器中:

def post_params
  params.permit(:title, :content, tags_attributes: [:id, :name, :_destroy])
end

当用户想从帖子中删除任何标签时

You need to send the id field of persisted record from the form in order to tell rails that this object already in the db.

def post_params
  params.permit(:title, :content, tags_attributes: [:id, :name])
end 

Also if you want user to have ability to remove tags you can modify your code like this.

class Post < ApplicationRecord
  belongs_to :user
  has_many :post_tags, dependent: :destroy
  has_many :tags, through: :post_tags

  accepts_nested_attributes_for :tags, allow_destroy: true
end

and in your controller:

def post_params
  params.permit(:title, :content, tags_attributes: [:id, :name, :_destroy])
end

when the user want to delete any tag from post add _destroy parameter as '1' along with the id in the fields of that tag

关于帖子和标签之间许多关系的问题(post_tag作为加入表)

水溶 2025-02-20 19:42:34

这条线解决了我的问题,

return send_from_directory('directory-path', file.filename)

完整代码

这是从烧瓶导入send_from_directory的
class uploadfileform(flaskform):
file = filefiel('file',validators = [inputRequired()))
submit = sumbtfield('download file')

@app.route('/',methods = ['get','post'])
def home_api():

form = UploadFileForm()
if form.validate_on_submit():

    file = form.file.data
    file.save(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))
    process_xl(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))
    download_file(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))

    return send_from_directory('directory-path', file.filename)
return render_template('index.html', form=form)

This line solved my problem

return send_from_directory('directory-path', file.filename)

This is the full code here

from flask import send_from_directory
class UploadFileForm(FlaskForm):
file = FileField('File', validators=[InputRequired()])
submit = SubmitField('Download File')

@app.route('/', methods=['GET', 'POST'])
def home_api():

form = UploadFileForm()
if form.validate_on_submit():

    file = form.file.data
    file.save(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))
    process_xl(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))
    download_file(os.path.join(os.path.abspath(os.path.dirname(_file_)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))

    return send_from_directory('directory-path', file.filename)
return render_template('index.html', form=form)

如何允许用户使用Python/Flask下载Excel文件?

水溶 2025-02-20 13:12:15

如果线通过两个点P1 =(x1,y1)和p2 =(x2,y2),则(x0,y0)与线的距离为:

“在此处输入图像说明”


因此您可以轻松地将此公式更改为DART

import 'dart:math';

main(){
  double x0 = -2;
  double x1 = 0;
  double x2 = 5/3;

  double y0 = 5;
  double y1 = 5/4;
  double y2 = 0;

  double numerator = (((x2 - x1)*(y1-y0)) - ((x1-x0)*(y2-y1))).abs();
  double denominator = sqrt(pow((x2-x1), 2) + pow((y2-y1), 2));

  double result = numerator / denominator;

  print(result);  /// 1.7999999999999998

}

的数学来源: https://en.wikipedia.org/wiki/distance_from_a_point_to_a_a_line

If the line passes through two points P1 = (x1, y1) and P2 = (x2, y2) then the distance of (x0, y0) from the line is:

enter image description here


so you can easily change this formula to dart

import 'dart:math';

main(){
  double x0 = -2;
  double x1 = 0;
  double x2 = 5/3;

  double y0 = 5;
  double y1 = 5/4;
  double y2 = 0;

  double numerator = (((x2 - x1)*(y1-y0)) - ((x1-x0)*(y2-y1))).abs();
  double denominator = sqrt(pow((x2-x1), 2) + pow((y2-y1), 2));

  double result = numerator / denominator;

  print(result);  /// 1.7999999999999998

}

source of Math:https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

如何找到偏移与线之间的距离?

水溶 2025-02-20 03:54:51

递归调用sumpower3(num,power+1)可以任意增加指数的值,从而导致堆栈溢出错误。要解决问题,请为此参数设置最大值 - log(num,3) - 并在其值超过该限制时终止递归。

public class Maim {
    public static void main(String[] args) {
        System.out.println(sumPower3(2296)); // true: 3^0 + 3^3 + 3^4 + 3^7 == 2296
        System.out.println(sumPower3(2297)); // false
        System.out.println(sumPower3(2298)); // true: 3^1 + 3^3 + 3^4 + 3^7 == 2298
    }

    private static boolean sumPower3(int num) {
        return sumPower3(num, 0, Math.log(num)/Math.log(3.0)); // set limit for power
    }

    private static boolean sumPower3(int num, int power, double limit) {
        if(num==0) {
            return true;
        }
        if(num<0 || power > limit) {        // check limit for power
            return false;
        }
        return sumPower3((int)(num-Math.pow(3, power)), power+1, limit) || sumPower3(num, power+1, limit);
    }
}

The recursive call sumPower3(num, power+1) may arbitrarily increase the value of the exponent, causing stack overflow error. To solve the problem, set a maximum value for this parameter - log(num,3) - and terminate the recursion when its value exceeds that limit.

public class Maim {
    public static void main(String[] args) {
        System.out.println(sumPower3(2296)); // true: 3^0 + 3^3 + 3^4 + 3^7 == 2296
        System.out.println(sumPower3(2297)); // false
        System.out.println(sumPower3(2298)); // true: 3^1 + 3^3 + 3^4 + 3^7 == 2298
    }

    private static boolean sumPower3(int num) {
        return sumPower3(num, 0, Math.log(num)/Math.log(3.0)); // set limit for power
    }

    private static boolean sumPower3(int num, int power, double limit) {
        if(num==0) {
            return true;
        }
        if(num<0 || power > limit) {        // check limit for power
            return false;
        }
        return sumPower3((int)(num-Math.pow(3, power)), power+1, limit) || sumPower3(num, power+1, limit);
    }
}

为什么递归不起作用?

水溶 2025-02-19 10:50:49

问题对我解决了。实际上是我的码头图像。我应该使用jetty:9-jre8-openjdk 的而不是使用,然后仅使用类和Servlet Jars可用对于我的申请。

在这里,它是完整的dockerfile

FROM maven as build

COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package


FROM jetty:9-jre8-openjdk
COPY --from=build /home/app/target/root.war /var/lib/jetty/webapps
EXPOSE 8080
CMD java -jar "$JETTY_HOME/start.jar"

Problem got resolved for me. Actually problem was with my jetty image. Instead of using FROM jetty:latest, I should be using FROM jetty:9-jre8-openjdk then only classes and servlet jars would be available for my application.

Here it the complete Dockerfile

FROM maven as build

COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package


FROM jetty:9-jre8-openjdk
COPY --from=build /home/app/target/root.war /var/lib/jetty/webapps
EXPOSE 8080
CMD java -jar "$JETTY_HOME/start.jar"

使用Jetty Docker Image运行Java Maven项目

水溶 2025-02-19 03:47:13

改变您的想法是正确的方法是将该组件添加到app.js。

然后,使用redux,设置消息的值和布尔值等...以显示或隐藏组件。

现在,您可以使用Redux上的任何页面上更改消息的价值和iSshow的价值。

change your mind The correct way is to add that component to app.js.

Then, using redux, set the value of message and boolean etc... to show or hide the component .

Now you can change the value of message and isShow on any page you want using redux.

如何通过JavaScript将React JSX组件附加到HTML

水溶 2025-02-18 16:36:28

最佳答案很棒。这是我在常规 mysql setup:

// Storage
// Debian. Apparently already UTF-8

// Retrieval
// The MySQL database was stored in UTF-8,
// but apparently PHP was requesting ISO 8859-1. This worked:
// ***notice "utf8", without dash, this is a MySQL encoding***
mysql_set_charset('utf8');

// Delivery
// File *php.ini* did not have a default charset,
// (it was commented out, shared host) and
// no HTTP encoding was specified in the Apache headers.
// This made Apache send out a UTF-8 header
// (and perhaps made PHP actually send out UTF-8)
// ***notice "utf-8", with dash, this is a php encoding***
ini_set('default_charset','utf-8');

// Submission
// This worked in all major browsers once Apache
// was sending out the UTF-8 header. I didn’t add
// the accept-charset attribute.

// Processing
// Changed a few commands in PHP, like substr(),
// to mb_substr()

这就是!

The top answer is excellent. Here is what I had to on a regular Debian, PHP, and MySQL setup:

// Storage
// Debian. Apparently already UTF-8

// Retrieval
// The MySQL database was stored in UTF-8,
// but apparently PHP was requesting ISO 8859-1. This worked:
// ***notice "utf8", without dash, this is a MySQL encoding***
mysql_set_charset('utf8');

// Delivery
// File *php.ini* did not have a default charset,
// (it was commented out, shared host) and
// no HTTP encoding was specified in the Apache headers.
// This made Apache send out a UTF-8 header
// (and perhaps made PHP actually send out UTF-8)
// ***notice "utf-8", with dash, this is a php encoding***
ini_set('default_charset','utf-8');

// Submission
// This worked in all major browsers once Apache
// was sending out the UTF-8 header. I didn’t add
// the accept-charset attribute.

// Processing
// Changed a few commands in PHP, like substr(),
// to mb_substr()

That was all!

UTF-8一直通过

水溶 2025-02-18 14:19:13

您可以在自动缩放组上启用额外的指标,这将使您可以在Elastic Beanstalk监视页面上显示您正在寻找的计数指标。

从EC2控制台中,单击左侧导航中的自动缩放组,然后单击与您的Elastic Beanstalk应用程序关联的自动化组。 (如果您不知道自动缩放组,则可以通过单击一个EC2实例,选择标签选项卡并找到aws:autoscaling:groupName值来找到它。)已经选择了正确的自动缩放组,请单击“监视”选项卡,然后选中“自动缩放组指标集合:启用”复选框。

启用后,请返回弹性豆键控制台,选择环境,然后单击左侧导航中的监视链接。在“监视”部分中,单击“编辑”,然后在“添加图”部分中为资源选择“ AwseBautoscalingGroup”。在“ CloudWatch Metric”选项下,您现在应该看到一些具有“组”前缀的新指标(请注意,出现新指标可能需要长达5分钟):

您可以创建一个具有“ GroupMaxSize”的度量,选择“最大值”为统计量,请参见Autoscaler随时间推移启动的实例计数。

You can enable extra metrics on the Auto Scaling Group, which will allow you to display the count metrics you are looking for on the Elastic Beanstalk monitoring page.

From the EC2 console, click Auto Scaling Groups in the left-hand navigation and click on the autoscaling group associated with your Elastic Beanstalk application. (If you don't know the auto scaling group, you can find it by clicking on one of the EC2 instances, selecting the Tags tab, and finding the aws:autoscaling:groupName value.) After you have selected the correct auto scaling group, click the Monitoring tab, and check the "Auto Scaling group metrics collection: Enable" checkbox.

autoscaling group monitoring tab

Once that is enabled, go back to the Elastic Beanstalk console, select the environment, and click the Monitoring link in the left-side navigation. In the Monitoring section, click Edit, and in the Add Graph section, select "AWSEBAutoScalingGroup" for the resource. Under the "CloudWatch metric" options, you should now see some new metrics with the "Group" prefix (note that it may take up to 5 minutes for the new metrics to appear):

Elastic Beanstalk monitoring edit page

You can create a metric with "GroupMaxSize", selecting "Maximum" as the Statistic in order see the instance counts launched by the autoscaler over time.

如何找到历史上的弹性豆stalk旋转了多少个EC2实例?

水溶 2025-02-17 18:32:42

使用 Muenchian分组仅获得独特的债权人:

xslt 1.0 <> xslt 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="creditor" match="Creditor" use="Contact/AddressBookUID" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="PolicyContactRoles">
    <xsl:copy>
        <xsl:for-each select="//Creditor[count(. | key('creditor', Contact/AddressBookUID)[1]) = 1]">
            <Entry>
                <AccountContactRole>
                    <Subtype>Creditor_De</Subtype>
                    <AccountContact>
                        <Contact>
                            <xsl:copy-of select="Contact/AddressBookUID"/>
                        </Contact>
                    </AccountContact>
                </AccountContactRole>
                <Subtype>PolicyCreditor_De</Subtype>
            </Entry>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Use Muenchian grouping to get only distinct creditors:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="creditor" match="Creditor" use="Contact/AddressBookUID" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="PolicyContactRoles">
    <xsl:copy>
        <xsl:for-each select="//Creditor[count(. | key('creditor', Contact/AddressBookUID)[1]) = 1]">
            <Entry>
                <AccountContactRole>
                    <Subtype>Creditor_De</Subtype>
                    <AccountContact>
                        <Contact>
                            <xsl:copy-of select="Contact/AddressBookUID"/>
                        </Contact>
                    </AccountContact>
                </AccountContactRole>
                <Subtype>PolicyCreditor_De</Subtype>
            </Entry>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

动态添加XML标签,不应允许使用XSLT基于XML中特定标签的重复项

水溶 2025-02-16 19:56:38

在您的Docker-compose.yml文件中,将链接属性添加到您的WebServer服务:
https://docs.docker.com/compose/compose/networking/networking/#links

然后在您的查询字符串中,主机参数的值是您的数据库服务名称:

$mysqli = new mysqli("database", "mattia", "prova", "prova");

In your docker-compose.yml file add a link property to your webserver service:
https://docs.docker.com/compose/networking/#links

Then in your query string, the host parameter's value is your database service name:

$mysqli = new mysqli("database", "mattia", "prova", "prova");

从其他容器访问MySQL容器

水溶 2025-02-16 14:33:52

这是我最终使用的...

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.fu.bar/groupId>
    <artifactId>server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>server</name>
    <description>server</description>
    <packaging>war</packaging>

    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>

        <jetty.version>11.0.9</jetty.version>
        <jersey.version>3.0.5</jersey.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-cdi</artifactId>
            <version>${jetty.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.ext.cdi</groupId>
            <artifactId>jersey-cdi1x</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-core</artifactId>
            <version>5.0.1.Final</version>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Here's what I eventually used...

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.fu.bar/groupId>
    <artifactId>server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>server</name>
    <description>server</description>
    <packaging>war</packaging>

    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>

        <jetty.version>11.0.9</jetty.version>
        <jersey.version>3.0.5</jersey.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-cdi</artifactId>
            <version>${jetty.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.ext.cdi</groupId>
            <artifactId>jersey-cdi1x</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-core</artifactId>
            <version>5.0.1.Final</version>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

码头休息&#x2B; cdi与小牛肉

水溶 2025-02-16 14:00:54

某些东西使您的组件渲染不止一次,重复API获取。使用Effects的第二个参数可以使代码仅在更新某些变量时执行,请尝试使用它。

Something is making your component render more than once, repeating the API fetch. UseEffects' second argument can make the code only execute when certain variables are updated, try using it.

Reactjs。调用API时多个数据加载

水溶 2025-02-16 03:44:27

如果在执行此脚本的执行中,数据库操作仅执行一次,则无需实例化函数。只需获取要插入的名称的数量,然后使用php 准备的语句当然,以防止提交不适当的价值。

<?php

include "connection.php"; // needs to provide $mysqli
$number = ""; // default empty string for form value

// perform database operations first
if (!empty($_POST["number"]) && 0 < $_POST["number"]) { // qualify input

    $number = $_POST["number"];

    // Select random data
    $get_names_stmt = $mysqli->prepare("SELECT data_firstname, data_lastname FROM data ORDER BY RAND() LIMIT ?");
    $get_names_stmt->bind_param("i", $number); // integer, value
    $get_names_stmt->execute();
    $get_names_stmt->store_result(); // allows simultaneous insert
    $get_names_stmt->bind_result($firstname, $lastname); // bind results to variables $firstname and $lastname

    // Prepare to insert random data
    $insert_names_stmt = $mysqli->prepare("INSERT INTO students (student_firstname, student_lastname) VALUES (?, ?)");

    // bind to string variables $firstname and $lastname
    $insert_names_stmt->bind_param("ss", $firstname, $lastname); 

    // loop random data selection, which provides variables $firstname and $lastname
    while ($get_names_stmt->fetch()) {
        // insert variables $firstname and $lastname
        $insert_names_stmt->execute();
    }

    // wrap it all up
    $get_names_stmt->close();
    $insert_names_stmt->close();
    $mysqli->close();

    echo "You generated " . htmlspecialchars($number) . " new students !";  
}

// if there is a $_POST["number"] variable, but it is not greater than 0
} else if (!empty($_POST["number"])) {   
    echo "Psss, try with a number greater than " . htmlspecialchars($_POST["number"] . ".");
}

?>

<form action="index.php" method="post">
    <input type="number" name="number" min="0" value="<?=$number?>"></input>
    <button type="submit" name="submit">Send</button>
</form>

顺便说一句,form ===客户端,php ===服务器端:

数据库注入从未在客户端上确保 - 永远不会发送到服务器的信任数据。曾经。

If the database operations are performed only once in the execution of this script then there is no need to instantiate functions. Simply get the number of names to insert, then insert them, using PHP prepared statements, of course, to prevent submission of inappropriate values.

<?php

include "connection.php"; // needs to provide $mysqli
$number = ""; // default empty string for form value

// perform database operations first
if (!empty($_POST["number"]) && 0 < $_POST["number"]) { // qualify input

    $number = $_POST["number"];

    // Select random data
    $get_names_stmt = $mysqli->prepare("SELECT data_firstname, data_lastname FROM data ORDER BY RAND() LIMIT ?");
    $get_names_stmt->bind_param("i", $number); // integer, value
    $get_names_stmt->execute();
    $get_names_stmt->store_result(); // allows simultaneous insert
    $get_names_stmt->bind_result($firstname, $lastname); // bind results to variables $firstname and $lastname

    // Prepare to insert random data
    $insert_names_stmt = $mysqli->prepare("INSERT INTO students (student_firstname, student_lastname) VALUES (?, ?)");

    // bind to string variables $firstname and $lastname
    $insert_names_stmt->bind_param("ss", $firstname, $lastname); 

    // loop random data selection, which provides variables $firstname and $lastname
    while ($get_names_stmt->fetch()) {
        // insert variables $firstname and $lastname
        $insert_names_stmt->execute();
    }

    // wrap it all up
    $get_names_stmt->close();
    $insert_names_stmt->close();
    $mysqli->close();

    echo "You generated " . htmlspecialchars($number) . " new students !";  
}

// if there is a $_POST["number"] variable, but it is not greater than 0
} else if (!empty($_POST["number"])) {   
    echo "Psss, try with a number greater than " . htmlspecialchars($_POST["number"] . ".");
}

?>

<form action="index.php" method="post">
    <input type="number" name="number" min="0" value="<?=$number?>"></input>
    <button type="submit" name="submit">Send</button>
</form>

By the way, FORM === client-side, PHP === server-side:

Database injections are NEVER secured on the client—NEVER trust data sent to the server. Ever.

将随机数据从HTML输入中插入数据库

水溶 2025-02-15 23:51:34

将CircleAvatar小时候到容器上显示图像。

  • 带边框和填充的容器
    • 循环
      • RADIUS的背景图像URL

Use CircleAvatar as a child to the container to display the image.

  • Container with border and padding
    • CircleAvatar
      • background image url with radius

圆形容器中的拉伸图像颤动

水溶 2025-02-15 18:32:12

对于组合谓词,您已使用了位运算符expression.and and expression.or bitwise and shift operators

在C#生成的结果中看起来像是

e => (e.Some > 1) & (e.Some < 10) | (e.Some == -1)

这样,EF也试图将位操作转换为SQL 。

而不是他们使用expression.andalsoexpression.orelse 布尔逻辑运算符

e => (e.Some > 1) && (e.Some < 10) || (e.Some == -1)

用于分析生成的表达式,我建议使用 Realable expressions.visualizers.visualizers ,您可能会自己发现错误。

For combining predicates you have used bitwise operators Expression.And and Expression.Or Bitwise and shift operators

In C# generated result looks like

e => (e.Some > 1) & (e.Some < 10) | (e.Some == -1)

So, EF is also trying to convert bit operations to the SQL.

Instead of them use Expression.AndAlso and Expression.OrElse which are Boolean logical operators

e => (e.Some > 1) && (e.Some < 10) || (e.Some == -1)

For analysis generated expressions, I would suggest to use ReadableExpressions.Visualizers and probably you will find mistake by yourself.

为什么使用案例而不是在何处从表达中生成查询?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文