Jump to content

Evanthes

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by Evanthes

  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
  15. 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
  16. awesome thanks, its been awhile since ive had to do programming like this...what do u mean exactly by escape your variables? thanks again
  17. [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.!
  18. cause boss said thats what he wants  :D
  19. 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!
  20. [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
  21. 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]
  22. just [quote author=Jocka link=topic=103765.msg413459#msg413459 date=1155242268] [code] global $today, $searchterm; [/code] put it at the top of the function [/quote] it worked, i really appreciate it!
  23. 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.