PHP - Is There An Easier Way To Do This, If So How?
$text=$_POST['Txt'];
$strrep1=str_replace('z', 'a', $text); $strrep2=str_replace('y', 'z', $strrep1); This code is a little bit time consuming to do I'm trying to make all the letters one higher, For example "Foo bar" becomes "Gpp Cbs" The reason I'm trying to do this is a long story, But anyway is there an easier way to do it reather than the way I was doing it? And would it work? Similar TutorialsCurrently what I have is this:
$url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); foreach($xml->gms->g as $games) { if(!empty($games['vtn'])) { if ((($games['gt']) =='WC') && (($games['q'])== 'F')) { echo "<li data-subcategory='Final Scores' data-category='Wild Card Games' data-color='1979ab'><a href='#'>",$games['htn']," ",$games['hs']," ",$games['vtn']," ",$games['vs']," Final</a></li>"; } if (($games['gt']) =='DIV') { echo "<li data-subcategory='Final Scores' data-category='Divisional Games' data-color='14ab05'><a href='#'>",$games['htn']," ",$games['hs']," ",$games['vtn']," ",$games['vs']," ",$games['d']," at ",$games['t'], "</a></li>"; } if (($games['gt']) == 'CON') { echo "<li data-subcategory='Conference Games' data-category='Sunday' data-color='000000'><a href='#'>",$games['htn']," ",$games['hs']," ",$games['vtn']," ",$games['vs']," ",$games['d']," at ",$games['t'], "</a></li>"; } } }It works great, Thanks to some help! The only thing I'd like to do now is have the output be a little more inline ...currently it reads the xml line by line and outputs the each item.. the order is the problem... It does this: Wild Card game Wild Card game Div game Div game Conference game Conference game Div game Div game Wild Card game Wild Card game I'd like it to output one type at a time....basically grouping all types together.. WC game Div game Conference game I continue to learn but this one is stumping me... I did get an idea from someone but not sure how to carry this one out... Instead of outputting it directly you could just add it to an array in the first loop So for each game you do $games[$type][] = $game; Then you can add another loop (for output) where you will have them sorted Just not sure how to handle that.. I'm feeling a bit lost at the moment... Is this in reference to putting $games[$type] = $game in place of foreach($xml->gms->g as $games)? I guess the second part has me lost as well adding another loop for output... needing to be sorted because each output is styled differently I guess I'm just not understanding.... can anyone clarify for me please? Thanks everyone! Here is my long drawn out code. Is there a better way of doing this and how can I echo the JS without it messing up the php. I really need the JS link to work! <?php if(isset($_SESSION['rest'])){ echo'<table width="300" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="middle" class="topnav"><div align="center" ><a href="index.php">Home</a></div></td> <td valign="middle" class="topnav"><div align="center"><a href="restpanel.php">User Panel</a></div></td> <td valign="middle" class="topnav"><div align="center"><a href="logout.php">Logout</a></div></td> </tr> </table>';} if(isset($_SESSION['chef'])){ echo' <table width="300" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="middle" class="topnav"><div align="center" ><a href="index.php">Home</a></div></td> <td valign="middle" class="topnav"><div align="center"><a href="chefpanel.php">User Panel</a></div></td> <td valign="middle" class="topnav"><div align="center"><a href="logout.php">Logout</a></div></td> </tr> </table>';} if(!isset($_SESSION['chef']) || !isset($_SESSION['rest'])){ echo "<table width='350' border='0' cellpadding='0' cellspacing='0'> <tr> <td valign='middle' class='topnav'><div align='center'><a href='index.php'>Home</a></div></td> <td valign='middle' class='topnav'><div align='center' >"<a href="javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Log In</a></div></td> <td valign="middle"class="topnav"><div align="center"><a href="register.php">Sign Up</a></div></td> <td valign="middle"class="topnav"><div align="center" ><a href="contact.php">Contact Us</a></div></td> </tr> </table>";} ?> Whenever people are going to update something, they have a list of things to update. Whenever they choose the file they wish to edit/re-upload, they click the [EDIT] link beside it. This takes them to the update page, of course on the same file. They still have edit.php?id=3 in the URL, for example. But whenever they click Submit, how am I suppose to get the ID again? Is there a less junky way to do it then this: if(!$_GET['id'] && $_POST['id']) { $id = $_POST['id']; } elseif($_GET['id'] && !$_POST['id']) { $id = $_GET['id']; } else { } I have about 350 rows that I have to update a single column in each row. I coded so I can do each row individually but I was wondering if there is a way to update all of them at once. Hence saving me time. This is my code: Code: [Select] <?PHP include "dbmembers.php"; ?> <?php if(isset($submit)){ $ID = mysql_real_escape_string(trim($_POST['ID'])); $result = mysql_query("SELECT response FROM myuser WHERE ID ='$ID'"); $row = mysql_fetch_array($result); $res = hash("sha256", $row['response'] .$salt ); { echo $row['response'] ."----".$res; echo "<br /><br />"; } } mysql_query("UPDATE myuser SET response='$res' WHERE ID = '$ID'"); printf ("Updated records: %d\n", mysql_affected_rows()); ?> Thanks in advance for any advise. Hi , I'm new on this forum so don't judge too hard.. But I have a few questions. I am recently new to PHP as this is my first computer language I've learnt besides HTML. My first question is, what's the difference between !== and !=, and is it more secure to use !== when comparing two fields such as passwords? I've different things and this has confused me.. And my second question is, I have this piece of code Code: [Select] /* option error checking */ $field = "option"; // Use field name for option /* Check if the option picked is from the list of options to choose from*/ if($suboption !== "option1" || $suboption !== "option2" || $suboption !== "option3" || $suboption !== "option4" || $suboption !== "option5" || $suboption !== "option6" || $suboption !== "option7"){ $form->setError($field, "* Unexpected error with option"); } I'm guessing in the long run, this will slow down my script.. is there an easier way of checking without using || $suboption !== and is it okay if I've used !==? Like I said I'm new to this so please don't flame.. I've done some research but I can't seem to find some accurate answer. Thank you, ZT Hello, I'm new to PHP and I have come up with the following code for my navigation but I am sure there has to be an easier and more efficient way to do this. Someone please start me on the right path. Thanks Code: [Select] <?php //Get selected page/sub page if (isset($_GET['page'])) { $sel_page = $_GET['page']; $sel_sub_page = ''; } elseif (isset($_GET['sub_page'])) { $sel_page = ''; $sel_sub_page = $_GET['sub_page']; } else { $sel_page = ''; $sel_sub_page = ''; } ?> Code: [Select] <!--Begin Navigation--> <ul> <?php //run the loop to get the page titles $query = "SELECT * FROM pages ORDER BY position ASC"; $page_set = mysql_query($query); confirm_query($page_set); while($page = mysql_fetch_array($page_set)){ echo '<li><a href="content.php?page=' . urlencode($page['id']) . '">' . $page['page_name'] . '</a></li>'; //run sub page query to see if the ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !=''){ echo '<ul>'; } //run the sub page loop again to display the sub page title $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); while($sub_page = mysql_fetch_array($sub_page_set)) { echo '<li><a href="content.php?sub_page=' . urlencode($sub_page['id']) . '">' . $sub_page['page_name'] . '</a></li>'; } //run the sub page loop for the last time to see if the end ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !='') { echo '</ul>'; } } ?> </ul> <!--End Navigation--> <?php $result = "SELECT * FROM portfolio"; $result = mysql_query ($result) or die (mysql_error()); $i=0; while($row = mysql_fetch_assoc($result)) { if($i==0) echo '<div class="portfolioPage">'; if($i==2) $divclass = 'portfolioProjectWrapper borderWhite'; else $divclass = 'portfolioProjectWrapper borderGray'; echo ' <div class="'.$divclass.'"> <a href="portfolioPage.html" class="image asyncImgLoad" title="img/'.$row['image290x290'].'"></a> <p class="imageDesc">'.$row['image290x290_phot'].'</p> <h3 class="title">'.$row['title'].'</h3> <p class="subtitle">'.$row['subtitle'].'</p> <p class="desc"> '.substr($row['description'], 0, 1200).' <a href="portfolioPage.html" class="commonLink">Read more</a> </p> </div> '; if($i==2) echo '</div>'; if(i==2) $i=0; else $i++; } ?> Please help me im backward at this been along time. HI, 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--> |