Re: Newbie Question: MySQL Rows
From: Ehtor (nomail_at_nomail.com)
Date: 10/03/04
- Next message: Diethard Wehn: "Encryption of mail addresses"
- Previous message: J.O. Aho: "Re: php blog problems"
- In reply to: Invalid: "Newbie Question: MySQL Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 03 Oct 2004 14:02:59 GMT
You probably need to review the mysql functions in the PHP documentation.
The number of rows returned by a SELECT query is available using the
mysql_num_rows() function. Pretty straight forward.
As for "re-arranging" the output, consider adding a column that allows you
to pull ad records based on priority --- maybe an integer called
"ad_priority"... then you can query based on this (and use order by to
arrange your result set appropriately).
As for traversing a record set by auto_increment value...
It kinda depends on which version of MYSQL you are using. Versions prior
to 4.1 (I think) do not support subqueries (which is one of the ways to do
this). For example, say your current ad number is 12 and you want to find
the PREVIOUS ad number. This number will be returned by the query:
select max(ad_number) from advertisements where ad_number < 12
You could put this in a sub-query (if supported) like this:
select * from advertisements where ad_number = (select max(ad_number) from
advertisements where ad_number < 12)
If you're using a version that does not support sub-queries and you feel a
burning need to do it in one step, you could still do it, but you'd likely
need to pick off the record you need:
First record from this query returns previous ad:
select * from advertisements where ad_number < 12 order by ad_number DESC
First record from this query returns next ad:
select * from advertisements where ad_number > 12 order by ad_number ASC
Hope this helps.
"Invalid" <lnvalid@sympatico.ca> wrote in
news:Aqn7d.24251$MD5.1336107@news20.bellglobal.com:
> Hi there, I'm new to both PHP and MySQL... I created a strip for my
> website, where banner ads can be added. Each banner is stored in the
> database as a new row. I want to add the option to rearrange those
> rows, move banners up and down in sequence... I can't seem to find a
> simple (or complicated) way to do this... I can't even find a way to
> find the number of the selected row.. I do have a adNum column in the
> table however, which auto_increment's with every new row added, so I
> can select the row I want using that... I can also sort using it, with
> "ORDER BY adNum ASC" in my query.. But even using the adNum column, I
> can't find a way to select the row previous or following the one I
> want to edit... I cant just say adNum-1, because the rows are not in
> total order. I have adNum 3, 5, 14, 17, etc... Can anyone help me?
>
> Thanks!
> ------=_NextPart_000_0020_01C4A7FC.EF5B1EE0
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
> <META content="MSHTML 6.00.2800.1400" name=GENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=#ffffff>
> <DIV><FONT face=Arial size=2>
> <DIV><FONT face=Arial size=2>Hi there, I'm new to both PHP and
> MySQL... I created a strip for my website, where banner ads can
> be added. Each banner is stored in the database as a new row. I
> want to add the option to rearrange those rows, move banners up and
> down in sequence... I can't seem to find a simple (or complicated) way
> to do this... I can't even find a way to find the number of the
> selected row.. I do have a adNum column in the table
> however, which auto_increment's with every new row added, so I
> can select the row I want using that... I can also sort using
> it, with "ORDER BY adNum ASC" in my query.. But even using
> the adNum column, I can't find a way to select the row previous or
> following the one I want to edit... I cant just say adNum-1, because
> the rows are not in total order. I have adNum 3, 5, 14, 17, etc... Can
> anyone help me?</FONT></DIV> <DIV><FONT face=Arial
> size=2></FONT> </DIV> <DIV><FONT face=Arial
> size=2>Thanks!</FONT></DIV></FONT></DIV></BODY></HTML>
>
> ------=_NextPart_000_0020_01C4A7FC.EF5B1EE0--
- Next message: Diethard Wehn: "Encryption of mail addresses"
- Previous message: J.O. Aho: "Re: php blog problems"
- In reply to: Invalid: "Newbie Question: MySQL Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|