show registration number on student registration page - php

i work on a registration page in php mysql with yii. i created a registration form and create a auto increment registration number from table student_info in column student_id.when we register any student then it auto assign a registration number .but now i use registration form with above code ,which show a text box , but i want display registration number on that place.my code is ...
<div class="row">
<div class="row-left">
<?php echo $form->labelEx($info,'student_id'); ?>
<?php echo $form->textField($info,'student_id'); ?>
<span class="status"> </span>
</div>
on the place of textfield , what i use , by which it display my auto incement registration number. i am new please help me ?please anyone

Put this code into your model:
public function init() {
if ($this->isNewRecord) {
$this->student_id = $this->generate_code();
}
}
$this->generate_code() - this is your function to generate the registration number :)
Then in your view-template use something like this:
<? echo $info->student_id; ?>

Since the user registration number is a very important one and you probably need it all the time, I would recommend to store it at session when the user login. To do so, you only need the following line at your login component:
$this->setState('registration_number', $user->student_id);
Replace "$user" with the model you use to login.
Then, if you need to display this number just add:
echo Yii::app()->user->registration_number
in the place you want it to be displayed.

Related

attempting to modify a field in codeigniter application db table but know how to identify the table

I am beginner in code igniter php framework. Today I have a task to modify existing code and somehow I am lost in the middle of the line on attempting to located a database table. This is the controller snippet that renders the view
..........
$data["all_types"] = $this->data_model->get_data("all_types",300,"Asc");
$this->load->view("preview_brands",$data);
...........
when the view is loaded I am iterating through the in the view to load data as shown
<div class="decoration"></div>
<?php foreach($all_types as $item): ?>
<div style="display:block;color:#000;">
<a style="font-size:17px;margin:15px 2px;font-family:Cgothic;"
href="<?php echo site_url()."...../..../".$item["id"]; ?>"
class="scale-hover"
title="<?php echo str_replace("_"," ",$item["name"]);?>">
<strong><?php echo str_replace("_"," ",$item["name"]);?></strong>
</a>
</div>
<?php endforeach; ?>
this is the model snippet code as shown
function get_data($db,$i,$order)
{
$this->db->order_by("name",$order);
$this->db->where('consent',"yes");
$query=$this->db->get($db);
return $query->result_array();
}
My challenge is how can I locate or identify the database table the above model is pointing to to fetch data. Hoping someone assists me
all_types is your table name.
$this->db->get($your_table name), get method take table name as a parameter.
Get Method Documentation
If more help needed I'm happy to help.
Happy Coding.
From your model code:
$query=$this->db->get($db);
This means $db is the table name. Looking at your controller code which calls the model function:
$data["all_types"] = $this->data_model->get_data("all_types",300,"Asc");
I can say that all_types is the name of the table.

How to pass data from anchor tag in laravel?

I currently have a form in laravel on whos submission the following methods run:
public function validateSave() {
$qualitycheck = new QualityCheck();
$qualitycheck['site-name'] = Request::input('site-name');
$qualitycheck['favicon'] = Request::has('favicon');
$qualitycheck['title'] = Request::has('title');
$qualitycheck['image-optimization'] = Request::has('image-optimization');
$qualitycheck->save();
Session::flash('quality-data', $qualitycheck);
return redirect('/');
}
So i have the below line that passes the data to the next page:
Session::flash('quality-data', $qualitycheck);
But what i would really want to do is, when the form is submitted, i would really just want to show a link on the next page , which will be coded like so:
#if(Session::has('quality-data'))
Submited Quality Check
#endif
Now on click on the link , i would like to show a view with all the data that the user submitted in the form , How do i do this ? I.E. How do i pass the data form from the <a> to the view that will show up when clicked on the <a> ??
So just to put things into perspective, this is how it works now:
STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: Data user submits is shown on this page.
How i want it to work is:
STEP-1 :: User submits form , data is flashed to next page.
STEP-2 :: A link is shown to the user(Only if user clicks on the link we move to the next step).
STEP-3 :: Data user submited in first step is shown on this page.
Next time you code, please follow the below coding practices.
Prefer using create() function of model.
Put all your request data that is to be used in one variable (like $input)
Prefer using route names like route('route.name') instead of strings inside redirection() function.
Please replace your function with
public function validateSave() {
$inputs = [
'site-name' => request()->get('site_name'),
'favicon' => request()->has('facvicon'),
'title' => request()->has('title'),
'image-optimization' => request()->has('image-optimization')
]);
$qualityCheck = QualityCheck::create($inputs);
$flashMessage = '<a href=' . route('quality.check.show', $qualityCheck) . '>Submitted Quality Check</a>'
Session::flash('quality-data', $flashMessage);
return redirect(route('home.index'));
}
And ensure you have something like this in your routes file.
Route::get('quality-check/{id}', 'QualityCheckController')->name('quality.check.show');
Let me know if something doesn't work...
try this one.
<a href="{{url('routename')}}">

