Thursday, March 9, 2017

How to update multiple cells in three (3) different columns with the same cell id, if any cell is empty update it with a value

My table consists of a column called 'gethelp'. When a user creates an account the users 'gethelp' column is equals to 'no' until the user makes payment. When the user makes payment the users 'gethelp' column = yes. The code searches the DB according to the ASCENDING ORDER, if a users 'gethelp' column = yes. We have columns called 'p1', 'p2', 'p3'. If your gethelp column is = yes, your screen will tell you to wait so you can be paired with a user to pay you. If you gethelp column is = no, your screen will show a button which displays 'make payment', when you click on that button it checks the DB for users who's gethelp column = yes, then it should update 'p1' column if 'p1' with the Auth::user()->email if column 'p1' already has a value probably updated already by an authenticated user, it should check p2, if p2 already has an email it should check p3.

This is my code:

public function GetUsersWhoNeedPayments()
{
    $UserToPay1 = DB::table('users')->where([
    ['gethelp', '=', 'YES'],
    ['paired_with1', '']
    ])->orderBy('updated_at', 'ASC')
    ->first();
    if(count($UserToPay1)>0)
    {
        echo $UserToPay1->name;
        $pairing = DB::table('users')->where([
        ['id', $UserToPay1->id]
        ])
        ->update(['paired_with1'=>Auth::user()->email]);
        #This code (Codename: GetBrokeUsers) Stops here!
        return view('makepayments', compact('UserToPay1'));
    }
    else{
        return view('makepayments')->with(['NoUserToPayMessage'=>'Please wait while we search for a user for you to pay.']);
    }
}

public function CheckIfYOuHaveGottenHelp()
{

        $GETHELP = Auth::user()->gethelp;

    if($GETHELP === 'YES')
    {

        $info = DB::table('users')->where(
        ['email' => Auth::user()->paired_with1]
        )->first();

        if($info == '')
        {
            $message = 'You will receive payment shortly, please wait while the system searches for a user to pay you.';
            return view('home', compact('message'));

        }

        else

        {
           return view('home', compact('info')); 
        }



    }

    else if($GETHELP === 'NO')
    {        
        return view('home')->with('GetHelpStatusMessage', 'Make Payment');
    }

    else 
    {
        return view('home')->with('GetHelpStatusMessage', 'There seems to be problems with your account. Contact us if you see this message.');
    } 

}

this is my home view:

@extends('layouts.app')

@section('content')
<div>


@if(isset($GetHelpStatusMessage))
<div class="container" style="text-color: white;">
<a href="" class="btn btn-lg" style="background-     color: black; color: green;">



</a>
</div>
@endif


@if(isset($message))
<h1 style="color: #000000;">Sorry :(</h1>

<p style="color: #000000;">  </p>
@endif



@if(isset($info))



<div class="container">


You are to receive payment of the sum 10,000 naira from the user below :
<br>
<br>
<table class="table">
<thead>

<tr>
<th>Bank Name</th>
<th>Account Name</th>
<th>Account Number</th>
<th>Phone Number</th>
<th>Time Left Before The Other User Is Blocked</th>

</tr>

</thead>

<tbody>

<tr class="active">

<td>

</td>
<td>

</td>
<td>

</td>

<td>

</td>

<td>
Count Down
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<input type="button" class="btn" value="Confirm Payment" style="background-  color: grey; color: white;"/>
</td>

</tr>

</tbody>


</table>


</div>

@endif

<br>

</div>
@endsection

the issue is it searches for column p1 only and stops..it doesnt search p1,p2,p3 cells of the same id before checking the next id, and the next, and the next..i want it to check the cells 3 cells and if they have value then it should go to the next row



via OG Paul Caleb

Advertisement