Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

i wanted to move records only one up & down onclick up or do

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

i wanted to move records only one up & down onclick up or do

Postby bhaskar1 » Tue Dec 11, 2012 6:55 am

i wanted to move records only one line up & down onclick of up or down link the code is as follows there or 19 recordsthe problem is if i press up link for sixth record it is moving some three records up instead of one record up this happening same down link also:


function showtoplist($show,$type,$field)
{
$SysvarHTML = "";
$recCount = $this->gettoplistRecords($start,$limit,"count",$crit);
$total_count = $recCount;
$max_row = 100;
if($total_count > 0) {
$total_pages = ceil($total_count/$max_row); // total number of pages
} else {
$show = 0;
$total_pages = 0;
}
if($show > $total_pages) {
$show = $total_pages;
}
if($show < 1) {
$show = 1;
$start = 0;
} else {
$start = (($show-1)*$max_row);
}
if($total_count == 0) {
$SysvarHTML .= "
<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" bgcolor=\"\" width = \"550\">
<tr class=\"heading\" height=\"25\" bgcolor = \"\">
<td class=\"heading\"align=\"center\">&nbsp;Top List&nbsp;</td>
<td class=\"heading\"align=\"center\">&nbsp;Add Photo&nbsp;</td>
<td class=\"heading\" align=\"center\">&nbsp;Order</td>
<td class=\"heading\" align=\"center\">&nbsp;Edit&nbsp;</td>
<td class=\"heading\" align=\"center\">&nbsp;Delete&nbsp;</td>
<td class=\"heading\" align=\"center\">&nbsp;Action&nbsp;</td>
</tr>
<tr>
<td class=\"matter\" colspan=\"5\"><center>Records Not Found.</center></td>
</tr></table>";
} else {
$funcResult = $this->gettoplistRecords($start,$max_row,"",$crit);
/*$SysvarHTML .= "

<table width = \"100%\">
<tr>
<td align=\"right\" class=\"text\">Total No. Records :&nbsp; $total_count &nbsp;&nbsp;&nbsp;</font></td>
<td align=\"right\" class=\"text\">Displaying Page $show of $total_pages</td>
</tr>
</table>
";*/
$SysvarHTML .="

<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width = \"600\">
<form name=\"frmwplist\" method=\"post\" action=\"delete_toplist.php\">
<tr class=\"textblacknav\" height=\"25\" >
<td class=\"textblacknav\"align=\"center\">&nbsp;&nbsp;</td>
<td class=\"heading\"align=\"center\">&nbsp;Add Photo&nbsp;</td>
<td class=\"textblacknav\" align=\"center\">&nbsp;Order</td>
<td class=\"textblacknav\" align=\"center\">&nbsp;Edit&nbsp;</td>

<td class=\"textblacknav\" align=\"center\">&nbsp;Action&nbsp;</td>
";
$SysvarHTML .="</tr>";
if(count($funcResult) > 0){
$i = 0;
foreach($funcResult as $fname => $fvalue){
$i++;
$aid = $fvalue['list_listid'];
$SysvarHTML .="
<tr >
<td class=\"matter\">&nbsp;" . $fvalue['list_title'] . "</td>
<td class=\"matter\" valign=\"middle\"><center><a href=\"addtopphoto.php?topid=".$fvalue['list_listid']."\"> <b>Add Photo</b></a></center></td>" ;

if($i == '1' && count($funcResult) == '1') {
$SysvarHTML.= "<td width=\"100\" class=\"matter\" align=\"center\"></td>";
} elseif($i + $start == $total_count){
$SysvarHTML.= "<td class=\"matter\" align=\"center\"><a href=\"".$PHP_SELF."?a_id=".$fvalue['list_listid']."&direction=u&order=".$fvalue['list_order']."&show=".$show."\" class=\"nav\"><center>Up</center></a></td>";
} else {
if($i + $start == '1'){
$SysvarHTML.="<td class=\"matter\" align=\"center\"><a href=\"".$PHP_SELF."?a_id=".$fvalue['list_listid']."&direction=d&order=".$fvalue['list_order']."&show=".$show."\" class=\"nav\"><center>Down</center></a></td>";
} else {
$SysvarHTML.="<td class=\"matter\" align=\"center\"><a href=\"".$PHP_SELF."?a_id=".$fvalue['list_listid']."&direction=u&order=".$fvalue['list_order']."&show=".$show."\" class=\"nav\"><center>Up</a>&nbsp;|&nbsp;<a href=\"".$PHP_SELF."?a_id=".$fvalue['list_listid']."&direction=d&order=".$fvalue['list_order']."&show=".$show."\" class=\"nav\">Down</center></a></td>";
}
}

$SysvarHTML .="
<td align=\"center\" class=\"matter\"><center><a href=\"addtoplist.php?status=edit&list_id=".$fvalue['list_listid']. "\" class=\"nav\">&nbsp;<B>Edit</B>&nbsp;</a></center></td>

<td align=\"center\" class=\"matter\"><center><input type=\"checkbox\" name=\"check[]\" value=\"$aid\"></center></td>
</tr>";
}
}

$SysvarHTML .="<tr valign=\"top\" >
<td align=\"right\" colspan=\"8\"><input type=\"submit\" name=\"submit\" value=\"Delete\" onClick=\"return check_deletetoplist();\"></td>
</tr></form></table></td></tr>";
if ($max_row < $total_count) {
$SysvarHTML .="

<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"100%\">
<tr/>
<td align=\"left\" colspan=\"160\">";
if($show > 1) {
$page = $show - 1;
$SysvarHTML .= "&nbsp;&nbsp;<a href=\"manage_toplist.php?show=$page".$qstring." \" class=\"nav\"><B>Previous</B></a>";
}
$SysvarHTML .= "</td><td align=\"right\" colspan=\"120\">";
if($show < $total_pages) {
$page = $show + 1;
$SysvarHTML .= "<a href=\"manage_toplist.php?show=$page".$qstring."\" class=\"nav\"><B>Next</B></a>&nbsp;&nbsp;";
}
$SysvarHTML .="
</td>
</tr>
</table>
";
}
}
return $SysvarHTML;
}

