小编Eli*_*Eli的帖子

如何使用laravel 5迁移在表中添加列而不丢失其数据?

我有一个现有的数据库表,我想在其上添加列.但是,当我运行php artisan migrate命令时,它没有说任何迁移.但是我已经添加了一个用于添加表列的Schema.我已经阅读了一些文章和链接,我应该php artisan migrate:refresh在添加新列之前先运行.问题是,它将删除我表中的现有数据.有没有什么办法可以执行迁移并在我的表中成功添加列而不删除我的数据?请帮我解决一下这个.非常感谢.这是我的迁移代码.

public function up()
{
    //
    Schema::create('purchase_orders', function(Blueprint $table){

        $table->increments('id');
        $table->string('po_code');
        $table->text('purchase_orders');
        $table->float('freight_charge');
        $table->float('overall_total');
        $table->timestamps();

    });

    Schema::table('purchase_orders', function(Blueprint $table){
        $table->string('shipped_via');
        $table->string('terms');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    //
    Schema::drop('purchase_orders');
}
Run Code Online (Sandbox Code Playgroud)

我想添加列shipped_via,并terms在我的purchase_orders表.

php migration postgresql laravel-5.2

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

Codeigniter $ this-> db-> order_by('','desc')结果不完整

我想在我的模型中使用下面的查询按降序对数据库值进行排序.但是,它并没有完全按降序排列数据库中的所有值,但是当使用升序时,它运行良好.

function sort_all_courses_desc($tennant_id)
{
    $this->db->select('*');
    $this->db->where('tennant_id',$tennant_id);
    $this->db->order_by("course_name","desc");
    $this->db->from('courses');
    $query=$this->db->get();
    return $query->result();
}
Run Code Online (Sandbox Code Playgroud)

php codeigniter

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

如何在Codeigniter中正确使用Alias

这是我的代码:

$this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE);
$this->db->from('courses');
$this->db->where('tennant_id',$tennant_id);
$this->db->order_by('course_name','ASC');
$query = $this->db->get();
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
Run Code Online (Sandbox Code Playgroud)

codeigniter

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

使用 codeigniter 比较数组中的数据并计算它在数据库中出现的实例数

我有这个数组 month $monthsNum = ['1','2','3','4','5','6','7','8','9','10','11','12'];,我希望在我的数据库列month_uploaded 中将其与 1-12 之间的值进行比较。我希望它计数实例的数量$ monthsNum发生在列数组值month_uploaded并将其存储在数组$ count_uploads .Zero计数被放置在阵列$ count_uploads零值。我该怎么做?非常感谢您的帮助。谢谢你。下面是我的代码片段。

在此处输入图片说明

function count_uploads_perMonth(){

  $monthsNum = ['1','2','3','4','5','6','7','8','9','10','11','12'];

  $query = $this->db->select("*")
                    ->from($this->table_par)
                    ->where_in("month_uploaded",$monthsNum)
                    ->get();


      foreach( $query->result() as $row ){

        $count_uploads[] = count($row->month_uploaded);

      }

      var_dump($count_uploads);

}
Run Code Online (Sandbox Code Playgroud)

输出:错误

array (size=5)
0 => int 1
1 => int 1
2 => int 1
3 => int 1
4 => int 1
Run Code Online (Sandbox Code Playgroud)

期望输出:

 array (size=12)
 0 => 0 or null
 1 => 0 or null
 2 => …
Run Code Online (Sandbox Code Playgroud)

php mysql arrays activerecord codeigniter

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

如何使用javascript获取数组中特定id的最后一个值?

我有一个函数将行的值存储在数组 onkeyup 事件中。但是,在某些情况下,它会存储相同的行值,但数量和总数不同,但 ID 相同。我如何将它存储在数组中,以便只保存特定 id 的最新值集?我知道这有点令人困惑,但请看下图。感谢您的帮助。

在此处输入图片说明

我想保存ff:

{id:"1", qty:"4", price:"45", total:"180"}
{id:"2", qty:"3", price:"10", total:"30"}
{id:"3", qty:"50", price:"12", total:"600"}
{id:"4", qty:"60", price:"12", total:"720"}
Run Code Online (Sandbox Code Playgroud)

我的代码:

var arrayVar = [];
var data;

$(function(){

  $('#tbl-po-list').on( 'keyup change' , 'input[type="number"]' ,function(){

    $(this).parents('.info').find('.total').val($(this).val() * $(this).parents('.info').find('.price').val());

      data = {
        id: $(this).parents('.info').find('.prod-id').val(),
        qty: $(this).val(),
        price: $(this).parents('.info').find('.price').val(),
        total: $(this).parents('.info').find('.total').val()
      }

      arrayVar.push(data); 

      for(var i = 0; i < arrayVar.length; i++){
        console.log(arrayVar[i]);
      }

    });   

  });
Run Code Online (Sandbox Code Playgroud)

javascript arrays ajax jquery

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

Laravel和查询使用join和distinct

我有2个表要使用查询join,即loansamortizations表。

Loans表中有许多摊销,所以loans.id是一个参考amortizations.loan_idamortizations表格。

Loan id:3存在两次amortizations table,每个都有value=10,800
Loan id:5在中也存在两次amortizations table,每个都有一个value=11,100和相同的搭配Loan id:11,在amortizations table每个中也存在两次都有一个value=5400
当您加起来时,total54,600。但我希望ID可以区分,以便值不会相加两次。因此总数等于27,300。我下面的现有查询返回一个54,600值,而不是27,300甚至distinct()在Laravel中使用它。我将如何实现?

Controller query

$oneToThirtyDue = Amortization::distinct('amortizations.loan_id')
                ->join('loans', 'loans.id', '=', 'amortizations.loan_id')
                ->select('loans.loan_type',\DB::raw('SUM(loans.loan_balance) as total_val'))
                ->where('amortizations.payment_status',0)
                ->where('amortizations.schedule', '<', date('Y-m-d'))
                ->where('amortizations.past_due', '<=', 30)
                ->groupBy('loans.loan_type')
                ->orderBy('loans.loan_type')
                ->get();
Run Code Online (Sandbox Code Playgroud)

请帮忙。非常感谢。

sql join laravel eloquent

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

如何使用jquery自动计算表行?

我有一个有 3 个表行的表,每行包含 5 列和输入文本框,最后一列是 4 列中输入的值的总和。我想在 4 列填充值后使用 jquery 或 javascript 自动计算总数。我怎么能这样做?这是我的表格代码。

桌子

<table name="tbl_a" id="tbl_a">
<tr>
    <td><span style="margin-left:30px;">a. Provision of  certified seeds</span></td>
    <td>no. of bags</td>
    <td>per AT</td>
    <td><input type="text" class="form-control" name="at[a]" id="a" value=""  style= "width:160px;"/></td>
    <td><input type="text" class="form-control" name="at[b]" id="b" value=""  style= "width:160px;"/></td>
    <td><input type="text" class="form-control" name="at[c]" id="c" value=""  style= "width:160px;"/></td>
    <td><input type="text" class="form-control" name="at[d]" id="d" value=""  style= "width:160px;"/></td>
    <td><input type="text" class="form-control" name="at[total_1]" id="total_1" value="" placeholder="total" style= "width:160px;"/></td>
</tr>
<tr>
    <td></td>
    <td>no. of farmers</td>
    <td></td>
    <td><input type="text" class="form-control" …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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