Jump to content

jdeutsch

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jdeutsch's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @skunk $s=get_all_students(); for($i=0;$i<count($s);$i++) { ... $regnum=student_reference_number($s[$i]['student_id'],$_SESSION['test_info']['test']['id'],$_SESSION['test_info']['session']['session_id']); if($regnum!=($i+1)) { $style.=" unsequenced"; $title=$s[$i]['student_last_name'].", ".$s[$i]['student_first_name']."'s reference number is out of the numerical sequence."; } ... } This was what I had done initially. The script checked the Reg. Num. ($regnum) against the current value of $i as the for loop processed. This caused all of the rows after the initially unsequenced one to be highlighted as well. @Andy $s=get_all_students(); $j=0; for($i=0;$i<count($s);$i++) { ... $regnum=student_reference_number($s[$i]['student_id'],$_SESSION['test_info']['test']['id'],$_SESSION['test_info']['session']['session_id']); if($regnum!=($j+1)) { $style.=" unsequenced"; $title=$s[$i]['student_last_name'].", ".$s[$i]['student_first_name']."'s reference number is out of the numerical sequence."; } else { $j++; } ... } I also tried what you suggested, but it caused a similar issue as above, except while the first snippet didn't start highlighting all rows until the third or fourth unsequenced record, this version (which includes $j), highlighted every row after the initial unsequenced record. I definitely appreciate the suggestions and the help. I hope the code snippets help you to help me.
  2. Each test is identified by the student's reference number. Ultimately, the sorting of the table has nothing to do with this number, but because both the last name and the reference number are ways we identify tests (especially when inputting grades), I'd like the table to have some sort of obvious styling applied to that row to indicate that while it is in alphabetical order, it is out of sequence. It's a relatively backward system we have: when we grade, online, everything must be sorted by last name; however, when we organize the physical test papers, everything must be sorted by the reference number. For the most part the there are maybe two or three records whose reference numbers are out of sequence (out of 600 or so test-takers), and these are people who registered late and therefore were given reference numbers after the original batch was assigned (if this all makes sense to anyone). Despite the fact that I am frequently sitting and coding, I'm actually not a logically-intelligent person, and small problems like this (that I feel have really simple answers) baffle me for days!
  3. I've tried searching all around: Google, the forums here, various other places, but all with no luck. I'm not new to PHP, and this might not be a scripting question necessarily (might be more of a logic question), but it's driving me crazy: I'm building a grading program for a school I work at. There are several state tests given each year, and we want to store all the information in a MySQL DB. Each student has a student id number, as well as a test reference number. Some of the reference numbers are not in the correct sequence because the table must absolutely be sorted by the students' last names. What I'd like to do is be able to highlight any rows that do not follow the standard numerical sequence (1, 2, 3...). For example: Ref # ID # Last Name 1 100000 Arnold 2 100001 Burns 3 100002 Cassidy 5 100003 Donaldson (this row needs to be highlighted) 4 100004 Cummings At the moment, my script seems to be highlighting every row after (and including) the out-of-sequence row. I've got the basics working: since the reference numbers begin with 1, I've got the script checking to see if the reference number is equal to $i (for my for loop) plus 1, but I know that this is what is causing the problem of all rows after being highlighted. I've tried starting with an empty variable ($refnum=0) and making this equal to the next ref num in the sequence (only if the current one is one more than the last), but that doesn't work either. If anyone has done this before and has a sample script to help me out, or even just some suggestions, thoughts, comments, or a solution that they can describe (with or without code), it would be immensely appreciated!
  4. Thanks for the pointer, and sorry about posting in the wrong place. Works fine, like you said.
  5. I recently found the following code on php.net listed under preg_replace. It does exactly what I'm trying to accomplish, however, it does the capture the TLD of the domain in question. CODE (extra spaces in regex added to keep code from running too long on the page): <?php function hyperlink($text) { // match protocol://address/path/file.extension?some=variable&another=asf% $text = preg_replace("/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]* [a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=]*)([\s|\.|\,])/i", " <a href=\"$1\" target=\"_blank\">$1</a>$2", $text); // match www.something.domain/path/file.extension?some=variable&another=asf% $text = preg_replace("/\s(www\.[a-z][a-z0-9\_\.\-]* [a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=]*)([\s|\.|\,])/i", " <a href=\"http://$1\" target=\"_blank\">$1</a>$2", $text); // match name@address $text = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]* \@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/i", " <a href=\"mailto://$1\">$1</a>$2", $text); return $text; } ?> For example, when attempting to extract http://www.google.com from a string, it gets "http://www.google" and nothing else. I am not very familiar with regular expressions, so if someone could tell me how to tweak the expressions to include the TLD (and any info after the domain - get variables, etc.), it would be greatly appreciated.
  6. Still isn't working. Don't quite understand why this is causing such an issue. I've also tried every combination of using ob_start, but still get similar errors, or no data.
  7. Thanks for the quick reply. I've never used ob_start or flush before, though I've read about them in the php manual. Which page(s) am I using them on, and do I need to include anything specific with them?
  8. I'm attempted to put together a simple chat script based solely on PHP/MySQL. I'm using iframes to juggle the chat window, and the list of users currently online, however, I keep running into problems. I've worked with iframes and php together before and never experienced these issues, so I'm stumped. I've got most of the site-wide functions grouped into a single file, for easy access, and have been requiring this file on each page where the functions will be used. This also includes my MySQL connection script. Using session_start and require on the parent page works fine, however, if I attempt to use either on the iframe source pages, I get a "session already started" error, and a "cannot redeclare XXXX function" error respectively. However, if I comment out the session_start or the require, the iframe source no longer recognizes the session variables, or the previously declared functions. I don't know what I'm doing wrong, and I'm sure it's something remarkably simple, but I've been going nuts trying to solve this for several hours now. Below are the affected snippets: INDEX.PHP (the parent page for the chat frames) <? session_start(); require("../scripts/includes.php"); if(!isset($_SESSION['chat_id'])) $_SESSION['chat_id']=generate_chat_id(); ?> ... <iframe src="chat_window.php" scrolling="auto" name="chat_window" id="chat_window"></iframe> <iframe src="online.php" scrolling="auto" name="online" id="online"></iframe> <div id="controls"> <form method="post" action="chat_window.php" target="chat_window"> <textarea name="msg" id="chat_msg"></textarea> <input type="hidden" name="chat_id" value="<? print $_SESSION['chat_id']; ?>" /> <input type="submit" value="Submit" name="send" id="submit_button" /> </form> </div> CHAT_WINDOW.PHP (displays the chat dialogue) <? session_start(); require("../scripts/includes.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body bgcolor="#FFFFFF"> <? $chat=get_chat($_SESSION['chat_id']); for($i=0;$i<count($chat);$i++) { if($chat[$i]['uid']==$_SESSION['uid']) $other_style=" blue"; else $other_style="red"; if(isset($_SESSION['admin'])) $a="admin"; else $a=""; print "<span class=\"dialogue\"><span class=\"username".$other_style."\">".get_username_from_id($chat[$i]['uid'],$a)." <span class=\"small\">(".date("m/d/Y h:i:sA",$chat[$i]['timestamp']).")</span> <span class=\"text\">".$chat[$i]['dialogue']."</span></span>"; } print time(); ?> </body> </html> ONLINE.PHP (displays the users online) <? session_start(); require("../scripts/includes.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body bgcolor="#FFFFFF"> <? $online=get_users_online(); for($i=0;$i<count($online);$i++) { print "<span class=\"online\"><a href=\"?u=".$online[$i]."&invite&new_chat\">".$online[$i]."</a></span>"; } ?> </body> </html> INCLUDES.PHP (running list of all required scripts) <? require("mysql.php"); require("functions.php"); require("online.php"); ?> Any and all help with this would be appreciated. Happy holidays!
  9. Thanks for all the replies and advice.  I actually figured out my problem.  I know I could have tried using the command line, or a cron job, but, this was part test, part experiement for me, to see if I could do it, as I'm still kind of a novice when it comes to PHP. I don't quite remember how I figured it out, because I started over from scratch, and tried recreating the code from memory, but obviously, I made some change that fixed everything. Thanks again for the help.
  10. I'm trying to create a PHP MySQL backup script to backup some important databases I've got.  I've pretty much got everything set up all right, and it seems to be exporting text to the browser window (later on a backup file), except in some situtations where a specific table has a large number of fields, when trying to print the contents of each table. The script works.  Some tables, which have only a few fields, less than 15 or so, print fine, table structure, and table contents, however, there are a few tables which have somewhere in the neighborhood of 80-100 fields, and when PHP goes to print the results of the query, I am faced with the error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in g:\Apache\Apache\htdocs\www\ed_db\untitled-1.php on line 50" [code]line 50:  while($row=mysql_fetch_array($query,MYSQL_NUM)) {[/code] This only occurs on these larger tables, so the question is, is there a limit to the size of the array generated by mysql_fetch_array?  And if so, how can I work around this? Thanks.
×
×
  • 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.