0

Hello,
I have this snippet of code to echo out the "mailer_id" with the largest value -

<?php 
$result = mysql_query('SELECT MAX(mailer_id) FROM mailer_directory')or exit(mysql_error()); 
echo 'the max mailer_id is ' . mysql_result($result, 0); ?>

My question is how do I echo out the corresponding email value for that field ?

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Bob Arctor
Featured Replies
  • 1

    [code=php] <?php $result = mysql_query('SELECT MAX(mailer_id),email FROM mailer_directory')or exit(mysql_error()); $row = mysql_fetch_assoc($result); echo 'the max mailer_id is ' . $row['email']; ?> [/code] or: [code=php] <?php $result = mysql_query('SELECT email FROM mailer_directory ORDER BY mailer_id DESC LIMIT 1')or exit(mysql_error()); $row = mysql_fetch_assoc($result); echo 'the max mailer_id is ' . $row['email']; ?> … Read More

  • [QUOTE=pritaeas;821312][code=php] <?php $result = mysql_query('SELECT MAX(mailer_id),email FROM mailer_directory')or exit(mysql_error()); $row = mysql_fetch_assoc($result); echo 'the max mailer_id is ' . $row['email']; ?> [/code] or: [code=php] <?php $result = mysql_query('SELECT email FROM mailer_directory ORDER BY mailer_id DESC LIMIT 1')or exit(mysql_error()); $row = mysql_fetch_assoc($result); echo 'the max mailer_id is ' . $row['email']; ?> … Read More

0
<?php 
  $result = mysql_query('SELECT MAX(mailer_id) FROM mailer_directory')or exit(mysql_error()); 
  $row = mysql_fetch_array($result);
  echo 'the max mailer_id is ' . $row[0]; 
?>
0

Thanks for the input.
I should have been more concise.
Here is the SQL table structure.

CREATE TABLE `mailer_directory` (
  `mailer_id` int(10) NOT NULL auto_increment,
  `name` varchar(24) NOT NULL default '0',
  `email` varchar(44) NOT NULL default '',
  `subject` varchar(24) NOT NULL default '',
  `message` varchar(200) NOT NULL default '',
  `submitted` date NOT NULL default '0000-00-00',
  `ip` varchar(16) NOT NULL default '0',
  `submission_id` varchar(36) NOT NULL default '0',
  `ticket_id` bigint(30) NOT NULL default '0',
  PRIMARY KEY  (`mailer_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=500 ;

Essentially I want to echo out to the browser the corresponding email for SELECT MAX(mailer_id)

1
<?php
  $result = mysql_query('SELECT MAX(mailer_id),email FROM mailer_directory')or exit(mysql_error()); 
  $row = mysql_fetch_assoc($result);
  echo 'the max mailer_id is ' . $row['email']; 
?>

or:

<?php
  $result = mysql_query('SELECT email FROM mailer_directory ORDER BY mailer_id DESC LIMIT 1')or exit(mysql_error()); 
  $row = mysql_fetch_assoc($result);
  echo 'the max mailer_id is ' . $row['email']; 
?>
1
<?php
  $result = mysql_query('SELECT MAX(mailer_id),email FROM mailer_directory')or exit(mysql_error()); 
  $row = mysql_fetch_assoc($result);
  echo 'the max mailer_id is ' . $row['email']; 
?>

or:

<?php
  $result = mysql_query('SELECT email FROM mailer_directory ORDER BY mailer_id DESC LIMIT 1')or exit(mysql_error()); 
  $row = mysql_fetch_assoc($result);
  echo 'the max mailer_id is ' . $row['email']; 
?>

Hi... try to do this....

$query="SELECT mailer_id,email FROM mailer_directory where mailer_id=MAX(mailer_id)"
$result = mysql_query('')or exit(mysql_error());
0

Pritaeas,
Thank you - appreciated.
That does the job.
Pretty much followed your first example.
I was on the same line - just using an inappropriate 'WHERE' and using a loop.
I got a bit lost on your second example.
I'll work on that.
Cheers.

0

Hi... try to do this....

$query="SELECT mailer_id,email FROM mailer_directory where mailer_id=MAX(mailer_id)"
$result = mysql_query('')or exit(mysql_error());

That looks promising.
I'll have a look at that.
Thank you.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.