Jump to content

Evanthes

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Posts posted by Evanthes

  1. [quote author=kenrbnsn link=topic=121036.msg497018#msg497018 date=1167943241]
    Can you post the rest of the code? The code snippet you posted doesn't have enough information for us to give a meaningful answer.

    Please post the code between [nobbc][code][/code][/nobbc] tags.

    Ken
    [/quote]
    The $ncorr variable is added via a if statement, then another if statement calculates the number of questions that were correct. the problem is that the variable doesnt hold its value outside of the if statements, as I want to use it in an email function. thanks a lot guys.
    :
    [code]
    function checkanswers($group1, $group2, $group3, $group4, $group5, $group6,$group7,$group8,$group9,$group10){
    $ncorr = '0';

    if ($group1 == "True") {
    echo "Answer to Question #1: $group1, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #1: The Correct Answer is: true, you answered: $group1<br></font>";
    }

    if ($group2 == "True") {
    echo "Answer to Question #2: $group2, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #2: The Correct Answer is: True, you answered: $group2<br></font>";
    }

    if ($group3 == "D") {
    echo "Answer to Question #3: $group3, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #3: The Correct Answer is: True, you answered: $group3<br></font>";
    }

    if ($group4 == "True") {
    echo "Answer to Question #4: $group4, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #4: The Correct Answer is: True, you answered: $group4<br></font>";
    }

    if ($group5 == "True") {
    echo "Answer to Question #5: $group5, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #5: The Correct Answer is: True, you answered: $group5<br></font>";
    }


    echo "You entered $group6 as an answer to Question 6<br>";


    echo "You entered $group7 as an answer to Question 7<br>";



    if ($group8 == "True") {
    echo "Answer to Question #8: $group8, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #8: The Correct Answer is: True, you answered: $group8<br></font>";
    }

    if ($group9 == "A") {
    echo "Answer to Question #9: $group9, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #9: The Correct Answer is: A, you answered: $group9<br></font>";
    }


    if ($group10 == "True") {
    echo "Answer to Question #10: $group10, You answered Correctly!<br>";
    $ncorr++;
    }else {
    echo "<Font color='red'>Question #10: The Correct Answer is: True, you answered: $group10<br></font>";
    }



    //------------------------------------------Results--------------------------------------------------


    if ($ncorr == '0') {
    $mess = "Some answers were incorrect, please backup and try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '1') {
    $mess = "you got one right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '2') {
    $mess = "you got two right";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '3') {
    $mess = "you got one right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '4') {
    $mess = "you got one right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '5') {
    $mess = "you got one right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '6') {
    $mess = "you got six right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '7') {
    $mess = "you got seven right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '8') {
    $mess = "you got eight right, two questions will be further graded";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '9') {
    $mess = "you got nine right, please try again";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    if ($ncorr == '10') {
    $mess = "you got ten right";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    echo "$ncorr answers<br>"; //variable shows up here
    }
    echo "{$ncorr} questions answered correctly"; //variable doesnt here[/code]
    fert- didn't work
    GFD- I'm not trying to divide, just showing the user the number they got right out of the total number of questions.
    thanks for the help guys
  2. Hey guys I got a variable ($ncorr) that I'm using to count the numnber of correct answer for a test...everything works fine, except when i want to call the variable outside of the for statement check out my example

    [code=php:0]

    if ($ncorr == '10') {
    $mess = "you got ten right";
    echo "<font size='1' face='verdana'><center><h1>$ncorr/8!</h1><br/>";
    echo "$mess</center></font>";
    }
    echo "$ncorr answers<br>"; //variable shows up here
    }
    echo "$ncorr questions answered correctly"; //variable doesnt here

    [/code]

    Any help would be greatly appreciated!
    thanks!
  3. Hey guys ive been developing a program on my local machiene thats works great, however now im moving it to our webserver and am having some problems. I've duplicated everything on the server with the exception of the port that mysql runs on. and now i am getting the following error:
    Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\cp\opendb.php on line 3

    here is my db connection code
    [code]
    //opendb.php
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
    mysql_select_db($dbname);
    [/code]

    i guess I'm just wondering why the php in the statement isnt being processed and its giving me the mysql error instead of "error connecting to mysql" like it should say in the code.
    the server is a 2k server running IIS, if that might have anything to do with it. thanks for your help!
  4. Im using this file to insert records into my database and for some reason it makes 2 for the same record each time its inserted. could someone please take a look and let me know what i might be doing wrong? thanks!
    [code=php:0]

    <?
    include('include.php'); // include file
    include 'opendb.php'; // includes mysql  connection


    $name=$_REQUEST['name'];
    $id=$_REQUEST['id'];
    $contact=$_REQUEST['contact'];
    $info=$_REQUEST['info'];
    $date=$_REQUEST['date'];
    $probable=$_REQUEST['probable'];
    $query= "insert into prospects values (null, '".$name."', '".$contact."', '".$info."', '".$date."', '".$probable."')";
    $result = mysql_query($query);
    if ($result)
    echo "<center>";
    {echo mysql_affected_rows(). ' Record(s) updated.';}
    echo "</center>";
    ?>
    [/code]
  5. hey guys i think I have a relatively easy question.

    I want to be able to see how many records for a primary key there are. I have a table that is filled with all this information. but the number of records doesnt update when i add a new one. check out my code and see what i mean:

    [code=php:0]
    $zone = $searchterm; // var created for link back to search
    $query = "select * from tbl_sites where zone = '".$searchterm."'" ;
    $result = mysql_query($query);

    $num_results = mysql_num_rows($result);
    echo "<center>";
    echo "<br><br><a href='test.php'>Return to list of Zones</a>";
    echo '<p> number of records found:' .$num_results. '</p>';
    echo "<center>";
    echo '<table border="1" align="center">';
    echo '<tr><td>';
    echo 'Site ID</td><td>Net</td><td>State</td><td>Zone</td><td>City</td><td>Address</td><td>Jobs</td>';
    for ($i=0; $i <$num_results; $i++)
    {
    $row = mysql_fetch_array($result);
    $siteid = $row['site_id'];
    echo '<tr><td>';
    echo '<tr><td>';
    echo htmlspecialchars(stripslashes($row['site_id']));
    echo '</td><td>';
    echo stripslashes($row['net']);
    echo '</td><td>';
    echo stripslashes($row['state']);
    echo '</td><td>';
    echo "</a>";
    echo stripslashes($row['zone']);
    echo '</td><td>';
    echo "</a>";
    echo stripslashes($row['city']);
    echo '</td><td>';
    echo "</a>";
    echo "<a href='siteinfo.php?searchterm=$siteid&zone=$zone'>";
    echo stripslashes($row['address']);
    echo '</td><td>';
    echo "</a>";
    echo stripslashes($row['jobs']);
    echo '</td>';
    echo "</tr>";
    [/code]
    this statement basically fills my table with data of each record. I'm trying to show the number of jobs and have it update when a new one is added, just like the numer of threads in a topic for a message board like this. although its not working, im guessing i need some sort of mysql_num_rows statement but i guess i dont understand how i can change this. thanks for anyhelp
  6. Hey guys I'm helping my company make a training video application that shows a video then requires the user to answer questions based on what they saw. I was thinking about using php to do this and then to stream the video over the network. is this a good idea? I know that php would work well to do the testing part but I guess I'm more worried about how well video is streamed over the net, or even if there is a better way to achieve this. thanks in advance
  7. [code=php:0]
    $query = "update tbl_work set site_id=$id comments=$comments date_of_work=$date where work_id=$workid";
    [/code]

    i guess ive just been looking at this too long and dont understand why mysql doesnt like this statement. Below is how the statement prints out.

    update tbl_work set site_id=1 comments=N/A date_of_work=2006-09-14 where work_id=942

    does this need to be formatted in some way? thanks for the help ahead of time.!
  8. I am running a program that queries the database, based on user input. Now i want to be able to backup specific searches to a excel file. All the Mysql queries are working dandy, and Ive followed the tutorial on the website to export to Excel but i must be missing somehting because everything (the columns and the data) is just printing into one cell. So I know I'm close to getting this to work seeing how my data is getting passed to the file but i guess my problem lies with the formatting. Does anyone know what the problem might be? Could it be something with my database? I'll post the code from the tutorial for reference.
    [code=php:0]
    include('include.php'); // includes mysql  connection
    // creating variable names
    $searchterm=$HTTP_GET_VARS['searchterm'];
    // begin here with code to push data to PDF/EXCEL

    $select = "select * from data.tbl_sites where zone = '".$searchterm."'" ;
    $export = mysql_query($select);
    $fields = mysql_num_fields($export);

    for ($i = 0; $i < $fields; $i++) {
        $header .= mysql_field_name($export, $i) . "\t";
    }

    while($row = mysql_fetch_row($export)) {
        $line = '';
        foreach($row as $value) {                                           
            if ((!isset($value)) OR ($value == "")) {
                $value = "\t";
            } else {
                $value = str_replace('"', '""', $value);
                $value = '"' . $value . '"' . "\t";
            }
            $line .= $value;
        }
        $data .= trim($line)."\n";
    }
    $data = str_replace("\r","",$data);
    if ($data == "") {
        $data = "\n(0) Records Found!\n";                       
    }
    header("Content-type: application/x-msdownload");
    header("Content-Disposition: attachment; filename=extraction.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    print "$header\n$data"; 
    ?>
    [/code]

    thanks for the help guys I really appreciate it!
  9. [quote author=corbin link=topic=103890.msg414029#msg414029 date=1155317936]
    Uhhhh... For it to out put on any page besides its self it will need to be included and then the function called on that page.
    [/quote]

    yeah i know...
    thanks for the help though i found the problem
  10. Hey guys im making a submit form function and for some reason it is just sending all the data to the same page instead of added.php like it should. could someone take a look at my code and let me know why its not doing that? much appreciated!

    [code=php:0]
    function addnew()
    {
    global $today, $searchterm;
    echo "<form action='inserted.php' method='get'>";
    echo '<tr><td>';
    echo "<textarea name=id rows=0 cols=25>$searchterm</textarea>";
    echo '</td>';
    echo "<td>";
    echo "<textarea name=comments rows=0 cols=25>N/A</textarea>";
    echo '</td><td>';
    echo "<textarea name=date rows=0 cols=25>".$today."</textarea>";
    echo '</td><td>';
    echo "<input type='submit' value='submit'";
    echo '</td>';
    echo '</tr>';
    echo '</form>';
    }



    [/code]
  11. Hey all Ive been trudging along on somewhat of a cms and ive made a page that i want to have records from the database load into a few select fields so that the user wont have to type those in when theyre entering new data. However what i think should work isnt even coming up. for some reason my textboxes are just normal blank ones without my info in it.
    anyways heres my function:

    [code=php:0]

    function addnew()
    {
    echo '<tr><td>';
    echo "<textarea name=id rows=0 cols=25>$searchterm</textarea>";
    echo '</td>';
    echo "<td>";
    echo "<textarea name=comments rows=0 cols=25>N/A</textarea>";
    echo '</td><td>';
    echo "<textarea name=date rows=0 cols=25>".$today."</textarea>";
    echo '</td>';
    echo '</tr>';
    }

    [/code]

    both $today and $searchterm are working fine just  not in that function.
    I bet its something like concatenation but ive been messing with that and cat get it to work. thanks for any help you guys can lend
×
×
  • 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.