Jump to content

[SOLVED] Really stuck with SELECT and SUM function


steviemac

Recommended Posts

Hello,

I an trying to get the SELECT and SUM function to work.  I would like a column to add all the numbers in the column and get a total.  If a user trys to update the table and that total is at a pre determined number it will echo one thing if not it will echo something else.

 

This is my code.  They enter their unique registration number and it will only display that row


Update  <?php echo "" .COURSE_NAME; ?> </h3>
<form name="search" method="post" action="<?=$PHP_SELF?>" onSubmit="return validateCompleteForm(this);">
<P align="center"><b>Enter Course Registration Number:</b> <input type="text" name="find" id="find" /> 
<input type="hidden" NAME="field" VALUE="[color=red]registration[/color]">  
<input type="hidden" NAME="Seats" >




<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</P> 
</form>
<P>Forgot you registration code?  <a href="forgotregistration.php">Go here</a></P>
<center><img src="../../images/blkline.jpg"></center>

<?php include '../db_config.php'; ?>
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
//This is only displayed if they have submitted the form
if ($searching == "yes")

{

    echo "<h3 align=\"center\">Results</h3>";

    

    

    if ($find == "")

    {

        echo "<p>You forgot to enter a search term</p>";

        exit;

        }

    

    

    

    

    

    $find = strtoupper($find);

    $find = strip_tags($find);

    $find = trim ($find);

    

    

    $data = mysql_query("SELECT  *, SUM(Seats) as totalSeats FROM " . USERS_TABLE . " WHERE upper($field) ='$find'   GROUP BY registration ") or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');

    

    

    while($result = mysql_fetch_array($data)) {

        if ($result['totalSeats'] == 25[color=red])//this would be the max and they would get the following [/color] {

           echo "<form action=\"updateck\" \" name=\"update\" method =\"POST\" >";
echo "<table align=\"center\" width=\"630\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" class=\"tblwhi\"><tr>";
echo "<tr><td class=\"thetag\">Seats Requested</td></tr>";
echo "<td class='thevalue'><P align=\"center\">$result[seats]</p> <input type=\"hidden\" size=\"30\" name=\"Seats\" value=\"$result[seats]\" /></td></tr>";
echo "<tr><td colspan=\"\"><input type=\"submit\" name=\"submit\" value=\"Update Selected\" /></td></tr>";
echo "<tr><td colspan=\"\"><center><img src=\"../../images/blkline.jpg\"></center></td></tr></table>\n";
echo "</form>\n"; 

            }



		else{
echo $result['totalSeats']; [color=red]// all I'm getting is the seats from the one row instead of the whole column[/color]
           echo "<form action=\"updateck\" \" name=\"update\" method =\"POST\" >";
echo "<table align=\"center\" width=\"630\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" class=\"tblwhi\"><tr>";
echo "<tr><td class=\"thetag\">Seats Requested</td></tr>";
echo "<tr><td class='thevalue'><P align=\"center\"><select name=\"Seats\" /><option>$result[seats]</option><option>1</option><option>2</option></select></p></td></tr>";
echo "<tr><td colspan=\"\"><input type=\"submit\" name=\"submit\" value=\"Update Selected\" /></td></tr>";
echo "<tr><td colspan=\"\"><center><img src=\"../../images/blkline.jpg\"></center></td></tr></table>\n";
echo "</form>\n"; 

            }

        

        }

    

    $anymatches = mysql_num_rows($data);

    if ($anymatches == 0)

    {

        echo "<P>Sorry, but we can not find an entry to match your query<br><br></P>";

        }

    

    

    echo "<P><b>Searched For:</b> " . $find;

    echo "</p>";

    } 

?>

 

I'm pretty much at the end of my rope.  I have been at this for two days with no success. Thank you for any help.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.