小编Und*_*e2k的帖子

将多个参数传递给函数php

为新手问题道歉,但我有一个带两个参数的函数,一个是数组,一个是变量function createList($array, $var) {}.我有另一个函数调用createList只有一个参数$ var,doSomething($var);它不包含数组的本地副本.我怎样才能将一个参数传递给一个在PHP中需要两个参数的函数?

尝试解决方案:

function createList (array $args = array()) {
    //how do i define the array without iterating through it?
 $args += $array; 
 $args += $var;


}
Run Code Online (Sandbox Code Playgroud)

php function

14
推荐指数
2
解决办法
4万
查看次数

Codeigniter DB类与预处理语句

嗨,我想知道使用Codeigniters活动记录类是否等同于在安全问题方面使用预准备语句?

<?php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

// insert one row
$name = 'one';
$value = 1;
$stmt->execute();

?>
Run Code Online (Sandbox Code Playgroud)

 $data = array(
   'title' => 'My title' ,
   'name' => 'My Name' ,
   'date' => 'My date'
);

$this->db->insert('mytable', $data); 

// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
Run Code Online (Sandbox Code Playgroud)

php mysql mysqli pdo codeigniter

4
推荐指数
1
解决办法
6233
查看次数

如何删除字符串中最后一次出现的下划线

我有一个包含许多下划线的字符串,后跟单词ex:" Field_4_txtbox"我需要找到字符串中的最后一个下划线并删除它后面的所有内容(包括"_"),所以它会返回给我" Field_4"但我需要这个为不同长度的结束字符串工作.所以我不能修剪固定的长度.

我知道我可以做一个If语句,检查某些结局,比如

if(strstr($key,'chkbox')) {
    $string= rtrim($key, '_chkbox');
}
Run Code Online (Sandbox Code Playgroud)

但是我想用一个正则表达式一次性完成这个,我怎么能做到这一点?

php regex

4
推荐指数
2
解决办法
2206
查看次数

获取Jquery进度条的值

我希望找到进度条的值,这样我就可以在每一步中增加一个百分比,但无论我尝试它还是说它未定义,或者在实例化对象之前无法调用该方法.

我试过的事情:

 alert($('progressbar:first').prop('progress-label')); 

 progressbarValue = progressbar.find( ".progress-label" ).val();
Run Code Online (Sandbox Code Playgroud)

HTML

<div id="progressbar"><div class="progress-label">Form Process</div></div>
Run Code Online (Sandbox Code Playgroud)
if(condition == true) {

    progressbar = $( "#progressbar" );
    progressbarValue = progressbar.find( ".ui-progressbar-value" );
    progressLabel = $( ".progress-label" );


    var size = parseInt($("#fieldWrapper .step").size(),10);
    var progress = 100/size ; 

 alert($('progressbar:first').prop('progress-label')); 
  progressbar.progressbar({
      value: progress,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );

      },
      complete: function() {
        progressLabel.text( "Complete!" );
      }
    });

        progressbarValue.css({
          "background": '#' + Math.floor( Math.random() * 16777215 ).toString( 16 )
        });

}
Run Code Online (Sandbox Code Playgroud)

html jquery

3
推荐指数
1
解决办法
5691
查看次数

bash脚本语法错误:word意外(期待"do")

我正在尝试在我的nginx服务器上运行此Dropbox脚本,但我得到:

 Syntax error: word unexpected (expecting "do")
Run Code Online (Sandbox Code Playgroud)

我复制粘贴网站的脚本,我尝试删除特殊字符,但我仍然得到相同的错误.

脚本:

#!/bin/sh
# /etc/init.d/dropbox
### BEGIN INIT INFO
# Provides:          dropbox
# Required-Start:    $network $syslog $remote_fs
# Required-Stop:     $network $syslog $remote_fs
# Should-Start:      $named $time
# Should-Stop:       $named $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop the dropbox daemon for debian/ubuntu
# Description:       Dropbox daemon for linux
### END INIT INFO

