I have a table in my database and i would like to bring up all the details where
the datafield "votes" is the largest. i cannot get the fuctionality i desire.

i would like a user to make a choice from the selection then have all the datafield where "votes" is the highest returned.
please help, the code i have is below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

 $connect = mysql_connect("localhost", "root","");
    if (!$connect)
       die("database connection failed". mysql_error());
    //make sure we’re using the right database
    $select_db = mysql_select_db("Elections");
    if (!select_db)
      die("database selection failed " .mysql_error());
    $portfolio = trim($_POST['portfolio']);
    $queryOne = "SELECT * FROM $portfolio WHERE MAX(Votes);
    $resultOne = mysql_query($queryOne);

<style type="text/css">
.auto-style1 {
	margin-top: 93px;



<form action="results.php" method="post" style="width: 514px; height: 168px">

    <fieldset name="Group1" style="height: 164px">
	<legend>Results Per Portfolio</legend>
		<select name="portfolio" style="height: 23px; width: 117px;" class="auto-style6">
				<option value=" president "> President </option>
				<option value=" vicePresident "> Vice President</option>
				<option value=" secretary "> Secretary </option>
				<option value=" viceSecretary "> Vice Secretary </option>
				<option value=" treasurer "> Treasurer </option>
    	 </select><br />
    <input name="Results" type="submit" value="Results" class="auto-style1"/>



Recommended Answers


Try changing the WHERE MAX(Votes) to

WHERE Votes = (select MAX(Votes) from $portfolio )
Jump to Post

All 2 Replies


Try changing the WHERE MAX(Votes) to

WHERE Votes = (select MAX(Votes) from $portfolio )

Alternatively sort by votes and use the first record:

select * from portfolio order by votes desc limit 1;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.