I have a pagination script, which can be seen here:
http://www.automotori6282.tk/phpsandbox/
This is the source code:
http://pastebin.com/raw.php?i=63dCvfxD (PmcPagination.php)
http://pastebin.com/raw.php?i=3k4nqwRB (demo.php, the page with the code in)
and index.php for http://www.automotori6282.tk/phpsandbox/ simply uses PHP's include() function to show demo.php
What I'm trying to do is extract from two tables for the pagination.
This is my current database structure:
programme varchar(255)
channel varchar(255)
episode varchar(255)
series varchar(255)
setreminder varchar(255)
However, I have the episodes stored in a separate table, and would like to make a query which extracts from both epdata167 and episodes table (the episodes table only has episode, seriesno, episodeno and description as its fields).
One error I made in my pagination script shows here:
TV Show showing on Channel 1 August 3rd - 12:30pm "" Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1" Set Reminder
and it still remains long after the event has happened.
This is how it should work:
TV Show showing on Channel 1 August 3rd - 12:30pm
TV Show showing on Channel 1 August 3rd - 2:45pm Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1" Set Reminder
Notice how the Set Reminder field doesn't show when the event happens, and there's no quotation marks if an episode isn't selected.
(The setreminder field is basically a link that a user would click on to send a reminder to them saying "TV show is airing on Channel 1 August 3rd - 8:30pm Episode 1" or "TV show is airing today at 8:30pm Episode 1". However, it would not display for the show that is airing right now, it would display like this:
TV Show showing on Channel 1 August 3rd - 12:30pm
)
This is the pagination code causing trouble:
$result = mysql_query("SELECT programme, channel, airdate, expiration, episode, series, setreminder FROM epdata167 where airdate > curdate() GROUP by airdate");
and here is the part of the pagination code I edited to try and use an ifelse statement but wasn't sure what to do:
class paginationData {
private $program;
private $channel;
private $airdate;
private $exiration;
private $episode;
private $series;
private $setReminder;
public function __construct($program, $channel, $airdate, $expiration, $episode, $setReminder)
{
$this->program = $program;
$this->channel = $channel;
$this->airdate = strtotime($airdate);
$this->expiration = $expiration;
$this->episode = $episode;
$this->setReminder = $setReminder;
}
//This function shows the data
public function display()
{
if(date('Y-m-d') == date('Y-m-d', $this->airdate)) $dateFormat = 'g:ia';
elseif(date('Y') == date('Y', $this->airdate)) $dateFormat = 'F jS - g:ia';
else $dateFormat = 'F jS, Y - g:ia';
echo '<tr>'."\n".
' <td><strong>'.$this->program.'</strong></td>'."\n".
' <td>showing on '.$this->channel.'</td>'."\n".
' <td>'.date($dateFormat, $this->airdate).'</td>'."\n".
' <td><b>"'.$this->episode.'"</b><br></td>'. "\n".
' <td>'.$this->setReminder.'</td>'."\n".
'</tr>'."\n";
}
}
Basically, I'm having trouble trying to get data as this in my project:
TV Show showing on Channel 1 August 3rd - 12:30pm
TV Show showing on Channel 1 August 3rd - 2:45pm Set Reminder
TV Show showing on Channel 1 August 3rd - 8:30pm "Episode 1"
Series 1, episode 1 Set Reminder
(that's if the episode is part of a series with a series number)
Not sure what JOIN to use and where, all help is appreciated trying to get this to work since I've got the pagination working; just trying to get the finer details working!
I'm not asking for people to do it for me, I've been learning myself, and have done my research.
Sorry if this seems a bit long, but I hope I've explained it all.
Thanks.
You need to use a UNION to get this to work.
Related
I'm building an application that schedules aircraft for flight schools/flying clubs, etc.
I currently have a schedule grid running that allows the user to click on a square to book a reservations starting at that time. That function works perfectly, however, if a single booking exists in the system, for some reason, Laravel deletes the final part of the URL, throwing a 404. Any thoughts on this? I inspected the page and it physically looks like the view is being altered, although the code clearly shows this part. See below:
When there are no records, if a user selects a box on the grid, they are directed to finalize the booking at:
/app/schedule/new/{time}/{date}/{resource}/{instructor?}
For example, a booking starting at 730am today with no instructor using resource #1 (plane 1) is:
/app/schedule/new/0730/20201204/1
However, when there is a booking in the system, all boxes on the grid point to
/app/schedule/new/{time}/{date}
Or, in our example:
/app/schedule/new/0730/20201204 (this is incorrect, there should be a /1 at the end)
Here is my route:
Route::get('/app/schedule/new/{time}/{date}/{resource}/{instructor?}', 'ScheduleController#show_new_booking_form');
And the view href which points to the correct link (instructor is optional):
<a href="/app/schedule/new/0730/{{$raw_date}}/{{$aircraft->aircraft_id}}">
(Edited) Complete steps for all this to happen.
User visits the bookings page with the schedule grid. This is where they would select the link from above. The controller method for that is:
public function show_schedule(Request $request)
{
// Reference Variables
$days = $request->days;
$org_id = Auth::user()->org;
// Information on Dates & Date Incremation
$today = Carbon::now('US/Eastern');
$date = $today->addDays($days);
$schedule_date = $date->isoFormat('dddd MMMM D, YYYY');
$raw_date = $date->isoFormat('YYYYMMDD');
$aircraft = DB::table('aircraft')->where('org', $org_id)->get(); // gets all aircraft for this organization
$bookings = DB::table('bookings')->where('org', $org_id)->get();
// Grid date info
$grid_date = $date->isoFormat('YYYY-MM-DD');
return view('schedule/schedule')->with(compact('raw_date','schedule_date', 'days', 'aircraft','bookings','grid_date'));
}
Then, they are presented with a form where they finish the booking if they are rerouted correctly. The view for the main schedule grid consists of a foreach loop to break the collection of aircraft into individual records:
#foreach ($aircraft as $aircraft)
<tr>
<th scope="row" data-toggle="tooltip" data-placement="right" title="{{$aircraft->type}}">{{ $aircraft->aircraft_n }}</th>
<td class="sh-td"><div class="td-clickable"></div></td>
... this continues for all times until 830pm (each gets it's own td)
PHP -> CODEIGNITER
Tables
- users [customers information]
- sms gateway [sms gateway configuration apiKey, sender code]
- sms template [ pre-approved dynamic templates eg, visitor to office]
Form
- fullname [input field] = SHREYAS
- Phone [input field] = 123456789
- service [dynamic dropdowm from services table] = ABC
- remark = QWERTY
** Form Submitted **
1) $post = $this->input->post(); [PHP codeigniter syntax for controller]
2) $data[] = $post[]; [all the form data is stored in array called data]
3) inserted data to db [visitors]
** sending sms to visitor **
1) $users_id = $this->session->userdata('users_id'); [PHP codeigniter syntax for getting users_id from session]
2) get_sms_gateway_details [of customer where users_id = $users_id]
3) $sms_content[users_id,sms_gateway_id,TITLE] // getting the template with users_id sms_gateway_id and title("visitors")
4) $sms_content is added in foreach loop to get visitors template message as string in $message
******** Problem I am facing ********
5) $message = Dear '.$post['fullname'],', Your request for '.$service_name.' is in progress. Our team will get back to you soon. Have a Great Day !!!. mob: +91
0000000000.
("this is the sms template used for visitors in which $post['fullname'] should be SHREYAS and $service_name = ABC" which was submitted in form above)
6) Final output required = Dear SHREYAS, Your request for ABC is in progress. Our team will get back to you soon. Have a Great Day !!!. mob: +91 0000000000.
7) later this will be added to sms_data_array[] and will be sent using PHP CRUL method
I have two tables: steps and flows.
steps has many flows.
steps has relative_time (string) column.
flows has active_on (nullable, timestamp) column.
Steps relative_time stores relative formats and their values looks like: "+1 year", "+2 days", "+30 days", etc.
Flows active_on is set when a flow gets activated by user and it looks like: "2017-12-30 00:00:00".
Every time I want to know when a flow will expire, I select it from database and, in PHP (Laravel, Carbon), I execute:
/**
* #return null|Carbon
*/
public function getExpiresAtAttribute()
{
if (!$this->active_on) {
return null;
}
// Access the relative time for step (for example: "+3 days").
$relativeTime = $this->step->relative_time;
// Adds the limit time to the activation date,
// turning it possible to check when the current flow
// will "expires".
return $this->active_on->modify($relativeTime);
}
Problem
It's easy to check expires at value in PHP. The problem is that now I need to select only flows that are "expired" directly from database and I don't know if it is possible by using this approach. How can I achieve this?
You could store in relative_time the number of days, instead of the php date interval. This way you can query:
SELECT * FROM flows, steps WHERE flows.step_id = step.id AND NOW() > ADDDATE(flows.active_on, steps.relative_time)
This way you get all the flows expired.
No need to change database structure actually. You could create a migration to transform relative_time from dateinterval to number of days (is a string field).
foreach (Steps::all() as $step) {
$step->update([
'relative_time' => strtotime($step->relative_time,0)/(3600*24);
]);
}
Then you can adjust the getExpiresAtAttribute:
/**
* #return null|Carbon
*/
public function getExpiresAtAttribute()
{
if (!$this->active_on) {
return null;
}
// Access the relative time for step (for example: "+3 days").
$relativeTime = $this->step->relative_time;
// Adds the limit time to the activation date,
// turning it possible to check when the current flow
// will "expires".
return $this->active_on->modify("+$relativeTime days");
}
I'm trying to build voting system for my web page (Laravel 5). Now, any user can vote multiple times, I want to fix it.
Here is my code in php:
public function addVote()
{
$bikepoint = $this->bikepoint->find($id);
$userid = \Sentry::getUser()->id;
$votesid = \DB::table('bikepoints')->select('votesuid')->where('votesuid', 'LIKE' , $userid)->get();
if (...) {
$bikepoint->votes = $bikepoint->votes + 1;
$bikepoint->votesuid = $bikepoint->votesuid . $userid . '; ';
echo 'Success!';
}
else {
echo 'Fail!';
}
$bikepoint->save();
}
My DB table:
id title votes votesuid
1 point1 2 93; 22;
2 point2 3 92; 28; 47;
3 point3 45 ...
4 point4 32 ...
5 point5 12 ...
So when user click the "Add vote" button, a function adds its ID to the votesuid field and one vote to the votes field.
I want to check if the user has already voted by checking if his ID is placed in the votesuid field. And, if so, the user cannot vote anymore.
For example, users with IDs 92, 28 and 47 should not be able to vote another time.
As suggested by others in the comments, yes, you do need to change your system so that each vote has it's own record on a table.
So create a Votes table and a Laravel model class for it, and give your Users model class a hasMany() relationship to Votes.
That's actually not too much work, is it?
But now then the solution to your question becomes trivially easy -- ie:
$votes = Sentry::getUser()->votes;
As things stand, you would need to do sub-string LIKE queries, which are much harder to write, and will also give you major performance problems when your DB starts getting bigger, so yes, you definitely need to be refactoring it now.
I am new to Grocery CRUD.
I am impressed by how much time saver this library is and i want to thank all great developers who worked on this project.
i have a small problem with showing the date field in the table. when i press the edit button , it's shown in the edit and view pages.
but it doesn't appear in the table.
Even if i create the record myself from the add record button, it's saved successfully but not shown in the table.
i have checked many things like the default format of the date in the library.
$config['grocery_crud_date_format'] = 'sql-date';
I tried different web browsers
this is my table and how i update the date and save it to the DB:
$datestring = "%Y-%m-%d";
$time = time();
$data = array(
'Attendence_date_daily' => mdate($datestring, $time),
'Check_in_time' => null,
'Check_out_time' => null,
'Attendence_status' => null,
'Employee_comment' =>null,
'Deducted_today' => 0,
'user_id' => $row->id
);
this is how i created the table
public function edit_daily_record()
{
$crud = new grocery_CRUD();
$crud->columns('daily_record_id','Attendance_date_daily','Check_in_time','Check_out_time','Attendence_status','Employee_comment','Deducted_Today','user_id');
$crud->set_table('daily_attendence_record');
$crud->display_as('Attendance_date_daily','Date')
->display_as('user_id','Employee');
$crud->set_subject('daily record');
$crud->set_relation('user_id','users','username');
$output = $crud->render();
$this->_example_output($output);
}
where 'Attendance_date_daily' is of type date in mysql DB . All fields are shown correctly except this date
'daily_record_id' is auto increment PK
'user_id' is a FK
can you please help me with this problem?
image 1
image 2
I solved this with the help of Mr. Paul Savostin
one of the Advanced members in Grocery CRUD Advance members.
the issue is a simple typo.
the name of the filed in the database is different than the controller by one letter.
this shows how can a letter change the whole code!