How to get selected from jmultiselect2side in yii and display in a new page

I'm new to yii and I don't understand the extensions much
but I used this extension called jmultiselect2side because I'm trying to make a site where users could reserve stuff like apparatuses in the lab
Anyway, I need a code that would get the Selected Items and then display them in another page for viewing purposes
I haven't put anything in the controller but the name of my controller and model is Apparatus
Here is my view:
<?php
$model= Apparatus::model()->findByAttributes(array('ApparatusCode'=>'1'));
// complete user list to be shown at multiselect order by ApparatusCode
$Apparatus= Apparatus::model()->findAll(
array('order' => 'ApparatusCode'));
?>
<center>
<?php
$this- >widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
'model'=>$model,
'attribute'=>'ApparatusName', //selected items
'labelsx'=>'Available',
'labeldx'=>'Selected',
'moveOptions'=>false,
'autoSort'=>'true',
'search'=>'Search:',
'list'=>CHtml::listData( // available items
$Apparatus,
'ApparatusCode',
'ApparatusName'),
));
?>
please help as soon as possible :/
put all above elements in a form. Set action for the form. Submit the form then the action in which you are handling this submit request, you can write there
if(isset($_POST))
{
foreach($_POST['Apparatus']['ApparatusName'] as $name)
{
do what ever you want
}
}
$name will represent the each selected item

How to edit user form which had dropdown in codeIgniter?

I have users in the admin module. Against each user row I have edit user option. when admin clicks on that edit user option. He will see edit user form with fields. Out of those form fields one of the filed is drop down which is user profile type.
Now from the database I will get an array of all the details about that user which admin editing called $user_details. But from the database what I will get is user profile id in the field name like this $user_details['profile_id'];
At the same time I had another array which maps profile id's with profile names. That is called as $profile
Now when admin clicks on edit first he needs to see the profile_name of that user before editing. And when he clicks on that drop down he needs to see what are the profile types available to changes.
I am not able to get idea how to do this.
Bu this is what I have tried
<label>Profile: <?php echo form_error('profile'); ?></label> <br />
<select class="styled" name="profile_id">
<?php foreach($profiles as $profile) { ?>
<option value="<?php echo $profile['profile_id']?>" <?php if ( set_value('profile_id') == $user_details['profile_id']) {?>selected="selected"<? } ?>><?php echo $profile['profile_name']?></option>
<?php } ?>
</select>
It is easy if you are going to use Codeigniter's builtin form_dropdown
$options = array();
foreach($profiles as $profile){
$options[$profile['id']] = $profile['profile_name'];
}
$select = isset($user_details['profile_id']) ? $user_details['profile_id'] : 0;
form_dropdown('profile_id',$options , $select , 'class= "styled" ');
It takes 4 parameters. 3rd and 4th are optional. 3rd is the key you want to be selected and 4th is used for other attributes like class , id etc. The first one is name and 2nd one is array.
For details see the Form Dropdown User guide.

Codeigniter - trying to pass data for the user from the DB?

Following from this tutorial..
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-6-login/
I have successfully implemented and created/logged in users..
I have now added an additional input for the signup form;
signup_form.php
<?php echo form_input('sport', set_value('sport', 'sport?)')); ?>
In the logged in area I would like it to display the users data for 'sport'
logged_in_area
I like <?php echo $this->session->userdata('sport'); ?>
In membership_model I have also added
'sport' => $this->input->post('sport'), in function create_member()
The data inserts into the database correctly! :)
It is just when they are logged in it doesn't pull that user information from the 'sport' column. What have I done wrong? (I have this eerie feeling it's the echo in the logged_in_area)
Thanks!
You have to manually set the value for $this->session->userdata('sport');
I think it is suited for you to add it with with something like
$this->session->set_userdata('sport', $this->input->post('sport') );
in
function create_member()
just after doing the insert into DB

Categories