munchkinz Posted January 24, 2011 Share Posted January 24, 2011 I'm sure there must be a way to simplify code as it is taking forever. The code is for a form with the results emailed to me. I have attached the files as they are too big to post here [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/225528-new-to-php-is-there-a-way-to-simplify-this-code/ Share on other sites More sharing options...
Maq Posted January 24, 2011 Share Posted January 24, 2011 I don't think many people are going to go through 54kb and 8kb worth of code. If you post specific examples then we could easily help you. There are general rules of thumb to optimize code. Do a search on here for some useful tips, here is a recent thread: http://www.phpfreaks.com/forums/miscellaneous/how-to-optimize-a-php-script/msg1514604/#msg1514604 Quote Link to comment https://forums.phpfreaks.com/topic/225528-new-to-php-is-there-a-way-to-simplify-this-code/#findComment-1164541 Share on other sites More sharing options...
munchkinz Posted January 24, 2011 Author Share Posted January 24, 2011 ok thank you. Here is a snippet of the code <tr><td><label for="LRSofa" id="LRSofa">Sofas:</label></td><td><select name="LRSofa"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select></td> <td><label for="LRArmChair" id="LRArmChair">Arm Chairs:</label></td><td><select name="LRArmChair"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select></td> <td><label for="LROtherChair" id="LROtherChair">Other Chairs:</label></td><td><select name="LROtherChair"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select></td> <td><label for="LRSCabinet" id="LRSCabinet">Small Cabinets:</label></td><td><select name="LRSCabinet"> There are about 150 of these. and this is some snippets of the code i am trying to simplify $LRSofa = Trim(stripslashes($_POST['LRSofa'])); $LRArmChair = Trim(stripslashes($_POST['LRArmChair'])); $LROtherChair = Trim(stripslashes($_POST['LROtherChair'])); $LRSCabinet = Trim(stripslashes($_POST['LRSCabinet'])); $Body .= "Living Room: "; $Body .= "\n"; $Body .= "Sofas: "; $Body .= $LRSofa; $Body .= "\n"; $Body .= "Arm Chairs: "; $Body .= $LRArmChair; $Body .= "\n"; $Body .= "Other Chairs: "; $Body .= $LROtherChair; $Body .= "\n"; $Body .= "Small Cabinets: "; $Body .= $LRSCabinet; $Body .= "\n"; $Body .= "Large Cabinets: "; $Body .= $LRLCabinet; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: ". $FName ." ". $LName ." <". $Email.">"); please ask if you need any more info thank you Quote Link to comment https://forums.phpfreaks.com/topic/225528-new-to-php-is-there-a-way-to-simplify-this-code/#findComment-1164560 Share on other sites More sharing options...
cyberRobot Posted January 24, 2011 Share Posted January 24, 2011 Based on the snippet the form fields look to be the same from product to product. So you could look into creating an associative array for all the different products. Then use a loop to display them. Quote Link to comment https://forums.phpfreaks.com/topic/225528-new-to-php-is-there-a-way-to-simplify-this-code/#findComment-1164575 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.