I am going to make a page where users can register and complete a survey, but the survey can be long, so I would like to know how I could make that when the user decides to stop, the data they entered reappears when they log in to the page and can continue where the survey left off.
Category: PHP
Category Added in a WPeMatico Campaign
function (Blueprint $table), Is $table a variable/property / object??? Which class’s object/ variable/property?
Schema::create(‘flights’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(‘airline’); $table->timestamps(); });
create tracking like feature using laravel and mysql?
Hope this question doesn’t get downvotes as it is little theoretical and it is a feature enabled in my application which is of real time racing appliccation.
In this application admin creates races and set some route and racers play those races with their mobile as they must have our product app.
Now what I am going to explain is we have created our own tracking feature for our admins in which admin can see the current positions of all the racers and for that we have done this implementation
there was a api which recieves user location in every 2-3 seconds and those records are stored in Database
(mysql database,INNODB)
and these are the field which i stored
{
"latitude":"",
"longitude":"",
"timestamp":""
"bearingAngle":"",
"currentSpeed":""
}
in my location table and for currentlocation i used to query my users latest location according to time and from that i was able to create current location tracking
one more feature which i introduced was complete tracing of users in which i use all the locations stored in DB and create a KML (Keyhole markup language) file by which complete track is visible to admin which racer has used for that race.
This was working fine but when the races increased the DB load gradually increased and day after day my tracking performance decreased as there were so much data and querying that data my db performance went down ….
For that i switched my implementations and instead of storing location data into DB
i stored those location data in txt files in this format
latitude|longitude|timestamp|bearingAngle|currentSpeed
latitude|longitude|timestamp|bearingAngle|currentSpeed
latitude|longitude|timestamp|bearingAngle|currentSpeed
latitude|longitude|timestamp|bearingAngle|currentSpeed
.
.
.
.
.
and stored only the latest location on table
from now i can get the current location from the tables and for tracing part i can use my files
this implementation reduced my load on DB and my performance also improved on backend level
Now there is no such code to debug but it is a architecture which i want to create and also created and at my own I did my best to optimize this implementation but somewhere in my mind there is some doubt that might be this implementation can be done more efficiently and I just want some ideas that how can i achieve this implementation more better.
Hope my problem is understood and again I am repeating this is not code level issue it is just a implentation improvement.
Thank you !!!
Partial mocking a Facade ignores the variables that are set in the constructor
I have a class names AbcService
<?php
namespace AppHttp;
class AbcService
{
private string $attr;
public function __construct()
{
$this->attr = 'some text';
}
public function aMethod(): bool
{
if (empty($this->attr)) {
return true;
}
return false;
}
public function bMethod()
{
return 'what';
}
}
I’ve created a facade on top of that:
<?php
namespace AppHttp;
use IlluminateSupportFacadesFacade;
class Abc extends Facade
{
protected static function getFacadeAccessor()
{
return AbcService::class;
}
}
Now calling this code from the tink
session (php artisan tink
) outputs true
, meaning that the attr
value did not change in the constructor.
use AppHttpAbc;
Abc::partialMock();
Abc::shouldReceive('bMethod')->once()->andReturn('partialMock');
print_r(Abc::aMethod());
I’ve placed a dd
in the constructor after changing the value of attr
and we know after calling the Abc::partialMock()
the constructor executed. Is this the normal behavior of the partialMock
in the Facade
? How can I only mock the bMethod
method and use other part of the class without changes?
Number to Excel column name conversion
In Excel, column names are characters from A to Z, if there are more columns needed, it continues with AA, AB ...
I want to write a function, that converts integers to those excel column names.
0 .... A
25 ... Z
26 ... AA
The solution I came up with is working up to AZ
, but I want it to work further.
function indexToXlxsColumn($index, $prefix="")
{
if($index < 26)
{
return $prefix.chr($index+65);
}else{
return indexToXlxsColumn($index % 26, "A");
}
}
How to adapt this function to work for each index without producing spaghetti code?
why pagniate_links not working any more in wordpress
paginate links shows a whitespace in my website i stuck for 2 days and the issue didn’t resolve
my code in function.php
function pagination_bar(){
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
my function call in index.php
<?php pagination_bar();?>
please Help??
How to integrate api platform with symfony
I am using the Platform API framework with fresh Symfony installation.
composer require api
composer require webonyx/graphql-php
in debug routes
php bin/console debug:router
I got :
- api_entrypoint ANY ANY ANY /api/{index}.{_format}
- api_doc ANY ANY ANY /api/docs.{_format}
- api_graphql_entrypoint ANY ANY ANY /api/graphql
- api_graphql_graphiql ANY ANY ANY /api/graphql/graphiql
- api_graphql_graphql_playground ANY ANY ANY /api/graphql/graphql_playground
but nothing work (no api platform interface).
Any help?
Select last 7 days records by date and avoid duplicates by specific column
I’m pretty sure the problem I’m facing is quite small, but I can’t figure out what’s wrong.
I have the following table in my sql:
+-----+------------------+---------------------+
| ID | EMAIL | VISIT |
+-----+------------------+---------------------+
| 1 | [email protected] | 2021-04-01,13:20:23 |
| 2 | [email protected] | 2021-04-03,12:03:44 |
| 3 | [email protected] | 2021-04-04,13:21:12 |
| 4 | [email protected] | 2021-04-06,09:34:31 |
| 5 | [email protected] | 2021-04-07,11:20:22 |
+-----+------------------+---------------------+
I want to display the last 7 days records but ordered by newest date and showing only the newest record by each email, like this
+-----+------------------+---------------------+
| ID | EMAIL | VISIT |
+-----+------------------+---------------------+
| 3 | [email protected] | 2021-04-04,13:21:12 |
| 4 | [email protected] | 2021-04-06,09:34:31 |
| 5 | [email protected] | 2021-04-07,11:20:22 |
+-----+------------------+---------------------+
I’ve tried this query to achieve this:
Attempt 1: SELECT * FROM table WHERE VISIT BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW() GROUP BY EMAIL ORDER BY VISIT DESC
Attempt 2: SELECT DISTINCT (EMAIL) FROM table WHERE VISIT BETWEEN (NOW() - INTERVAL 7 DAY) AND NOW() ORDER BY VISIT DESC
The results are displayed correctly, but in a strange order.
If I give up GROUP BY clause, it displays correctly but also includes EMAIL column duplicates.
How to make sure a user enters an email format in an email input?
I have a form with an email field using html and php.
I would like to make sure that the user enters an email.
On the HTML side, I put :
type = "email"
Is it necessary to add a (filter_var($email, FILTER_VALIDATE_EMAIL)
on the PHP side?
The view is not displaying returned data *LIST* from the controller ( PHP – JQUERY )
I want to send a list ($data = [“1″,”2”];) to the controller from the view, and the result (1 2) be shown on the console,
but my code shows the code source of the view page! not the list $data
CHECK THE IMAGE:
MY CODE :
———
Controller:
public function deliverySetup(){
if(isset($_POST['request'])){
$request = $_POST['request'];
if($request == 'deliverySetup'){
$data = ["1","2"];
$this->view("control/hajar", $data);
}
}
}
View:
function deliverySetup(){
$.post('<?php echo URLROOT ?>' + 'Scan/deliverySetup', {request: 'deliverySetup'}, function (data) {
console.log(data);
});
}
Attempt to assign property of non-object when updating the existing the record
I want to update some records from my table and if user has uploaded a picture, I need to upload it and update the seller_certificate_card
as well.
Here is my code:
public function doStepTwo(Request $request, $id)
{
$newSeller = Seller::where('id', $id)->update([
'seller_first_name' => $request->fname_seller,
'seller_last_name' => $request->lname_seller,
]);
if($request->hasFile('upload_certificate'))
{
$destination_path = "public/images/sellers/$user_id";
$image = $request->file('upload_certificate');
$image_name = $image->getClientOriginalName();
$path = $request->file('upload_shenasname')->storeAs($destination_path,$image_name);
$newSeller->seller_certificate_card = $image_name;
$newSeller->save();
}
}
And the seller_certificate_card
at the table has this structure:
seller_certificate_card varchar(255)
But I get this error:
Attempt to assign property ‘seller_certificate_card’ of non-object
So what’s going wrong here? How can I fix this issue?
How to return to the DOM a string variable from controller that contains an html image tag with asset() function in src ? [laravel 9][php 8]
I am facing an issue with laravel 9.
In my controller, I have created a variable wich contains inside quotes the html code to be returned to the view.
I have a problem to determine where I should use single quotes and double quotes or backticks so that the {{asset()}} in the image src is compiled properly.
for now my image url looks like this in the console :
http://127.0.0.1:8000/%7B%7B%20asset(storage/upload/test2-png.png)%20%7D%7D
Here is the error in the console :
GET http://127.0.0.1:8000/%7B%7B%20asset(storage/upload/test2-png.png)%20%7D%7D 404 (Not Found)
Here is the variable I am talking about :
$celebrityDetailsContent = "
<div id='celebrity_text_and_picture_container' class='w-100 p-3'>
<img src='{{ asset(storage/upload/{$celebrityClicked->image}) }}' class='float-start img-border-radius img-thumbnail w-50 m-3' alt='Celebrity photo' title='Celebrity photo'>
<p class='fw-bold'>{$celebrityClicked->firstname} {$celebrityClicked->lastname}</p>
<p class='text-start'>{$celebrityClicked->description}</p>
</div>
";
return $celebrityDetailsContent; ```
Thanks for your Help.
PHP ftp_connect in readonly mode
There is a way to establish a read-only ftp connection with PHP?
I only need to do these inside the remote ftp:
- ftp_connect
- ftp_login
- ftp_chdir
- ftp_get
- ftp_close
If I, for mistake, delete/modify something on the remote ftp it’ll be a very big problem (due to work matters).
(I already check my code 10 times and do a lot of tests, but human error is always possible.)
Thanks
php calculation keeps getting the answer as 0
this is the index.php file
if(isset($_POST['submit']))
{
echo header('Location:answer.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<form method="post">
<div class="form-group">
<label> Insert P value </label>
<input type="text" name="p" placeholder="please insert your P value">
</div>
<br>
<div class="form-group">
<label> Insert R value </label>
<input type="text" name="r" placeholder ="please insert your R value ">
</div>
<br>
<div class="form-group">
<label> Insert your N value </label>
<input type="text" name="n" placeholder=" please insert your N value">
</div>
<br>
<button type="submit" name="submit" > Submit </button>
</body>
</html>
this is the answer.php file
<?php
$p=isset($_POST['p'])?$_POST['p']: " ";
$r=isset($_POST['r'])?$_POST['r']:" ";
$n=isset($_POST['n'])?$_POST['n']: " ";
$si=(int)$p*(int)$r*(int)$n/100;
echo "Hello this is the final answer ".$si;
?>
i want the answer to be displayed in another page that is answer.php but whatever number i am inserting i keep getting the answer as 0. Please help and thank you.
how to put an array paramter in a sql command?
$stmt = $conn->prepare("UPDATE stopwatch SET $array[0] = ......
$stmt->execute();
doing $array[0]
works fine in my sql command, but i want an variable in my array parameter like $array[$value]
doing this doesn’t work.
To explain a bit i want to do an sql commmand that use a php get methode and the variable that i get from the get methode i want to put in an array like that:
$value = $_GET['value']; // value = 2 for example
$ID = array("t_inter_1", "t_inter_2", "t_inter_3", "t_arrivee");
echo $ID[$_GET['value']]; // works fine
echo $ID[$value]; // works fine
but doing this in my sql command doesn’t work. I don’t know what am i supposed to do, and I don’t know what I am doing wrong, thanks for the help