PHP - Is It Possible To Shorten This?....
Hi everyone,
I know im being really picky here, but im trying to optimize my code, and i was wondering if there is any way i can shorten the following: if ($submit) {echo $name;} else {echo $row['dbname'];} I know it fairly short already however im using it as the value of a html text box. Thanks Similar TutorialsHi, When a user POSTS 10 maps (dropdown), I don't want any two or more being the same. From my knowledge, only way I know of doing this, is this very long messy way: Code: [Select] if($_POST['map1']==$_POST['map2'] || $_POST['map1']==$_POST['map3'] || $_POST['map1']==$_POST['map4'] || $_POST['map1']==$_POST['map5']) etc... then I need to type if $_POST['map2']==$_POST['map1'] etc... How can I put this in its simplest form so that there are no POST duplicates? Thanks for any help.
The $a variable contains the news text. The $link variable contains a link to the page with the full text of this news. change text I need help to shorten the following url in apache .htaccess
example.com/index.php?q=1&w=2
if possible, the url that i would like is...
example.com/index.php/1/2
or better yet...
example.com/index/1/2
Hey all, I really like programming in PHP, but I'm still in the learning process. And mostly, I'm not that good in making my code short. This is now the case again. I have this code which gets a lot of checkboxes, only checkboxes, out of a mysql database, for a planning project. Now the code I have so far, retrieves the checkboxes, which are booleans in the database, and checks if they are True or False and sets the checkboxes respectively to checked="yes" or not. This code works. But I'm here to get tips on how to shorten my code, since it's very repetitive and thus long, which isn't quite efficient. As I said, I'm still in learning process, so I hope you guys understand that I'm looking for help with this. Thanks. EDIT: Okay, I now suddenly see, that I can use elsif for True and False. This would be logical to do, and I can accomplish this easily. But it would be still very repetitive. Here's the code: Code: (php) [Select] <?php while ($row = mysql_fetch_array($result)){ // UNCHECKED if ($row['fact-sent'] == false){ $fact_sent = '<input type="checkbox" />'; } if ($row['fact-payed'] == false){ $fact_payed = '<input type="checkbox" />'; } if ($row['domain'] == false){ $domain = '<input type="checkbox" />'; } if ($row['content'] == false){ $content = '<input type="checkbox" />'; } if ($row['design-sent'] == false){ $design_sent = '<input type="checkbox" />'; } if ($row['design-approved'] == false){ $design_approved = '<input type="checkbox" />'; } if ($row['design-sliced'] == false){ $design_sliced = '<input type="checkbox" />'; } if ($row['temp-website'] == false){ $temp_website = '<input type="checkbox" />'; } if ($row['temp-website-sent'] == false){ $temp_website_sent = '<input type="checkbox" />'; } if ($row['temp-website-approved'] == false){ $temp_website_approved = '<input type="checkbox" />'; } if ($row['cms'] == false){ $cms = '<input type="checkbox" />'; } if ($row['seo'] == false){ $seo = '<input type="checkbox" />'; } if ($row['analytics'] == false){ $analytics = '<input type="checkbox" />'; } if ($row['webmaster-tools'] == false){ $webmaster_tools = '<input type="checkbox" />'; } if ($row['website'] == false){ $website = '<input type="checkbox" />'; } if ($row['website-online'] == false){ $website_online = '<input type="checkbox" />'; } // CHECKED if ($row['fact-sent'] == true){ $fact_sent = '<input type="checkbox" checked="yes" />'; } if ($row['fact-payed'] == true){ $fact_payed = '<input type="checkbox" checked="yes" />'; } if ($row['domain'] == true){ $domain = '<input type="checkbox" checked="yes" />'; } if ($row['content'] == true){ $content = '<input type="checkbox" checked="yes" />'; } if ($row['design-sent'] == true){ $design_sent = '<input type="checkbox" checked="yes" />'; } if ($row['design-approved'] == true){ $design_approved = '<input type="checkbox" checked="yes" />'; } if ($row['design-sliced'] == true){ $design_sliced = '<input type="checkbox" checked="yes" />'; } if ($row['temp-website'] == true){ $temp_website = '<input type="checkbox" checked="yes" />'; } if ($row['temp-website-sent'] == true){ $temp_website_sent = '<input type="checkbox" checked="yes" />'; } if ($row['temp-website-approved'] == true){ $temp_website_approved = '<input type="checkbox" checked="yes" />'; } if ($row['cms'] == true){ $cms = '<input type="checkbox" checked="yes" />'; } if ($row['seo'] == true){ $seo = '<input type="checkbox" checked="yes" />'; } if ($row['analytics'] == true){ $analytics = '<input type="checkbox" checked="yes" />'; } if ($row['webmaster-tools'] == true){ $webmaster_tools = '<input type="checkbox" checked="yes" />'; } if ($row['website'] == true){ $website = '<input type="checkbox" checked="yes" />'; } if ($row['website-online'] == true){ $website_online = '<input type="checkbox" checked="yes" />'; } // OUTPUT echo '<tr><td class="customer">'.$row['project'].'</td><td class="customer">'.$row['customer'].'</td><td class="data">'.$fact_sent.'</td><td class="data">'.$fact_payed.'</td><td class="data">'.$domain.'</td><td class="data">'.$content.'</td><td class="data">'.$design_sent.'</td><td class="data">'.$design_approved.'</td><td class="data">'.$design_sliced.'</td><td class="data">'.$temp_website.'</td><td class="data">'.$temp_website_sent.'</td><td class="data">'.$temp_website_approved.'</td><td class="data">'.$cms.'</td><td class="data">'.$seo.'</td><td class="data">'.$analytics.'</td><td class="data">'.$webmaster_tools.'</td><td class="data">'.$website.'</td><td class="data">'.$website_online.'</td></tr>'; } ?> hello, is it possible to get the 1274 out of the following? Code: [Select] $jobnumber='1009-1274R'; $shortnumber= (this is where i need it to be 1274); Hello all, I am using a simple iframe to include a facebook like box on my webpage. Code: [Select] <iframe src="http://www.facebook.com/plugins/likebox.php?id=<?php echo $pageID;?>&width=<?php echo $width;?>&colorscheme=<?php echo $colorScheme;?>&show_faces=<?php echo $showFaces;?>&connections=<?php echo $connection;?>&stream=<?php echo $streams;?>&header=<?php echo $header;?>&height=<?php echo $height;?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:<?php echo $width;?>px; height:<?php echo $height;?>px;" allowTransparency="true"></iframe> The problem is that I want to limit the title of the facebook page to 15 characters. Any ideas on how I could do this? Hello everyone For a site of one of our customers our programmer created his own CMS which works OK at the site, but now the customer wants to shorten the URLS which are generated by the system. Is this easily possible? The programmer doesn't have the time to help us with it so that's why I try my luck here... I hope somebody can help me. Thanks! Hi all, im trying to shorten this string which cnotains about 1000 characters, to say 250 Code: [Select] <?php echo $row_Best_Sellers['experience_name']; ?> Ive tried using the below to no avail, can anybody give me some advice? Code: [Select] <?PHP $small = some_function($row_Best_Sellers['experience_description']); echo $small; function some_function($string){ $string = substr($string,0,100); $string = substr($string,0,strrpos($string," ")); return $string; } ?> Ok, I have a log file that is written to. I only want the text file to have the last fifty lines (\n) delimited So, how do I make it delete the excess from the TOP of the file? So if it had 60 lines, I would want it to only have lines 10-60 to net 50 total. Thanks. |