473,695 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python,mysql question

I have a search page & the reults for the search are fetched from the
I want that on the results page only first 25 results are shown & a
link "next 25 results" be shown.Same for the 2nd result page.
How do I do this?
Jul 18 '05 #1
3 1507
On 18 Mar 2004 05:09:00 -0800, james blair wrote:
I have a search page & the reults for the search are fetched from the
I want that on the results page only first 25 results are shown & a
link "next 25 results" be shown.Same for the 2nd result page.
How do I do this?

What have you tried? What were the outcomes of your attempts?

\ "Truth would quickly cease to become stranger than fiction, |
`\ once we got as used to it." -- Henry L. Mencken |
_o__) |
Ben Finney <http://bignose.squidly .org/>
Jul 18 '05 #2
Il gio, 2004-03-18 alle 14:09, james blair ha scritto:
I have a search page & the reults for the search are fetched from the
I want that on the results page only first 25 results are shown & a
link "next 25 results" be shown.Same for the 2nd result page.
How do I do this?

here is how I ( a python newbie :) ) do it, using mod_python for apache
and ... sorry for the last req.write that is quite hard to read

def search(req,star t="0",itemsperp age="5"):
req.write("<htm l>" etc etc... )
start=int(start )
itemsperpage=in t(itemsperpage)
curs1=db1.curso r()
curs1.execute(" ""SELECT ... FROM ... WHERE
ORDER BY ... LIMIT %s,%s
;""",(start,ite msperpage+1) )
for i in xrange(itemsper page):
row=curs1.fetch one()
if row!=None:
req.write(repr( row)) # change to something more useful
row=curs1.fetch one() # any row left for next page?
'<a href="/script.py/search?itemsper page='+str(item sperpage)+
'&amp;start='+s tr(start-itemsperpage)+' ">Previous</a> ')
*(start-itemsperpage>=0 )
+('<a href="/script.py/search?itemsper page='+str(item sperpage)
+'&amp;start='+ str(start+items perpage)+'">Nex t</a>')*

the last req.write(..) could be rewritten as

if (start-itemsperpage>=0 ):
req.write('<a href="/script.py/search?itemsper page='+str(item sperpage)+
'&amp;start='+s tr(start-itemsperpage)+' ">Previous</a> ')
if row!=None:
#first line of "next page" is empty, so no "next page" is needed
req.write('<a href="/script.py/search?itemsper page='+str(item sperpage)
+'&amp;start='+ str(start+items perpage)+'">Nex t</a>')

which is far more readable.

Any comment is appreciated, it's one of the first python script I wrote.
Linux User #153639 RoLug Member - http://rovigo.linux.it
GnuPG id:E88F9363 keyserver.linux .it
Jabber id:ca**@jabber. linux.it
Jul 18 '05 #3
james blair wrote:
I have a search page & the reults for the search are fetched from the
database. so you are doing web stuff?
I want that on the results page only first 25 results are shown & a
link "next 25 results" be shown.Same for the 2nd result page.
How do I do this?

basically you re-run the mysql query at each page request.
check mysql's limit and offset keywords:
<http://www.mysql.com/documentation/mysql/bychapter/manual_SQL_Synt ax.html#SELECT>

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://www.deelan.com/> .
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Zunbeltz Izaola | last post by:
Hi! I am planning a program and I need some advice about what tool to use. Basically my program will deal with a object A. A is a list like object with same attributtes and a list of objects B. B is also a list like object with attributes and a list of object C. class A: Name = ""
by: Dave Ekhaus | last post by:
hi my news carrier didn't have any mysql specific news groups - so apologize in advance if this isn't exactly the proper group for these question(s) ... anyway - i'm trying to figure out how to perform a bulk insert of data from a text file into a table in a mysql database from the python programming language. i have lots of experience with ms sql server and there we used bcp and then dts packages, but i can't seem to find the
by: Christopher Kang | last post by:
I had a question about python and mysql, but I want to first thank those who taught me about the factory method, it was exactly what I needed. Anyway, I have a problem where I am pulling floating point values out of mysql and into python using the MYSQLdb module. However, the values seem to be altered a little when I store them in python.. Because the decimal places are off, I am unable to use the values that
by: Aquarius | last post by:
I appologize in advance for this strange (and possibly stupid) question. I want to know if there is a way to interface a MySQL database without Python-MySQL or without installing anything that has C files that need to be compiled. The reason for this, is that I want to develop a certain web application, but my hosting provider (!#@$!@#%) isn't very eager to supply Python-MySQL (or any modules to python). Is there an alternative approach...
by: John Nagle | last post by:
I've been installing Python and its supporting packages on a dedicated server with Fedora Core 6 for about a day now. This is a standard dedicated rackmount server in a colocation facility, controlled via Plesk control panel, and turned over to me with Fedora Core 6 in an empty state. This is the standard way you get a server in a colo today. Bringing Python up in this completely clean environment is a huge hassle, and it doesn't...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.