Jump to content

Evanthes

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Evanthes's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. how could i go about returning the value? Ii's working a bit better by defining it outside the function, my functions still work, and outside the functions I am getting 0 for a value instead of nothing like i had before.
  2. hehe yeah I'm def not that great at coding... yeah I'll try defining it outside and see where that gets me thanks
  3. [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
  4. 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!
  5. im finding its some sort of problem with php, i guess the exe doesnt work well with mysql or something
  6. thanks for the help, but im still getting the same error with that
  7. 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!
  8. i guess i dont understand, it tells me only 1 record was inserted yet 2 show up, think i might have a database problem or something?
  9. [code=php:0]$query= "INSERT INTO `prospects` VALUES (NULL, '.$name.', '.$contact.', '.$info.', NOW(), '1')  LIMIT 1"; [/code] great idea, i think that will solve my problem, although for some reason it wont work when i put the limit in. any ideas why? thanks
  10. 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]
  11. sweet i got it, your statement worked out really well obsidian, thanks a lot!
  12. yeah exactly, hopefully within the for loop, so it goes in the right spot on my table, and it knows that record we're dealing with
  13. i updated my first post, basically there are multiple records that have the same work_id and i want to display the number of records for each work_id...im gonna keep fiddling with this
  14. 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
×
×
  • 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.