Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. Hi I'm fairly new to all this myself, but I'd say there are 2 problems. 1. You are not actually instructing the function to return any values. 2. You cannot return an array from a function (or so I've been told). Hope this points you in the right direction.
  2. I was thinking down those lines and I can do basic joins where I select values from one table based on values within linked other tables. However, how do I select 1 value from 1 table and another value from another table based on values in linked tables. Sorry about this, I'm a bit of a newbie to mysql
  3. Hi I am trying to get information from several tables within a database and produce a comparative statement that will produce a table for me. I have 3 tables which contain the following useful columns mdl_scorm ID course name [*]mdl_scorm_scoes_track ID userid(relates to mdl_user.id) scormid(relates to mdl_scorm.id) element value timemodified [*]mdl_user id firstname lastname I am trying to get all 'name' from mdl_scorm and put into a HTML table, then against each one put the value for a particular user and the time modified from mdl_scorm_scoes_track. If there is no entry in the mdl_scorm_scoes_track I need it to say incomplete. I seem to be going round in circles with this and never acheiving the required result. Please could someone have a look at the code below and offer any advice. mailout.php simply sends an email of the table to a designated address, config.php sets up a load of sitewide variables, the only one which applies to this is $USER which relates to mdl_user.id to find the current user. If you need any more info let me know. <head> <title>Induction Results</title> </head> <body><div align="center"> <?php if (isset ($_POST['return'])) { header( 'Location: http://www.mysite.co.uk' ) ; exit(); } include_once "../config.php"; include_once "../induction_output/Rmail.php"; $username = $USER->firstname . " " . $USER->lastname . " "; //BB_ Where header and CSS are printed from print_header("$site->fullname: $loginsite", $site->fullname, $navigation, $focus, '', true, '<div class="langmenu">'.$langmenu.'</div>'); ?> <?php $userid = $USER->id; echo $username . "has completed the following modules<br /><br/>"; $course = "SELECT id, name from mdl_scorm where course = 219"; $firstname = "SELECT firstname, lastname FROM mdl_user WHERE id = $userid"; $course = mysql_query($course); $table = "cmi.core.lesson_status"; echo '<table border="1" cellpadding="10"><tr><td>Module Name</td><td>Status</td><td>Completion Date</td></tr>'; while ($course_row = mysql_fetch_assoc($course)) { echo "<tr><td>" . $course_row['name'] . "</td>"; $user_value = 'SELECT userid, timemodified, value FROM mdl_scorm_scoes_track WHERE element ="cmi.core.lesson_status" AND scormid = ' . $course_row['id']; $user_value = mysql_query($user_value); if (!isset ($user_value)){ echo "help"; } while($process = mysql_fetch_assoc($user_value)){ if ($process['userid']==$userid) { echo "<td>" . $process ['value'] . "</td><td>" . $process['timemodified'] . "</td>"; } else { echo "<td>Incomplete</td><td></td>"; } } echo "</tr>"; } echo "</table>"; if (isset ($_POST['happy'])) { include_once "../induction_output/mailout.php"; exit(); } else { echo '<form action="" method="post">'; echo '<input type="submit" name="happy" value="Confirm Details and Send to Human Resources"></input>'; echo '</form>'; } ?> <form action="" method="post"> <input type="submit" name="happy">Confirm Details and Send to Human Resources</input> </form> </div></body>
  4. Cheers Guys If only I'd known about Rmail about 6 hours ago!!! lol Works a treat!!
  5. Hi all I'm trying to send an automated email of a zip file. However it seems to be just reading the files into the body of the mail rather than attaching a single zip archive containing several files. I receive the mails, but I effectively want a blank message body with a zip file attached. Please see code below, any ideas why this is not working. I'm a bit of a newbie and never used this before so any pointers would be good. <?php //Send Zip file as attachment //Set Email and attachment details $to = "me@123.com"; $from = "Visionnet <DO_NOT_REPLY>"; $subject = "Subject"; $message = "Please see attached file"; $fileatt = "wiki_zip.zip"; $fileatt_type = "application/zip"; $fileatt_name = "wiki_zip.zip"; //Read in the attachment $file=fopen($fileatt,'rb'); $data=fread($file,filesize( $fileatt)); fclose($file); //Add the MIME content $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the Headers for file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multipart message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; //Base64 encode file data $data = chunk_split(base64_encode($data)); //Add attachment to message $message .= "--{mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; //Send message $ok = @mail($to, $subject, $message, $headers, "$from"); if($ok) { echo "mail sent"; } else { echo "mail failed"; } ?>
  6. Hi I have a database set up using MySQL and want to be able to query this and then export to Excel using PHP. I've had a look around on the web but a lot of what I'm reading is going over my head. I don't have PEAR so can't use the ready made stuff. Basically, I want to be able to query the database, then export the arrays to an excel file and a pop up to appear asking the user to open / save / cancel (standard pop-up) Anyone know of any good places to start looking for the information for this? Sorry, I'm new to all this so any help / pointers would be greatly appreciated. Cheers
  7. I get /getquiz.php?test= Which says to me that no variable is being passed I know that $userrow['userid'] contains a value as I can echo this out when needed. Seems so simple, but got me stumped
  8. I've kept it simple, I was just trying to echo it out to ensure it was working. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <?php if (!$_GET['test']) { echo "fail"; } echo $_GET['test']; //echo $userphpid; echo "hello"; ?> </BODY> </HTML>
  9. Hi All Please take a look at the code below. I am sucessfully accessing a database and pulling the details through into a HTML form with a drop down. However I then want to use a variable (test) in another page. However I cannot get the variable userrow['userid'] to send a value to my getquiz.php. What am I doing wrong? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <?php include_once "db.inc.php"; ?> <body> <form action="getquiz.php" method="GET"> <tr><td class="title">Please Select User</td> <td><select name="test"> <?php $courseid = mysqli_query($link, 'SELECT id FROM mdl_quiz WHERE course = "225"; '); if (!courseid) { $error = ' Error fetching course id: ' . mysqli_error($link); include 'error.html.php'; exit(); } else { while($row = mysqli_fetch_array($courseid)) { $user = mysqli_query($link, 'SELECT userid FROM mdl_quiz_attempts WHERE quiz =' . $row['id']); while ($userrow = mysqli_fetch_array($user)) { $names = mysqli_query($link, 'SELECT firstname,lastname FROM mdl_user WHERE id=' . $userrow['userid']); while ($usernames = mysqli_fetch_array($names)) {?> <option value="<?php $userrow['userid']?>"> <?php echo $usernames ['firstname'] . " " . $usernames['lastname'] . $userrow['userid']; ?> </option> <?php } } } } ?> </select> </td></tr> <center><input type="submit" value="Submit"></center> </table> </form> </body> </html>
  10. Hi All I'm currently in the beginnings of my life as a php developer and I've been looking online for some decent intermediate tutorials. I've done the basic W3Schools tutorial and attended a taught session which compounded this knowledge. I'm now looking to take the next step and I'm not sure where to go. I'm looking to gather a good knowledge level to then apply in career development. Unfortunately I'm not currently working in the web dev world and it's very difficult to be able to showcase what little talent I have. I've checked the 'looking for work' forum but everything seems a bit beyond me at the moment. Anybody any ideas for some good tutorials (free ones are best) which are available to push me in the right direction. I've also got a basic knowledge of MySql too.
  11. I'm fairly new to this all myself, but one possibility would be to write the information from the first website to a file, then use the second webiste to read the information from the file? I'm sure some of the clever chaps on here will be able to give you a bit of code for it.
  12. Hi All Please can someone help me. I have a CSV file with over 3000 lines. Each one contains the following information Country Insurance Name Mandatory or Optional Description and Coverage Group SIPP Cost Per Day Cost Per Week Cost Per Month Deductable I have written the following script to read line by line, compare the country and insurance with the previous and if it is the same, tag certain parts of each line onto the end of the previous. However, I am getting no output from this, and I keep getting an error saying I am using too much memory or my computer hangs. I am fairly new to php so any pointers would be good. Firstly, does my script look like it should do what I want it to do? If so, any clues how to get around the momory issue. If not, what have I done wrong? Cheers guys <?php //open file paths $handle=fopen("insurances.csv","r"); $handle_out=fopen("insuranceoutput.csv","a"); //writes the first line of the csv file into an array to act as a comparrison if($handle){ $line=fgets($handle); $line_array=explode(",",$line); $full_array=$line_array; fclose($handle); } } if($handle) { while (!feof($handle)) { // read one line into array $line=fgets($handle); $line_array=explode(",",$line); fclose($handle); //test to see if country matches previous while ($line_array[0] == $full_array[0]) { //test to see if insurance matches previous while ($line_array[1] == $full_array[1]) { //write array values 4 - 9 to main array $full_array[]=array("$line_array[4]","$line_array[5]","$line_array[6]","$line_array[7]","$line_array[8]","$line_array[9]"); } } //write to new file when new insurance is found foreach($full_array as $output) { fwrite($handle_out, "$output,"); } fwrite($handle_out,"\n"); fclose($handle_out); } // write to new file if new country is found. foreach($full_array as $output) { fwrite($handle_out, "$output,"); } fwrite($handle_out,"\n"); fclose($handle_out); } } ?>
  13. Any ideas anyone??? It's got me totally stumped!!!
  14. When I echo the data out of the basic arrays, I get the following. $morale_count1[1] = 1 $morale_count1[2] = 1 $morale_count1[3] = 0 $morale_count1[4] = 0 $morale_count1[5] = 0 $total_morale1 = 2. I have another report set up which just produces the raw data and this works fine, it's just the % conversion which is not working.
  15. Hi all I have several arrays set, and I can guarantee I have values in these as I have tested them by echoing out each value. However, when I pass it through a user defined function to produce a percentage for each value of the total arry, I get a null return. I don't even get any errors. Any ideas? // Produce the % array of each array for use in 2nd report $percent_morale1=percentCalc($morale_count1[1],$morale_count1[2],$morale_count1[3],$morale_count1[4],$morale_count1[5],$total_morale1); $percent_morale2=percentCalc($morale_count2[1],$morale_count2[2],$morale_count2[3],$morale_count2[4],$morale_count2[5],$total_morale2); $percent_morale3=percentCalc($morale_count3[1],$morale_count3[2],$morale_count3[3],$morale_count3[4],$morale_count3[5],$total_morale3); $percent_morale4=percentCalc($morale_count4[1],$morale_count4[2],$morale_count4[3],$morale_count4[4],$morale_count4[5],$total_morale4); $percent_morale5=percentCalc($morale_count5[1],$morale_count5[2],$morale_count5[3],$morale_count5[4],$morale_count5[5],$total_morale5); $percent_morale6=percentCalc($morale_count6[1],$morale_count6[2],$morale_count6[3],$morale_count6[4],$morale_count6[5],$total_morale6); <?php function percentCalc($value1,$value2,$value3,$value4,$value5,$total) { $array=array($value1,$value2,$value3,$value4,$value5); while (list($key,$arraycontent)= each($array)) { $c_percent=(($arraycontent/$total)*100); $final_array[]=$c_percent; } return $final_array; } ?> <?php echo"<td class=\"percent1\" > "; printf("%01.0f",$percent_morale1[1]); echo "%</td>"; echo"<td class=\"percent2\" > "; printf("%01.0f",$percent_morale1[2]); echo "%</td>"; echo"<td class=\"percent3\" > "; printf("%01.0f",$percent_morale1[3]); echo "%</td>"; echo"<td class=\"percent4\" > "; printf("%01.0f",$percent_morale1[4]); echo "%</td>"; echo"<td class=\"percent5\" > "; printf("%01.0f",$percent_morale1[5]); echo "%</td>"; ?>
  16. This seems like such a simple error, however I've no idea why I am getting it. apparently I have an unexpected comma on line 4 of the code below. I can't work out what the error is. Any ideas? Sorry to be a pain if it really is something simple, but I'm a bit new to all this php stuff. <?php function percentCalc($value1,$value2,$value3,$value4,$value5,$total) { $array=($value1,$value2,$value3,$value4,$value5); while (list($key,$arraycontent)= each($array)) { $c_percent=(($arraycontent/$total)*100); $final_array[]=$c_percent; } return $final_array; } ?>
×
×
  • 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.