Jump to content

php server go down when i run this page


bluetoother
 Share

Recommended Posts

<table cellpadding="0" cellspacing="0"><tr><td colspan="2"><font size="5"><?php echo getcoursename($_GET['course_id']);?></font></td><td align="right"><a href="#" onClick="java script:window.print()" class="prntlnk">						<img border="0" src="images/print.gif"><br>						print</a></td>						</td></tr><tr><td class="header_cell" width="200">Title</td><td width="350" class="header_cell">Learning Objectives</td><td width="50" class="header_cell">Duration</td></tr><?php$rs=odbc_exec($conn,"SELECT * FROM Course_Lessons WHERE CID=".$_GET['course_id']);if(!$rs)exit("wrong course number");while(odbc_fetch_row($rs)){$lesson_arr[]=odbc_result($rs,"Less_ID");}//whilefor($x=0;$x<sizeof($lesson_arr);$x++){$rs=odbc_exec($conn,"SELECT * FROM Lesson WHERE L_ID=".$lesson_arr[$x]);if(!$rs) echo "<tr><td colspan='3' class='cell_content'>wrong lesson</td></tr>";$lo=odbc_result($rs,"Learning_Obj");?><tr><td class="cell_content" valign="top"><?php echo odbc_result($rs,"Title"); ?></td><td class="cell_content" valign="top"><?php echo str_ireplace(";","",str_ireplace("\r","<br>",$lo)); ?><br></td><td class="cell_content" valign="top" align="center"><?php echo odbc_result($rs,"Duration_in_hrs"); ?></td></tr><?php}//for?></table>

why this happensdo i fill php parameters so it goes down?am i giving the php overwork?in some cases the fields that i read data from contain some big amount of textreading from database became slower when i added str_ireplace functionis it ODBC ?WTF

Link to comment
Share on other sites

Hi... Everything looks fine but try to debug/dump your code line by line.. what r u getting in all $rs and whether u r getting result properly or not..?Regards,Vijay

Link to comment
Share on other sites

There are some things you are doing that are not efficient. First, with this:

$rs=odbc_exec($conn,"SELECT * FROM Course_Lessons WHERE CID=".$_GET['course_id']);if(!$rs)exit("wrong course number");while(odbc_fetch_row($rs)){$lesson_arr[]=odbc_result($rs,"Less_ID");}//while

You don't need to select *, you only need Less_ID. It takes more time and memory to get everything from the database, so only get what you need.After that, you build the $lesson_arr array, and then loop through it to do another query on the Lesson table. So, if there are 100 results from the first query, then you are sending 100 more queries to the database. That is also going to take more time. And again, the second query you select * where you only use 3 fields. I'm not sure of the structure of the table, but you will want to select only what you need there as well.If you have the CID, and you want to get all lessons in the course, you can do that with one query, you don't need to do one to get all the lesson IDs, then a second for the lesson information. You can do that like this:

$rs=odbc_exec($conn, "SELECT l.L_ID, l.Learning_Obj, l.Title, l.Duration_in_hrs  FROM Course_Lessons AS c, Lessons AS l WHERE c.CID=" . intval($_GET['course_id']) . " AND c.Less_ID = l.L_ID ORDER BY l.L_ID, l.Title");if(!$rs)  exit("wrong course number");while(odbc_fetch_row($rs)){  $lo=odbc_result($rs,"Learning_Obj");  ?>  <tr><td class="cell_content" valign="top"><?php echo odbc_result($rs,"Title"); ?></td><td class="cell_content" valign="top"><?php echo str_replace(array(";", "\r"), array("", "<br>"), $lo); ?><br></td><td class="cell_content" valign="top" align="center"><?php echo odbc_result($rs,"Duration_in_hrs"); ?></td></tr>  <?php}

You also don't need to use str_ireplace, you are just replacing punctuation characters so the replace does not need to be case-insensitive. It will take more time that way. You can use str_replace instead. You also don't need to use str_replace twice, you can send the search and replace parameters as arrays to replace both at once.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...