ABuchan Posted March 2, 2009 Share Posted March 2, 2009 The basic function of this is to create static pages from dynamic content, there are 1249 entries in the database that need this operation done on them, i figured a for loop would work nicely with $PK moving up by one each time. please note that i am not trained as a programmer, this is just brute force coding. the output i get is just one file, number 1 and then it stops executing. any help would be appreciated. code is attached, and the loop declaration is below. If anyone could provide me with a way to make this work for($PK=1; $PK<1250; $PK += 1) { stuff that sends queries, and builds html} [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/ Share on other sites More sharing options...
xerodefect Posted March 2, 2009 Share Posted March 2, 2009 The basic function of this is to create static pages from dynamic content, there are 1249 entries in the database that need this operation done on them, i figured a for loop would work nicely with $PK moving up by one each time. please note that i am not trained as a programmer, this is just brute force coding. the output i get is just one file, number 1 and then it stops executing. any help would be appreciated. code is attached, and the loop declaration is below. If anyone could provide me with a way to make this work for($PK=1; $PK<1250; $PK += 1) { stuff that sends queries, and builds html} Your looping function is working but may I suggestion putting the for($PK=1; $PK<1250; $PK += 1) { above ### CREATE OUTPUT FILE try that? else its something in your script messing it up, Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774363 Share on other sites More sharing options...
ABuchan Posted March 2, 2009 Author Share Posted March 2, 2009 Thank you for you reply, unfortuanately that still only goes through the function for the value 1. What sort of things would cause this? Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774368 Share on other sites More sharing options...
corbin Posted March 2, 2009 Share Posted March 2, 2009 break; or exit; Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774373 Share on other sites More sharing options...
ABuchan Posted March 2, 2009 Author Share Posted March 2, 2009 I dont have any of those, i really can't think of _anything_ that i put in there that would interupt a loop... Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774378 Share on other sites More sharing options...
genericnumber1 Posted March 2, 2009 Share Posted March 2, 2009 Are you changing the value of $PK? Only break, exit, die and changing the value of $PK inside of the loop would cause the loop to break... unless of course you're getting a fatal error and you don't have show errors on. Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774383 Share on other sites More sharing options...
ABuchan Posted March 2, 2009 Author Share Posted March 2, 2009 would i have had to do something to turn show errors on? if show errors is on by default, and those are the only things that would cause the loop to break, then i guess $PK must be changing somehow, but the only times i am using it is to create a file using fopen, in the WHERE statement of 4 queries, and as part of an echo message to let me know whether it is working or not. Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774386 Share on other sites More sharing options...
genericnumber1 Posted March 2, 2009 Share Posted March 2, 2009 Can you show us your code? Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774387 Share on other sites More sharing options...
ABuchan Posted March 2, 2009 Author Share Posted March 2, 2009 sure. I just truncated earlier... for the sake of truncation i guess... also there are large areas that have been commented out, they are features that will be implemented later. like when i have the time to go around taking 1300 pics. <?php #function acc_page_generate($PK) # { ### MySQL Login details go here $user="XXXXX"; $password="XXXXX"; $database="XXXXX"; $rs = mysql_connect('localhost', $user, $password); if (!$rs) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); ### Place directory paths here $rootdir = '/home/greenhouse/html/'; $imagedir = '/home/greenhouse/html/images/'; for($PK=1; $PK<1250; $PK += 1) { ### CREATE OUTPUT FILE $file_spec = $rootdir.$PK.'.html'; $accfile = fopen($file_spec,'w'); ### BEGIN OUTPUTTING HTML CODE $strout = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.chr(10); $result=fwrite($accfile,$strout); ### GENERATE TITLE HTML $sql = 'SELECT `genus_spec` , `common` , `phylum` , `class` , `category` , `subclass` , `order` , `family` , `origin` , `ID` , `quantity` , `usda_num` , `authority` , `room` , `PK` FROM `specimen` WHERE `PK` ='.$PK; $sql_result=mysql_query($sql); if (!$sql_result) { echo mysql_error(); } $i=0; ### We use the following in numerous locations so assign to dedicated variables $name = mysql_result($sql_result,$i,genus_spec); $family = mysql_result($sql_result,$i,family); $room = mysql_result($sql_result,$i,room); echo 'creating output file: '.$PK.'.html - '.$name.chr(10); $strout = '<TITLE>'.mysql_result($sql_result,$i,genus_spec).' '.mysql_result($sql_result,$i,family); $strout = $strout.' '.mysql_result($sql_result,$i,common).'</TITLE>'.chr(10); $result=fwrite($accfile,$strout); ### CREATE META TAGS $strout = '<HEAD><META NAME="description" CONTENT="Ohio State Biological Sciences Greenhouse Data page for '.mysql_result($sql_result,$i,genus_spec); $strout = $strout.' :: Location: '.mysql_result($sql_result,$i,room); ### Check for images $imagemask=$imagedir.'byspecies/'.strtr($name," ","_").'*.jpg'; $imagearray=glob($imagemask); if (count($imagearray)>0) $strout = $strout.' :: '.count($imagearray).' Image(s) available'; $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'.chr(10); $result=fwrite($accfile,$strout); ### ADD KEYWORDS $strout = '<META NAME ="keywords" CONTENT="'; $strout=$strout.mysql_result($sql_result,$i,genus_spec); $strout=$strout.' '.mysql_result($sql_result,$i,common); $strout=$strout.' '.mysql_result($sql_result,$i,origin); $strout=$strout.' '.mysql_result($sql_result,$i,family).'">'.chr(10); $result=fwrite($accfile,$strout); ### INCLUDE HTML HEADER FILE ### Elements common to all web pages $i=0; $strout = '<link href="designin.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" media="all" type="text/css" href="dropdown.css" /> <!--[if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColElsRtHdr #sidebar1 { padding-top: 30px; } .twoColElsRtHdr #mainContent { zoom: 1; padding-top: 15px; } /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> </head> <body class="twoColElsRtHdr"> <div id="container"> <div id="header"> <center><table width="704" border="0" cellpadding="0"> <tr> <td width="162"><div id="header"><img src="randim.php" height="164" width="162" /></td> <td width="449"><h2> Biological Sciences Greenhouse</h2>322 W.12th Avenue<br /> Columbus, OH 43210-1293<br /> 614-292-7904 Greenhouse<br />614-292-9634 Insectary</td> <td width="85"><a href="http://osu.edu"><img src="osulogo.jpg" alt="The Ohio State University" width="81" height="82" align="top" /></a> </td> </tr> </table></center> <div id="nav"> <ul class="select"> <ul class="select"><a href="index.html">Home</a></ul> <ul class="select"><li><a href="about.htm">About Us <!--[if IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"> <li><a href="about.htm">General Information</a></li> <li><a href="conservatory.htm">Conservatory</a></li> <li><a href="insects.htm">Insectary</a></li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--></li></ul> <ul class="select"><li><a href="#">Programs <!--[if IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"> <li><a href="tours.htm">Tours</a></li> <li><a href="courses.htm">Courses</a></li> <li><a href="http://www.biosci.ohio-state.edu/~plantbio/Facilities/abrc/abrchome.htm">ARBC</a></li> <li><a href="prc.htm">Plant Rescue Center</a></li> <li><a href="research.htm">Research</a></li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--></li></ul> <ul class="select"><li><a href="">Staff <!--[if IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"> <li><a href="joan.htm">Joan Leonard</a></li> <li><a href="emily.htm">Emily Yoders-Horn</a></li> <li><a href="george.htm">George Keeney</a></li> <li><a href="students.htm">Student Staff</a></li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--></li></ul> <ul class="select"><li><a href="plantdb.htm">Collections <!--[if IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"> <li><a href="plantdb.htm">Plants</a></li> <li><a href="insectlist.htm">Insects</a></li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--></li></ul> <ul class="select"><li><a href="#">User Pages <!--[if IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"> <li><a href="rules.htm">Greehouse Guidelines</a></li> <li><a href="wps.htm">WPS Training</a></li> <li><a href="spaceform.pdf">Space Request Form</a></li> <li><a href="environform.pdf">Environmental Programming Requests</a></li> <li><a href="spacefees.htm">Space Fees</a></li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--></li></ul> </ul> <!-- end #header --> </div> </div> <div id="mainContent">'; $result = fwrite($accfile,$strout); #### #### Family select dropdown currently disabled in lieu of search function #### - see topnavbar in ghmaster #### - #### ### BUILD FAMILY DROP DOWN MENU #$strout = mysql_result($sql_result,$i,dropdown).chr(10); #$result=fwrite($accfile,$strout); #$strout = '<option selected>Select Plant Family</option>'.chr(10); #$result=fwrite($accfile,$strout); #$sql = 'select specimen.genus_spec,specimen.genus_spec,famcomm.family '; #$sql=$sql.'from gh_inv inner join classify on gh_inv.genus=classify.genus '; #$sql=$sql.'inner join famcomm on specimen.family=famcomm.family '; #$sql=$sql.'where gh_inv.projnum="GEN_COLL" '; #$sql=$sql.'order by famcomm.family'; #$sql_result=mysql_query($sql); #if (!$sql_result) { # echo mysql_error(); #} #$num=mysql_numrows($sql_result); #$i=0; #$tempfam=''; #while ($i<$num) { # if (mysql_result($sql_result,$i,family)<>$tempfam){ # $strout='<option value="'; # $strout=$strout.mysql_result($sql_result,$i,PK).'.html">'; # $result=fwrite($accfile,$strout); # $strout=mysql_result($sql_result,$i,family).'</option>'.chr(10); # $result=fwrite($accfile,$strout); # } #$tempfam=mysql_result($sql_result,$i,family); #$i++; #} #$strout = '</select></form></td></tr></table>'; #$result=fwrite($accfile,$strout); ### PLACE FAMILY LISTING CODE ### - Left main column of page $strout = '<table width="100%"><tr>'; $result=fwrite($accfile,$strout); $strout = '<td bgcolor="#1B771B" width="20%" align="left" valign="top" style="padding: 20px;">'; $result=fwrite($accfile,$strout); ### Suspend search engine Indexing ### - otherwise search for species X will return all species in family $strout = '<!-- ISEARCH_END_INDEX -->'; $result=fwrite($accfile,$strout); $strout = '<h1>'.$family.'</h1>'; $result=fwrite($accfile,$strout); $sql = 'SELECT `genus_spec` , `common` , `family` , `authority` , `PK` FROM `specimen` WHERE `family` ='."'$family'"; $sql_result=mysql_query($sql); if (!$sql_result) { echo mysql_error(); }else { $num=mysql_numrows($sql_result); $i=0; $strout = '<ul>'; $result=fwrite($accfile,$strout); $strout = chr(10).'<li><a href="'.mysql_result($sql_result,$i,PK).'.html">'; $strout = $strout.mysql_result($sql_result,$i,genus_spec).'</a>'; $result=fwrite($accfile,$strout); } $strout = '</ul><font color="GREEN">W/C</font> = <i>Wild Collected</i></td>'.chr(10); $result=fwrite($accfile,$strout); ### Resume Indexing $strout = '<!-- ISEARCH_BEGIN_INDEX -->'; $result=fwrite($accfile,$strout); ### START SECOND COLUMN $strout = '<td width="80%" align="left" valign="top" style="padding: 20px;">'.chr(10); $result=fwrite($accfile,$strout); $sql = 'SELECT `authority` FROM `specimen` WHERE `PK` ='.$PK; $sql_result=mysql_query($sql); if (!$sql_result) { echo mysql_error(); } $i=0; $strout = '<FONT SIZE=+2><B>'.$name.'</B><I> '.mysql_result($sql_result,$i,authority).'</I></FONT><P>'; $result=fwrite($accfile,$strout); ### MAIN DATA SECTION $sql = 'SELECT `genus_spec` , `common` , `origin` , `authority` FROM `specimen` WHERE `PK` ='.$PK; $sql_result=mysql_query($sql); if (!$sql_result) { echo mysql_error(); } $i=0; $strout = '<FONT SIZE=2>'.chr(10).'<UL><LI>Query '; $result=fwrite($accfile,$strout); ### IPNI Search $strout = '<a href="http://www.ipni.org/ipni/plantsearch?find_wholeName='; $strout = $strout.trim(mysql_result($sql_result,$i,genus_spec)); $strout=$strout.'&find_searchAll=&find_family=&find_infrafamily=&find_genus=&find_infragenus='; $strout = $strout.'&find_isAPNIRecord=on&find_species=&find_infraspecies=&find_isGCIRecord=on'.chr(10); $result=fwrite($accfile,$strout); $strout='&find_authorAbbrev=&find_publicationTitle=&find_isIKRecord=on&find_rankToReturn=all'; $strout=$strout.'&output_format=normal&find_includePublicationAuthors=on&find_includePublicationAuthors=off'; $strout=$strout.'&find_includeBasionymAuthors=on&find_includeBasionymAuthors=off&find_sortByFamily=on'; $strout=$strout.'&find_sortByFamily=off&query_type=by_query&back_page=query_ipni.html" TARGET="_blank">IPNI</a>'.chr(10); $result=fwrite($accfile,$strout); $strout = '<LI><B>Common Name: </B>'.mysql_result($sql_result,$i,common).'<LI><B>Family: </B>'.$family; $result=fwrite($accfile,$strout); $tempstr = mysql_result($sql_result,$i,authority); IF (!EMPTY($tempstr)){ $strout=' <I>'.mysql_result($sql_result,$i,authority).'</I>'; $result=fwrite($accfile,$strout); } $strout='</UL><P>'.chr(10).'<UL>'; $result=fwrite($accfile,$strout); $strout='<LI><B>Country of Origin: </B>'.mysql_result($sql_result,$i,origin).chr(10); $result=fwrite($accfile,$strout); $strout='</UL><P>'; $result=fwrite($accfile,$strout); ### ACCESSION IMAGES SECTION /*$strout = '<h6>Images of this accession: <i>{and/or its current location}</i></h6><p> <br>'; $result=fwrite($accfile,$strout); $imagemask=$imagedir.'byspecies/'.strtr($name," ","_").'*.jpg'; $imagearray=glob($imagemask); foreach (glob($imagemask) as $filename) { ### regenerate thumbnails only if thumbnail is older than source image if (!file_exists($imagedir.'byspecies/thumb/'.basename($filename)) or (filemtime($imagedir.'byspecies/'.basename($filename)) > filemtime($imagedir.'byspecies/thumb/'.basename($filename)))) { ### Regenerate thumbnail images from large images $width = 200; $height = 150; list($width_orig, $height_orig) = getimagesize($filename); $reduction_ratio = $height_orig/150; $width = intval($width_orig/$reduction_ratio); $height=$height_orig/$reduction_ratio; echo 'resampling '.$filename.' from '.$width_orig.'x'.$height_orig.' to '.$width.'x'.$height.chr(10); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p,ereg_replace('/byspecies/','/byspecies/thumb/',$filename), 100); imagedestroy($image); } ### output file info $strout=ereg_replace('home/','<a href="http://plants.biosci.ohio-state.edu/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout=ereg_replace('home/images/byspecies/','<img vspace=20 hspace=20 height=150px src="http://plants.biosci.ohio-state.edu/images/byspecies/thumb/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout = '</img></a> '; $result=fwrite($accfile,$strout); } ### Repeat for map images $imagemask=$imagedir.'maps/'.$PK.'*.jpg'; foreach (glob($imagemask) as $filename) { ### regenerate only if thumbnail is older than source image if (!file_exists($imagedir.'maps/thumb/'.basename($filename)) or (filemtime($imagedir.'maps/'.basename($filename)) > filemtime($imagedir.'maps/thumb/'.basename($filename)))) { ### Regenerate thumbnail images from large images $width = 200; $height = 150; list($width_orig, $height_orig) = getimagesize($filename); $reduction_ratio = $height_orig/150; $width = intval($width_orig/$reduction_ratio); $height=$height_orig/$reduction_ratio; echo 'resampling '.$filename.' from '.$width_orig.'x'.$height_orig.' to '.$width.'x'.$height.chr(10); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p,ereg_replace('/maps/','/maps/thumb/',$filename), 100); imagedestroy($image); } ### output file info $strout=ereg_replace('/var/www/html/','<a href="http://plants.biosci.ohio-state.edu/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout=ereg_replace('/var/www/html/images/maps/','<img vspace=20 hspace=20 height=150px src="http://plants.biosci.ohio-state.edu/images/maps/thumb/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout = '</img></a> '; $result=fwrite($accfile,$strout); } ### Repeat for location images $imagemask=$imagedir.'location/'.$room.'*.jpg'; foreach (glob($imagemask) as $filename) { ### regenerate only if thumbnail is older than source image if (!file_exists($imagedir.'location/thumb/'.basename($filename)) or (filemtime($imagedir.'location/'.basename($filename)) > filemtime($imagedir.'location/thumb/'.basename($filename)))) { ### Regenerate thumbnail images from large images $width = 200; $height = 150; list($width_orig, $height_orig) = getimagesize($filename); $reduction_ratio = $height_orig/150; $width = intval($width_orig/$reduction_ratio); $height=$height_orig/$reduction_ratio; echo 'resampling '.$filename.' from '.$width_orig.'x'.$height_orig.' to '.$width.'x'.$height.chr(10); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p,ereg_replace('/location/','/location/thumb/',$filename), 100); imagedestroy($image); } ### output file info $strout=ereg_replace('/var/www/html/','<a href="http://plants.biosci.ohio-state.edu/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout=ereg_replace('/var/www/html/images/location/','<img vspace=20 hspace=20 height=150px src="http://plants.biosci.ohio-state.edu/images/location/thumb/',$filename); $strout = $strout.'">'; $result=fwrite($accfile,$strout); $strout = '</img></a> '; $result=fwrite($accfile,$strout); } */ ### CLASSIFICATION SECTION $sql = 'SELECT `phylum` , `class` , `subclass` , `order` , `family` FROM `specimen` WHERE `PK` ='.$PK; $sql_result=mysql_query($sql); if (!$sql_result) { echo mysql_error(); } $i=0; $strout='</ul><h6>Classification:</h6><p><UL>'; $result=fwrite($accfile,$strout); $strout='<LI><B>Division: </B>'.mysql_result($sql_result,$i,phylum).chr(10); $result=fwrite($accfile,$strout); $strout='<LI><B>Class: </B>'.mysql_result($sql_result,$i,1).chr(10); $result=fwrite($accfile,$strout); $strout='<LI><B>SubClass: </B>'.mysql_result($sql_result,$i,subclass).chr(10); $result=fwrite($accfile,$strout); $strout='<LI><B>Order: </B>'.mysql_result($sql_result,$i,order).chr(10); $result=fwrite($accfile,$strout); $strout='<LI><B>Family: </B>'.mysql_result($sql_result,$i,family).chr(10); $result=fwrite($accfile,$strout); $strout='</ul>'.chr(10); $result=fwrite($accfile,$strout); ### END OF MAIN DATA SECTION $strout = '</td></TR></TABLE>'; $result=fwrite($accfile,$strout); ### FOOTER CODE $strout = '</div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" /> <div id="footer"> <p><a href="http://www.biosci.ohio-state.edu/">College of Biological Sciences</a> <a href="http://www.biosci.ohio-state.edu/~plantbio/plantbio.html">Plant Biology Page</a> </p> <!-- end #footer --></div> <!-- end #container --></div>'; $result=fwrite($accfile,$strout); $strout = '</FONT></BODY>'; $result=fwrite($accfile,$strout); # CLOSE THE OUTPUT FILE fclose($accfile); ### CLOSE OUTPUT FILE mysql_close($rs); return true; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774389 Share on other sites More sharing options...
genericnumber1 Posted March 2, 2009 Share Posted March 2, 2009 You have return true; INSIDE of your loop, that's what's doing it. Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774391 Share on other sites More sharing options...
ABuchan Posted March 2, 2009 Author Share Posted March 2, 2009 thanks! I should probably shedule myself for some programming courses next term if im going to keep this up i guess... I feel really stupid for not knowing that... sorry for taking up your time like that, but thank you very much for helping me! Quote Link to comment https://forums.phpfreaks.com/topic/147515-solved-for-loop-not-looping/#findComment-774392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.