______________________________________________________________
This how i am calling:
<?php echo $Objlist->showtoplist($_GET['show'],$_GET['type'],$_GET['field'],$_GET['direction']);?>

___________________________________________
required functions:
function gettoplistRecords($start,$limit,$type,$crit = "")
{
if ($type=="count"){
$sqlStmt = "SELECT COUNT(list_listid)as count FROM mp_photos";
$arrResult = $this->getResult($sqlStmt);
return $arrResult[0]['count'];
}
else {
$sqlStmt = "SELECT * FROM mp_photos ORDER BY list_order desc LIMIT $start,$limit ";

$arrResult = $this->getResult($sqlStmt);
return $arrResult;
}
}

_____________________________
function getResult($sql)
{
$conObj = $this->openConnection("local"); // Connection Established
$arrReturnObj = array(); // Define an Array object to return resultset

if ( !($result = mysql_query($sql)) )
{
//echo "<div id=\"error\" class=\"err\">An internal error has occured.<br> " . mysql_error() . "<br>Sql:" .$sql . "</div>"; // MySQL Error Message while executing query
echo "<div id=\"error\" class=\"err\">An internal error has occured.<br> </div>"; // MySQL Error Message while executing query
$this->closeConnection();
exit;
}

for ($i = 0; $i < mysql_num_rows($result); $i++) {
$arrReturnObj[] = mysql_fetch_array($result , MYSQL_ASSOC); // Assign the values to the defined array
}

mysql_free_result($result); // Free memory occupied by result resource
$this->closeConnection();
return $arrReturnObj; // return resultset as an Array
} //end function
bhaskar1
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Dec 11, 2012 6:46 am

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.