SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is worng with this query?

    $query = "select max(dive_id) from divefile" ;
    $row = mysql_query($query);
    I need to assign the output of max(dive_id) to $new_id,

    if I say $new_id = $row[max(dive_id)];
    system return me with Wrong parameter count for max() .
    how should i assign to output to $new_id, many thanks.

  2. #2
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    North Richmond
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure on this, but try $new_id = $row[0];

    See how you go with that.
    Regards,
    BJ Duncan

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Location
    Perth, Australia
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try assigning the selected column to a new column name.
    also, you missed out using the mysql_fetch_array() function
    e.g.
    PHP Code:
    $query "select max(dive_id) as max_dive_id from divefile" ;
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    $new_id $row['max_dive_id']; 

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The contents of the square brackets should also be in quotes. Two problems. At the moment, php is running the PHP max function(1) on an undefined constant(2 -- dive_id). Using quotes inside the square brackets should solve the problem.

    You should also fetch results of a query in this form:

    Code PHP:
    $result = mysql_query($query) or die (mysql_error($link));
    $row = mysql_fetch_assoc($result);
    $new_id = $row['max(dive_id)'];

    rodp's solution is probably more ideal.

  5. #5
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT
    	MAX(dive_id) AS dive_id
    FROM
    	divefile
    ...And then you can use your ['dive_id']; as rodp said.
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •