Storing inputs in mysql array - mysql

I got a text field for entering the new categories and submit with ajax ..
My script is working but everytime i submit new category mysql is creating one row to hold single category name .
I would like to create something like this eachtime when i add a new category the same single row should get updated
Id. User id. Category
1. 23. Personal , shopping , others +
So everytime i update a category name the row should be updated with the comma separated value . And also i would like to fetch the result in a select box

Related

Joomla 3x - Profile Fields

I have added a checkbox to the user profile and need to know how to get a list of all the user email addresses where they have checked the checkbox. I would like to just run a SQL query, but can't see where the value is stored.
All the profile data is stored in #__user_profiles table. To retrieve the data from the profile table you can perform this query
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "checkbox.".
// Order it by the ordering field.
$query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value')));
$query->from($db->quoteName('#__user_profiles'));
$query->where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'checkbox.%\''));
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
You will get object list of all those users who clicked on your checkbox. Remember to use the profile_key name in place of checkbox
Ok - I have now managed to answer my own question (I took an export of the database as a SQL file, ticked the checkbox as a test user, made another export and then compared the files to see what had changed).
The values are stored in the jos_fields_values table. The query below assumes that there is only one checkbox - if you have more than one you will need to query the field_id as well, Replace xxx with the prefix of your Joomla installation.
SELECT email FROM xxx_users INNER JOIN xxx_fields_values ON xxx_users.ID=xxx_fields_values.item_id

how to get data from multiple selection server report

2nd dropdown is multiselect. Working fine when i'm selection only one poll when when selecting more than one poll getting error "incorrect syntax near ',' "
My data set query is
SELECT tblPS_Question.Question
,tblPS_PollSurveyMaster.PollSurveyID
,tblPS_PollSurveyMaster.PollSurveyName
FROM tblPS_Question
INNER JOIN tblPS_PollSurveyMaster ON tblPS_Question.PollSurveyID = tblPS_PollSurveyMaster.PollSurveyID
WHERE (tblPS_PollSurveyMaster.IsActive = 1)
AND (tblPS_PollSurveyMaster.PollSurveyName = #PollSurveyName)
I guess #PollSurveyName is taking only one poll name how to pass multiple name so that based on passed names Questions dropdown will get populated.
Assuming that #PollSurveyName is the name of the 1st parameter then just change your last line to
AND (tblPS_PollSurveyMaster.PollSurveyName IN(#PollSurveyName))

Create a double join query using Rails Admin

I am trying to create a form using Rails Admin, version 4.0.0. For this form I have tables called items, locations, cities and item_in_city. Tables are related in the following ways:
items table has a column called location which is array or location ids where item is present
location table has a column called city_id which connects it to city table
there is item_in_city table which has item_id and its corresponding list of city_id
Now, I want to create a form using Rails Admin, where I can give option to add a new item. While adding this new item I want to give an option to select (multiple) cities and corresponding to cities I want to give list of locations which can be selected.
I figured out the solution, So I thought of posting it as it can be useful to others. Combination of city name and location can be posted by defining an enum method in the following way
def location_enum
Location.all.collect {|l| [ l.city.name + ' ' + l.name, l.id] }.sort
end

Inserting multiple selected dropdown values into a single column

Iam having a form which contaings of name,id etc..in this form iam getting dropdown from the same table only some ids here iam selecting multiple values and that should be inserted into db but only one value is inserting into the table remaining is not inserting can any one help me regarding this.
Model:
$data=array(
'first_name'=>$this->input->post('first_name'),
'exam_id'=>$this->input->post('exam_id'),
);
$this->db->insert('table',$data);
This is my dropdown
$this->table = 'table';
$exam = $this->dropdown('exam_id','examr_id');
return $exam;
This is my view:
$exam['']='--Select --';
$exam_id="id='exam_id' ";
if($this->input->post('exam_id')) $selected=$this->input->post('exam_id');else $selected='';
echo form_multiselect('exam_id',$exam,$selected,$exam_id);?>
any one help me it will be more helpfull for me
When you select multiple values and check that selected value pass in your url using GET or POST method. And than split your requested data using implode function. and save into database.

how to get next and previous record id using linq to sql?

var product = db.Products.First(p => p.Id == 5);
In the product detail show page, show.aspx?Id=5, I want to get the previous and next product link.
How can I do that?
Should I connect to the database three times to get the current product and previous id and next id for generate links?
I have solved this problem by returning two entities.