I have connected to one MySql table to fetch 1000 records that need to be displayed using JSP. I want to split my table into multiple tables (of size 50) which can be viewed by using next button on jsp page. How can I implement it?
String sql = "select * from people";
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet result = statement.executeQuery();
while(result.next()) { // here i get 1000 records. how can i display these records on mulitple jsp pages?
// ... get column values from this record
}
Above gives 1000 records and I use a PreparedStatement.
Assuming you can fetch the complete table in JSP.
Just add one more param to the function returning the ROWS COUNTER
Add COUNTER to LIMIT clause in your QUERY.
Now you need to keep track of the COUNTER so Update the URL on click on next as
First Click - URL?pageCOUNTER=1
Second Click - URL?pageCOUNTER=2
Fetch the pageCOUNTER varaible from URL and pass it to your function as COUNTER
And so on. Keep getting you result.
OR USE JAVASCRIPT TABLE - http://www.datatables.net/
Related
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
With App inventor 2 I got the ROWID number and I put the value in the "riga" variable. The Query is executing once and it writes correctely the data in the fusion table row, but then the query keeps on executing many times and the app writes hundred of times "400 Bad Request: Rowid must contains only numerals and underscores".
Why is it happening?
you created an endless loop
you should add a variable let's name it action, set it to rowid while you get the rowid and set it to update while you do the update
in the fusiontable controls got result event you need an if statement like this (pseudocode)
if action = "rowid"
then extract the received rowid and do the update
else print "update was successful"
btw. to get the rowid, you better split the result at \n (new line) to convert it into a list with 2 items, then select the second item to get the row id
String q="insert into ChooseRandom (Qid,Question,Option1,Option2,Option3,Option4,Answer,isImage,ImageQuestion) SELECT Qid,Question,Option1,Option2,Option3,Option4,Answer,isImage,ImageQuestion FROM model ORDER BY RAND()";
I am using the above query for randomize sql result set and insert the randomized data's into new table. this works good but this query randomize the rows in table. i need to randomize the rows as well as column and insert into new table.
How can i do this can any one help me to fix this
Thanks in advance
compare to image 1 and image 2 options are randomized as well as rows are randomized.
how can i achieve this
Actually my problem is i can randomize my database table data using rand() function in mysql. but i need to shuffle my column's all so.
i solve my issue but using array list in java i just add the column values to list and than i shuffle the list than i get the list item one by one the code what i used is given bellow .
List<String> lst = new ArrayList<String>();
op1=rs.getString("Option1");
op2=rs.getString("Option2");
op3=rs.getString("Option3");
op4=rs.getString("Option4");
lst.add(op1);
lst.add(op2);
lst.add(op3);
lst.add(op4);
Collections.shuffle(lst);
op1=lst.get(0);
op2=lst.get(1);
op3=lst.get(2);
op4=lst.get(3);
than i used this values to what ever i want.
If I have the following query, is it possible to be able to run a function inside? Let's say I want to add WHERE zip_code = user_distance(zip_code)?
I want to take data from each row and run it through a function before actually selecting it.
#posts = Listing.find_by_sql(["SELECT * FROM listings WHERE industry = ? && ", current_user.industry])
If you are mainly looking to get this working and not worrying so much about performance (because going straight to the SQL is faster than going through ActiveRecord) then you could do:
listings = []
Listing.all.each do |listing|
listings << listing if user_distance(listing.zip_code)
end
So, it will go through each listing and add it to that array if the user_distance method returns true (or however it is set up).
Another thing you could do is set up a stored procedure ("stored proc") on your database that takes in a zip code and returns what it is you want (i.e, does the same thing as user_distance), and that user defined variable max_distance could be in a database table so it's accessible to your stored procedure. Then you could call that stored proc from the SQL and still be able to pass in the zip_code of each row.
I am trying to return a list of results, where the joined table has multiple values, but I only want one image value for each listing value.
The SQL is like this:
SELECT
Title, Comments, ThumbNailPath, thumbheight, thumbwidth
FROM
Listings as l INNER JOIN
Images as i ON l.id = i.ListingId
WHERE
(i.ImageSlot = 1)
My repository class looks something like this: (db.GetListings() is the stored procedure method I added to the methods section of the .dbml file)
private ListingModelDataContext db = new ListingModelDataContext();
public IQueryable FindAllListings()
{
//return all listings and first associated thumbnail
return db.GetListings();
}
When I try calling from stored procedure I get error
'System.Data.Linq.ISingleResult' to 'System.Linq.IQueryable'. An
explicit conversion exists (are you
missing a cast?)
I am looking for guidance on how I might either call that sql statement from a stored procedure or simply structure the linq to return that value.
My preference is to know how to write the LINQ statement. To clarify, I have a one to many relationship on the images table. (multiple images per listing) I only want to return the first image though on a search results page. So, for each listing return image value where imageSlot = 1.
I should get a list of rows showing the listing values joined to the image values. I get the correct results in SQL but not sure how to write it in linq or how to call the sproc correctly.
Thanks in advance and sorry if this is hard to read.
Are you trying to do soemthing like :
var result = (stored proc).Single()
or
var result = (stored proc).SingleOrDefault()
?? This would break if there are indeed multiple elements coming back - instead use the .First() or .FirstOrDefault() methods:
var result = (stored proc).FirstOfDefault();
returns the first entry from the stored proc, or null if the stored proc returns no values at all.
Marc