+ Reply to Thread
Results 1 to 5 of 5

Thread: row_number SQL Help

  1. #1
    tillabong is offline x10Hosting Member tillabong is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    60

    row_number SQL Help

    Hi ive been trying to fix this but i keep getting the error
    mysql_fetch_array(): supplied argument is not a valid MySQL result resource. can someone help me with this? please.

    when i remove the Row_Number() OVER (ORDER BY shopname ASC) AS rownumber part the script works just fine. im trying the number my results when they display.



    $query = "SELECT * , Row_Number() OVER (ORDER BY shopname ASC) AS rownumber
    FROM table
    ORDER BY shopname";
    $result = mysql_query($query);
    while($data = mysql_fetch_array($result))

    thank you very much.

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: row_number SQL Help

    I'm not that good with sql, but there must be an error in there.
    Try using the function mysql_error() after you executed the query, it should give some details on the error.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  3. #3
    tillabong is offline x10Hosting Member tillabong is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    60

    Re: row_number SQL Help

    thanks. i've tried mysql_error() but it still returns the same error message.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: row_number SQL Help

    MySQL doesn't have a ROW_NUMBER function. Generally speaking, the concept of a row number doesn't apply in relational databases. You can keep a count of rows as you access them in PHP, if you wish. Better yet, display the list as an <ol> and the browser will number the items for you.

    A bit of advice: selecting all columns (SELECT *) is generally a bad idea because it introduces a dependence on the order of columns and pulls unnecessary information from the database, which uses resources you don't need to use. The result is brittle code and requires more work, should you change the order of the columns or insert additional columns into the table. Also, the code that handles the response depends on specific columns; selecting all columns makes this dependency implicit rather than explicit. Better to explicitly name the columns you need in the SELECT statement.
    Last edited by misson; 01-24-2010 at 02:34 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    tillabong is offline x10Hosting Member tillabong is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    60

    Re: row_number SQL Help

    thank you very very much for the advice.

+ Reply to Thread

Similar Threads

  1. SQL Import
    By lemon-tree in forum Free Hosting
    Replies: 1
    Last Post: 12-14-2009, 05:53 PM
  2. SQL Azure with ASP Dot Net
    By zegnhabi in forum Tutorials
    Replies: 0
    Last Post: 12-13-2009, 04:32 PM
  3. Microsoft SQL Server (a rant)
    By merrillmck in forum Programming Help
    Replies: 6
    Last Post: 07-08-2009, 10:43 AM
  4. sql database does not restore
    By softwork in forum Free Hosting
    Replies: 3
    Last Post: 05-20-2008, 06:47 AM
  5. Sql?
    By SLIForum in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 12-03-2007, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers