PHP - Moved: How Would You Make A Cleaner Url?
This topic has been moved to mod_rewrite.
http://www.phpfreaks.com/forums/index.php?topic=315050.0 Similar TutorialsHI, My code works but I was wondering if there's a simpler/cleaner way to code it ... Code: [Select] <?php require_once('config.php'); // code to get data form database mysql_select_db($database, $makeconnection); $sql_get_categories = " SELECT * FROM tbl_categories ORDER BY category_id ASC"; $get_categories = mysql_query($sql_get_categories, $makeconnection) or die(mysql_error()); $row_get_categories = mysql_fetch_assoc($get_categories); $totalRows_get_categories = mysql_num_rows($get_categories); // i named the 3 fields form the form in the HTML so i can update them into the tadabase $category_1 = $_POST['category_1']; $category_2 = $_POST['category_2']; $category_3 = $_POST['category_3']; //updating the databse if (isset($_POST['submitted_categories'])&&($_POST['submitted_categories'] == "yes")) { $register_query = "SELECT category_id FROM tbl_categories WHERE category_id='$category_id'"; mysql_select_db($database, $makeconnection); $sql_modify1 = ("UPDATE `tbl_categories` SET `category_name` = '$category_1' WHERE `category_id` =1"); $sql_modify2 = ("UPDATE `tbl_categories` SET `category_name` = '$category_2' WHERE `category_id` =2"); $sql_modify3 = ("UPDATE `tbl_categories` SET `category_name` = '$category_3' WHERE `category_id` =3"); $Result1 = mysql_query($sql_modify1, $makeconnection) or die(mysql_error()); $Result2 = mysql_query($sql_modify2, $makeconnection) or die(mysql_error()); $Result3 = mysql_query($sql_modify3, $makeconnection) or die(mysql_error()); header ("Location: the-rest.php"); } ?> here's the form in the html part Code: [Select] <!--CATEGORIES --> <h2>Categories</h2> <form action="" method="post" enctype="multipart/form-data" name="category-form" id="category-form"> <?php do { ?> <h3><input class="user-form-input" id="category_<?php echo $row_get_categories['category_id'];?>" name="category_<?php echo $row_get_categories['category_id'];?>" type="text" value="<?php echo $row_get_categories['category_name'];?>" /></h3> <?php } while ($row_get_categories = mysql_fetch_assoc($get_categories)); ?> <input name="submitted_categories" type="hidden" id="submitted_categories" value="yes" /> <input name="submit" type="submit" class="button-save" id="submit" value="update categories"/> </form> <!--END OF CATEGORIES--> I have a method where the operator condition started getting too long and was becoming difficult to understand and troubleshoot. private function validateCallbackRequest():self { if($this->params->xyz < 3 || isset($this->x->bla['hi']) || soOnAndSoOnAndSoOn) { throw new Exception('Invalid params'); } return $this; } I could break it into sections, but would rather not duplicate all the exception throwing. private function validateCallbackRequest():self { if($this->params->xyz < 3 || isset($this->x->bla['hi'])) { throw new Exception('Invalid params'); } if(soOnAndSoOnAndSoOn) { throw new Exception('Invalid params'); } return $this; } I could assign variables, but don't really care for this all that much. private function validateCallbackRequest():self { $initialStuff=$this->params->xyz < 3 || isset($this->x->bla['hi']); $otherStuff=soOnAndSoOnAndSoOn; if($initialStuff || $otherStuff) { throw new Exception('Invalid params'); } return $this; }
Any recommendations? This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=307669.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=348155.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310894.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316783.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=347193.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349338.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349030.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=354321.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349726.0 This topic has been Ctrl+X/Ctrl+V'd to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=347400.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317523.0 Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way? Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. Hi I just wanted to know how I can make this.... I want to write this in PHP, I dont know the best way to do this.... I am starting a software development company, Each time someone make a purchase of a software product I wan to include a cd key, I dont know how to include just one cd key... I want to place the cdkeys in a mysql db though which I know how to do, but just the fact of me taking only one cdkey out of it and it can't be used already... it has to go down the line how would I do this? Thanks ahead of time Basically, All I want to do is save a .txt (doesn't have to be .txt) to my FTP and PHP simple echos it. The .txt is where a message is stored. But when I write the message my self like this: Hello This is a message. - And then upload it to my FTP, PHP echos it like this "HelloThis is a message". Is there anyway for PHP to notice the 'white space'? --OR-- If you know of a better way to make a message system, then also let me know Thanks, Ollie! ok I need to know how to do this say I have variables.. like so $a[] = 12345; $a[] = 23456; $a[] = 35424; what do I have to do to get those variables to combine the value? and make that a variable? so it would be like $aCompiled = 12345,23456,35424, puts them in a string then I can use the variable later on in the script.. So I'm trying to make a counter that counts how many times a record on mysql database has been viewed. Not a hit counter for a webpage. In other words I have a page that displays the info of that record from the mysql database and within that page I would like to display the amount of times it has been viewed. Would anyone know where I can begin or send me to a good tutorial? Thanks |