DROPBOX_USERS="root"
start() {
    echo "Starting dropbox..."
    for dbuser in $DROPBOX_USERS; do
        start-stop-daemon …
Run Code Online (Sandbox Code Playgroud)

bash nginx

3
推荐指数
1
解决办法
9837
查看次数

嵌套数组的 Mustache 模板

我怎样才能使用小胡子循环这个?我有一个数字索引的外部数组。或者如何做其他事情并保持这个结构?

我试过:

<ul>
{{#cars}}  
<li> {{#.}} {{.}} {{/.}}</li>
{{/cars}}
</ul>
Run Code Online (Sandbox Code Playgroud)

大批

>   Array(
>             [cars] => Array 
>                 (
>                  [0] => Array
>                      (
>                        [0] => Array
>                           (
>                             [id] => 343443
>                             [name] => Mazda
>                           )
>         
>                         [1] =>
>                           (
>                             [id] => 45353
>                             [name] => Toyota
>                           )
>                      )
>                   [1] => Array 
>                       (
>                          [0] => Array 
>                           (
>                             [id] => 922424
>                             [name] => Camry
> …
Run Code Online (Sandbox Code Playgroud)

php mustache

3
推荐指数
1
解决办法
4520
查看次数

将参数传递给包含在 IMG 标签中的 PHP 文件

我有两个文件 [Main.html] 和 [image.php]。然而,[image.php] 正在处理二进制数据,因为它显示来自数据库的图像。我的问题是我可以,如果我可以,我如何将参数从 main 传递到 [image.php]?

我像这样在 main 中调用 image.php:

img src="image.php" alt="从数据库中检索的图像"

<?php
$mysqli=mysqli_connect('localhost','root','','draftdb');
if (!$mysqli)
die("Can't connect to MySQL: ".mysqli_connect_error());


    $stmt = $mysqli->prepare("SELECT display.PICTURE_ID 
    FROM cards  
    INNER JOIN display ON cards.DISPLAY_ID = display.DISPLAY_ID 
    WHERE display.DISPLAY_ID=? AND cards.CARD_TYPE =?" );

     if( rand(1, 8) == 8) 
     {
     $cardtype='Mythic';
     $displayid=rand(1,15) ;

     }

     else
     {
     $cardtype='Rare';
    $displayid=rand(16,19) ;
     }

    $stmt->bind_param("si", $displayid, $cardtype);
    $stmt->execute();
    $stmt->bind_result($image);
    $stmt->fetch();
    header("Content-Type: image/jpeg");
    echo $image; 
    ?>
Run Code Online (Sandbox Code Playgroud)

php mysql

2
推荐指数
1
解决办法
2105
查看次数

用Mysqli登录PHP

我是相对较新的php/mysqli我无法验证用户,我不确定如何获取行并验证数据,然后将用户重定向到新页面或显示错误(所有我知道我需要使用_SESSION).基本上我遇到了fetch()例程的问题,对此进行编码的正确方法是什么?


  <?php 
    session_start();
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    /* Create a new mysqli object with database connection parameters */
    $mysqli = mysqli_connect('localhost', 'root', '', 'draftdb');

    if(mysqli_connect_errno()) 
    {
          echo "Connection Failed: " . mysqli_connect_errno();
          exit();
    }
       /* Create a prepared statement */
    if($stmt = $mysqli -> prepare("SELECT Login_ID, Login_PW,
    FROM login  
    WHERE Login_ID=? AND Login_PW =?"))
     {

          /* Bind parameters
             s - string, b - boolean, i - int, etc */
          $stmt -> bind_param("ss", $username, $password);

          /* Execute it …
Run Code Online (Sandbox Code Playgroud)

html php mysql mysqli

2
推荐指数
1
解决办法
7005
查看次数

在Codeigniter中包含Zend Library

所以我正在尝试安装一些Zend Framework组件,因此我可以使用google API picasa库.

我尝试将Zend库添加到我的

codeigniter-> application-> libraries

然后跑步$this->load->library('Zend');但我收到了

无法加载请求的类:zend

然后我试着这样做

$clientLibraryPath = '/usr/local/lib/php/Zend/Gdata';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
Run Code Online (Sandbox Code Playgroud)

错误

> Exception thrown trying to access Zend/Loader.php  using
> 'use_include_path' = true. Make sure you  include Zend Framework in
> your include_path  which currently  contains:
> .:/usr/share/php:/usr/share/pear:/usr/local/lib/php/Zend/Gdata
Run Code Online (Sandbox Code Playgroud)

我不确定实际路径应该是什么我也将Zend libary上传到users/local/lib/php.我究竟做错了什么?

php zend-framework codeigniter

2
推荐指数
1
解决办法
3252
查看次数

javascript按变量名称将项目推送到对象中

对不起新手问题,但我必须忽视一些事情.如何设置obj.{this.name} = propertyobj.sandwich = off.我的对象看起来像:

obj { sandwich: off, soup: off }
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/naaua4b5/

复选框列表:

<input type = "checkbox" name = "sandwich" />
<input type = "checkbox" name = "soup" />
Run Code Online (Sandbox Code Playgroud)

js代码:

var obj = {} ; 

$('input[type=checkbox]:not(:checked)').map(function()
{
     var item_name =  this.name;
     var value = 'off';
     obj.item_name = value;
}).get();

console.log (obj);
Run Code Online (Sandbox Code Playgroud)

javascript

1
推荐指数
1
解决办法
632
查看次数

在非对象上调用成员函数get()

我正在使用Codeigniter框架,我收到以下错误,

在第11行的site_model.php中的非对象上调用成员函数get()

这是get()的行.test是我数据库中表的名称.我究竟做错了什么?

<?php
    class Site extends CI_Controller 
    {
        function index()
        {
            $this->load->model('site_model');
            $data['records']= $this->site_model->getAll();
            $this->load->view('home',$data);
        }
    }

?>

<?php

    class Site_model extends CI_Model 
    {

        function getAll()
        {
            $q = $this->db->get('test');
            if($q->num_rows > 0 )
            {
                foreach ($q ->result() as $row )
                {
                    $data[] = $row ;
                }
            }
        return $data;
        }
    }
Run Code Online (Sandbox Code Playgroud)

php codeigniter

0
推荐指数
1
解决办法
9723
查看次数

如何让div元素与页面一起滚动

我有一个div元素,我想在滚动页面时移动它,如下图所示.但是现在它只是坐在一个固定的位置.我怎么能做到这一点?我知道我需要使用JS,有人能指出我正确的方向吗?

滚动

<div id='slider'>


</div>
Run Code Online (Sandbox Code Playgroud)

html javascript

0
推荐指数
1
解决办法
387
查看次数

在PHP中访问数组中的对象

以下是来自Salesforce的以下返回查询.如果我尝试这样做,$form_information[0]->Program_Type__c;我会收到以下错误:

不能使用stdClass类型的对象作为数组

下面是我的以下数组,其中包含一个对象?我的问题是如何从我的对象中提取Program_type__c和Campus_ID__c并将其保存到变量中?

print_r($form_information);



Array
    (
        [totalSize] => 1
        [done] => 1
        [records] => Array
            (
                [0] => stdClass Object
                    (
                        [attributes] => stdClass Object
                            (
                                [type] => Program_Instance__c
                                [url] => /services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG
                            )

                        [Program_Type__c] => Field Science
                        [Program_Sub_type__c] => 
                        [Campus_ID__c] => a03i0000002DDBjAAO
                    )

            )

    )
Run Code Online (Sandbox Code Playgroud)

var_dump

array(3) {
  ["totalSize"]=>
  int(1)
  ["done"]=>
  bool(true)
  ["records"]=>
  array(1) {
    [0]=>
    object(stdClass)#21 (4) {
      ["attributes"]=>
      object(stdClass)#22 (2) {
        ["type"]=>
        string(19) "Program_Instance__c"
        ["url"]=>
        string(68) "/services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG"
      }
      ["Program_Type__c"]=>
      string(13) "Field Science"
      ["Program_Sub_type__c"]=>
      NULL
      ["Campus_ID__c"]=>
      string(18) …
Run Code Online (Sandbox Code Playgroud)

php salesforce

0
推荐指数
1
解决办法
251
查看次数