Re: Newbie Question: MySQL Rows

From: Ehtor (nomail_at_nomail.com)
Date: 10/03/04


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...&nbsp;I created a strip for my website, where banner ads can
> be added.&nbsp;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,&nbsp;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,&nbsp;with "ORDER BY adNum ASC" in my query..&nbsp;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>&nbsp;</DIV> <DIV><FONT face=Arial
> size=2>Thanks!</FONT></DIV></FONT></DIV></BODY></HTML>
>
> ------=_NextPart_000_0020_01C4A7FC.EF5B1EE0--



Relevant Pages

  • Re: Parameter help
    ... You didn't post the SQL statement your query is using, ... If your query now has a parameter prompt something like: ... [Enter Banner title] ... you might be able to change that Selection Criterion to something like: ...
    (microsoft.public.access.queries)
  • Re: Can a divs width expand to fit contents width?
    ... Dave Rado wrote: ... and of course it must wrap. ... You seem to have forgotten about older query and started talking about ... second banner on the page, which is a table, if you add more text to ...
    (comp.infosystems.www.authoring.stylesheets)
  • RE: IF function in Query
    ... KARL DEWEY ... in an Excel worksheet to list the Banner name by searching for a name within ... My plan was to export the query into an Excel sheet, ...
    (microsoft.public.access.queries)
  • IF function in Query
    ... Can an IF function be used in a Query? ... in an Excel worksheet to list the Banner name by searching for a name within ... but it exceeds the maximum number of lines allowed. ...
    (microsoft.public.access.queries)
  • Report/Query for all advertisments of a specific user
    ... I want to create a query to find all the advertisements a specific user gets ... CollectionID from the view 'v_Advertisement' it is possible to retrieve the ...
    (microsoft.public.sms.misc)