Jump to content

m.adel

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

m.adel's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hello I'm a php developer but my javascript and my ajax experience is not good and i want a little help here is a simple code to re-arrange table rows sorting depending on the pos value which stored in mySQL db .. it works fine but if the user reload the page or pressed enter after the operation it will cause errors by duplicating the pos value .. any way please review my simple code and modify it to work fine <?php require_once('../../config.php'); require_once('../../inc/functions.php'); define('PAGE_NAME','view Categories'); include('../admin_header.php'); if (isset($_GET['editCC'])){ $sel_parent_info = sql_query('pos', $_GET['nPos'], 'categories'); $id = $_GET['editCC']; $nPos = $_GET['nPos']; $oPos = $_GET['oPos']; $query = " UPDATE categories SET pos = {$nPos} WHERE id = {$id}"; $result = mysql_query($query, $connection); if ($result) { $query = " UPDATE categories SET pos = {$oPos} WHERE id = {$sel_parent_info['id']}"; $result = mysql_query($query, $connection); if ($result){ $query = "SELECT * FROM categories ORDER BY pos ASC"; $result = mysql_query($query, $connection); } else { $query = " UPDATE categories SET pos = {$oPos} WHERE id = {$id}"; $result = mysql_query($query, $connection); } $count_results = mysql_num_rows($result); } else { $errors[] = "failed to re arrainge <br />" . mysql_error(); } } // get the posted cats $query = "SELECT * FROM categories ORDER BY pos ASC"; $result = mysql_query($query, $connection); $count_results = mysql_num_rows($result); ?> <?php if (!empty($message)) { echo "<div class=\"message\">" . $message ."</div>"; }?> <?php if (!empty($errors)) { display_errors($errors, count($errors)); }?> <div align="center"><h1><?php echo PAGE_NAME." ({$count_results})"; ?></h1></div> <?php if (mysql_num_rows($result) == 0) { echo "<div class=\"alert\">there is no categories</div>"; } else { echo " <h2>All Categories( {$count_results} ) </h2> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr align=\"center\" style=\"color:#FFF\" bgcolor=\"#003366\"> <td>title</td> <td>position</td> <td>created</td> <td>description</td> <td>status</td> <td>photo</td> <td>sub categories</td> <td>Actions</td> </tr>"; if(!$result) { die (mysql_error()); } else { $color="1"; while($cat_info = mysql_fetch_array($result)) { $id = $cat_info['id']; $oPos = $cat_info['pos']; $query1 = "SELECT * FROM sub_categories WHERE parent_id = {$id} ORDER BY pos ASC"; $result1 = mysql_query($query1, $connection); confirm_query($result1); if($color==1){ echo "<tr bgcolor='#999999' onMouseover=\"this.bgColor='#FFFFFF'\"onMouseout=\"this.bgColor='#999999'\"> <td>{$cat_info['name']}</td> <td>{$cat_info['pos']}</td> <td>{$cat_info['date']}</td> <td>{$cat_info['comment']}</td>"; $status = set_type($cat_info['status']); echo" <td>{$status}</td> <td align=\"center\"><img src=\"{$upload_url}{$cat_info['pic']}\" height='100' width='100' alt=\"قسم الـ\" /></td> <td>"; if (mysql_num_rows($result1)>0){ while ($sub_cats = mysql_fetch_array($result1)){ echo " - ".$sub_cats['name']."<br />"; } } else { echo "No sub Categories"; } echo " </td> <td> <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/delete.gif\" width=\"24\" height=\"24\"></a> <a href=\"edit_cat.php?id={$id}\"><img src=\"../images/edit.gif\" width=\"24\" height=\"24\"></a>"; if ($cat_info['pos']<$count_results) { $nPos = $cat_info['pos']+1; echo " <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/down.gif\" width=\"24\" height=\"24\"></a>"; } if ($cat_info['pos']>1) { $nPos = $cat_info['pos']-1; echo " <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/up.gif\" width=\"24\" height=\"24\"></a>"; } echo"</td>"; $color="2"; } else { echo "<tr bgcolor='#CCCCCC' onMouseover=\"this.bgColor='#FFFFFF'\"onMouseout=\"this.bgColor='#CCCCCC'\"> <td>{$cat_info['name']}</td> <td>{$cat_info['pos']}</td> <td>{$cat_info['date']}</td> <td>{$cat_info['comment']}</td>"; $status = set_type($cat_info['status']); echo" <td>{$status}</td> <td align=\"center\"><img src=\"{$upload_url}{$cat_info['pic']}\" height='100' width='100' alt=\"قسم الـ\" /></td> <td>"; if (mysql_num_rows($result1)>0){ while ($sub_cats = mysql_fetch_array($result1)){ echo " - ".$sub_cats['name']."<br />"; } } else { echo "No sub Categories"; } echo " </td> <td> <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/delete.gif\" width=\"24\" height=\"24\"></a> <a href=\"edit_cat.php?id={$id}\"><img src=\"../images/edit.gif\" width=\"24\" height=\"24\"></a>"; if ($cat_info['pos']<$count_results) { $nPos = $cat_info['pos']+1; echo " <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/down.gif\" width=\"24\" height=\"24\"></a>"; } if ($cat_info['pos']>1) { $nPos = $cat_info['pos']-1; echo " <a href=\"{$_SERVER['PHP_SELF']}?editCC={$id}&oPos={$oPos}&nPos={$nPos}\"><img src=\"../images/up.gif\" width=\"24\" height=\"24\"></a>"; } echo"</td>"; $color="1"; } } } } ?> </table> <?php include('../admin_footer.php'); ?>
  2. thanks so much .. indeed i was only need to view period day 1st and i was gonna try to view the period number later .... this solution made it short and easy .. and its really easy to understand the script .. thanks again
  3. hi would you please have a look at this small code .. try and try it in PHP page ... all what i wanna do is making the period day (1,2,3,...10) be printed each 10 days and all what i got is 11 in all lines after too many tries and bugs and errors :-\ i wish u can help me thanks <?php $start_day = strtotime("1 October 2007"); $end_day = strtotime("25 May 2009"); $j = -1; $period = 0; for ($i=$start_day;$i<=$end_day;$i+=86400) { $j++; for($x=1;$x<=10;$x++) { } echo date("d M Y",$i) . " => Army Day :" . $j . " => Period day :" . $x ."<br>"; } ?>
  4. yea thanks so much that was so quick
  5. Hi its easy to fix but i'm noob i know that .. look this script is a part from my project , copy the code and put it in blanck php file and test it u'll know the problem .. cuz i'm not good with the explaining .. thanks <?php $myPeriod = new medosPeriod(); $myPeriod->showPeriod(2008,9,20,"Period One"); $myPeriod->showPeriod(2008,9,30,"Period Two"); $myPeriod->showPeriod(2008,10,10,"Period Three"); $myPeriod->showPeriod(2008,10,20,"Period Four"); $myPeriod->showPeriod(2008,10,30,"Period Five"); $myPeriod->showPeriod(2008,11,9,"Period Six"); $myPeriod->showPeriod(2008,11,19,"Period Seven"); $myPeriod->showPeriod(2008,11,29,"Period Eight"); $myPeriod->showPeriod(2008,12,8,"Period Nine"); $myPeriod->showPeriod(2008,12,18,"Period Ten"); $myPeriod->showPeriod(2008,12,28,"Period Eleven"); $myPeriod->showPeriod(2009,1,8,"Period Twilve"); $myPeriod->showPeriod(2009,1,18,"Period Thirteen"); $myPeriod->showPeriod(2009,1,28,"Period Fourteen"); $myPeriod->showPeriod(2009,2,7,"Period Fifteen"); $myPeriod->showPeriod(2009,2,17,"Period Sixteen"); $myPeriod->showPeriod(2009,2,27,"Period Seventeen"); $myPeriod->showPeriod(2009,3,9,"Period Eighteen"); $myPeriod->showPeriod(2009,3,19,"Period Nineteen"); $myPeriod->showPeriod(2009,3,29,"Period Twintey"); $myPeriod->showPeriod(2009,4,8,"Period Twintey One"); $myPeriod->showPeriod(2009,4,18,"Period Twintey Two"); $myPeriod->showPeriod(2009,4,28,"Period Twintey Three"); $myPeriod->showPeriod(2009,5,8,"Period Twintey Four"); class medosPeriod{ function showPeriod($year,$month,$day,$period){ $fday = getdate(mktime(0,0,0,$month,$day,$year)); $lday = getdate(mktime(0,0,0,$month,$day+10,$year)); echo '<table class="month">'; echo ' <tr><th colspan="10">'.$fday['month']." - ".$fday['year']." ( ".$period." )</th></tr>"; echo ' <tr class="days"><td>Day 1</td><td>Day 2</td><td>Day 3</td><td>Day 4</td><td>Day 5</td><td>Day 6</td><td>Day 7</td><td>Day 8</td><td>Day 9</td><td>Day 10</td></tr>'; echo ' <tr>'; for($i=$fday['mday'];$i<$lday['mday'];$i++){ echo "<td$class>$i</td>"; } echo ' </tr>'; echo ' </table>'; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.