SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation PHP Newbie: need to add total amount from individual fields

    hello all,

    i'm new at this php and mysql stuff,

    i need to display the total amount from each field i have, (each field may have different words submitted i.e. pub_priv may contain public or private)

    here is my code to submit.

    PHP Code:
    <?php 
    error_reporting
    (E_ALL E_NOTICE);
    $db mysql_connect("localhost","",""); 
    mysql_select_db ("reforumc_email"); 
    $query "INSERT INTO equinoxsurvery(pub_priv, size, scope, position, entrepreneur, more_entrep, percieve, attracted, entrep_approach, met, screens, behave, rewarded, offers, function)
    VALUES('"
    .$_POST['pub_priv']."','".$_POST['size']."','".$_POST['scope']."','".$_POST['position']."','".$_POST['entrepreneur']."','".$_POST['more_entrep']."','".$_POST['percieve']."','".$_POST['attracted']."','".$_POST['entrep_approach']."','".$_POST['met']."','".$_POST['screens']."','".$_POST['behave']."','".$_POST['rewarded']."','".$_POST['offers']."','".$_POST['function']."')"
    $result mysql_query($query); 
    echo 
    "Thank you for taking our survey."?>
    here is my code that displays the results

    PHP Code:
    <?php
    $connection 
    mysql_connect ("localhost","reforumc_eup","test1234");
    if (
    $connection == false){
      echo 
    mysql_errno().": ".mysql_error()."<BR>";
      exit;
    }  

    $query "SELECT * FROM equinoxsurvery";
    $result mysql_db_query ("reforumc_email"$query);

    if (
    $result){
      echo 
    "<table border=1>";
      echo 
    "<tr><td><b>Full Name</b></td><td> <b>Email Address</b></td></tr>";

      
    $numOfRows mysql_num_rows ($result);
      for (
    $i 0$i $numOfRows$i++){
        
    $question1 mysql_result ($result$i"pub_priv");
        
    $question2 mysql_result ($result$i"size");
        
    $question3 mysql_result ($result$i"scope");
        
        echo 
    "<table border=1>";  
        echo 
    "<tr colspan=3><td>$question1</td><td bgcolor=#E8EFF7>$question2</td><td>$question3</td></tr>";
        echo 
    "</table>";
      }

      echo 
    "</table>";
    }
    else{
      echo 
    mysql_errno().": ".mysql_error()."<BR>";
    }

    mysql_close ();

    ?>
    and here are the links to the pages that are submitting them... it's not completely ready. and it's not displaying all the results in the tables, but it's a start
    Please tell me if i've made no sense

    test page
    Last edited by daemoncel; Nov 30, 2004 at 13:17.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    South Africa
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    <?php
    $connection 
    mysql_connect ("localhost","reforumc_eup","test1234") or die('Database not available');
    mysql_select_db('reforumc_email');

    $query "SELECT * FROM equinoxsurvery";
    $result mysql_query($query) or die(mysql_error());

    if (
    mysql_num_rows($result) > 0) {
        echo 
    "<table border=1>";
        echo 
    "<tr><td><b>Full Name</b></td><td> <b>Email Address</b></td></tr>";    

        while(
    $row mysql_fetch_assoc($result)) {

            
    $question1 $row["pub_priv"];
            
    $question2 $row["size"];
            
    $question3 $row["scope"];

            echo 
    "<table border=1>";  
            echo 
    "<tr colspan=3><td>$question1</td><td bgcolor=#E8EFF7>$question2</td><td>$question3</td></tr>";
            echo 
    "</table>";
        }
    }
    else {
        echo 
    'No rows';
    }

    mysql_close ();

    ?>

  3. #3
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply

    but unfortunately it doesn't really do anything different (of course i'm a newbie, and am having trouble figuring out what it's doing different

    also, i don't think i made much sense, so

    basically i want to find out how many people said Public for the pub_priv field and how many people said private for the same field (pub_priv)

    and so on

    and be able to display it neatly.

    sort of like a poll

    well at least i'm understanding the code now and thanks for the quick response

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in essence i need a poll (survey)

    have i setup the the db wrong?

    i created it so that each field can contain different responses from the Survey

    i.e. pub_priv may contain public or private

  5. #5
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please, i really need help with this, this survey is killing me, i on't know if i'm doing it the right way

    anyone?

  6. #6
    SitePoint Addict Fire59's Avatar
    Join Date
    Aug 2003
    Location
    mn
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you just want the count then do this
    PHP Code:
    $sql "SELECT count(*) FROM equinoxsurvery WHERE pub_priv ='private'";
    $result mysql_query($query) or die(mysql_error()); 
    $private_comp $result[0];
    $sql "SELECT count(*) FROM equinoxsurvery WHERE pub_priv ='public'";
    $result mysql_query($query) or die(mysql_error()); 
    $public_comp $result[0]; 

  7. #7
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much

    i'm trying to get it to work now

    so do i just plug this code in?

    and create a while and add in the echo that calls in the appropriate Var?

  8. #8
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i can't seem to get that code to submit display anything.

    I popped the above code in to my code

    do i add my own if and where statements in as well?

    PHP Code:
    <?php
    $connection 
    mysql_connect ("localhost","reforumc_eup","test1234") or die('Database not available');
    mysql_select_db('reforumc_email');

    $query "SELECT * FROM equinoxsurvery";
    $result mysql_query($query) or die(mysql_error());

    if (
    mysql_num_rows($result) > 0) {
       
    // echo "<table border=1>";
        //echo "<tr><td><b>Full Name</b></td><td> <b>Email Address</b></td></tr>";    

        
    while($row mysql_fetch_assoc($result)) {
        
            
    $question0 $row["id"];
            
    $question1 $row["pub_priv"];
            
    $question2 $row["size"];
            
    $question3 $row["scope"];

            echo 
    "<table border=1>";  
            echo 
    "<tr colspan=4><td>$question0</td><td>$question1</td><td bgcolor=#E8EFF7>$question2</td><td>$question3</td></tr>";
            echo 
    "</table>";
        }
    }
    else {
        echo 
    'No rows';
    }
    $connection mysql_connect ("localhost","reforumc_eup","test1234") or die('Database not available');
    mysql_select_db('reforumc_email');

    $sql "SELECT count(*) FROM equinoxsurvery WHERE pub_priv ='private'";
    $result mysql_query($query) or die(mysql_error());
    $private_comp $result1[0];
    $sql "SELECT count(*) FROM equinoxsurvery WHERE pub_priv ='public'";
    $result mysql_query($query) or die(mysql_error());
    $public_comp $result[0]; 

    mysql_close ();
    ?>

  9. #9
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This page of mine needs to be done soon

    i kinda got volunterred into something and did not have a choice on

    and now i'm stuck

    please help!

    all i need is to display on the page linked above, the total results... very important

  10. #10
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Ridgefield
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well thanks for the help anywya, still can't figure it out.


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
  •