[seesion 찜게시판 문의] 가장 최근것을 위에 오게 하려면 어떻게해야 될까요?

[seesion 찜게시판 문의] 가장 최근것을 위에 오게 하려면 어떻게해야 될까요?

QA

[seesion 찜게시판 문의] 가장 최근것을 위에 오게 하려면 어떻게해야 될까요?

답변 1

본문

안녕하세요. :)

아래는 찜게시판 소스입니다.

리스트 정렬시 가장 최근것이 밑으로 붙는데요.

가장 최근것을 위에 오게 하려면 어떻게해야 될까요?

도움 부탁 드려요. 




<?
function shop_price($today,$bo_table)
{
    global $g4;

  $price = 0;
  if(is_array($today))
  {

    foreach($today as $wr_id => $qty)
    { 
      $tmp_write_table = $g4['write_prefix'] . $bo_table;
      $sql = "select * from $tmp_write_table where wr_id=$wr_id";
      $row = sql_fetch($sql);

      $price +=$row[sel_price]*$qty;

    }
  }
  return $price;
 
 
 
}


  $tmp_write_table = $g4['write_prefix'] . $bo_table;

  //
  if($amount){
  $item_qt = $amount;
  }
  else{
  $item_qt = 1;
  }

  if($wr_id && $bo_table)
  {

    $wr = get_write($tmp_write_table, $wr_id);
    if (!$wr[wr_id])
        alert("존재하지 않는상품입니다.\\n\\n삭제된상품이거나 판매보류된 상품입니다.");

    if(!isset($_SESSION[$today]))
    {
      $_SESSION[$today] = array();
      $_SESSION['items'] = 0;
      $_SESSION['total_price'] = 0;

    }

    if(isset($_SESSION[$today][$wr_id])){
      $_SESSION[$today][$wr_id]++;

 }
    else {
      $_SESSION[$today][$wr_id] = $item_qt;

 }

    $_SESSION['total_price'] = shop_price($_SESSION[$today],$bo_table);
    $_SESSION['items']       = shop_qty($_SESSION[$today]);
  }

  if(isset($_POST['save']))
  {  
    foreach ($_SESSION[$today] as $wr_id => $qty)
    {
      if($_POST[$wr_id]=='0')
        unset($_SESSION[$today][$wr_id]);
      else
        $_SESSION[$today][$wr_id] = $_POST[$wr_id];
    }
    $_SESSION['total_price'] = shop_price($_SESSION[$today],$bo_table);
    $_SESSION['items']       = shop_qty($_SESSION[$today]);
  }

  if($del)
  {
    unset($_SESSION[$today][$del]);
  }

  if($wr_id || $del)
  {
    goto_url("./today.php");
  }

$colspan = 4;


if($state_path =='today.php')$colspan++;


?>



 <?

 if($_SESSION[$today]&&array_count_values($_SESSION[$today]))
 {
  foreach ($_SESSION[$today] as $wr_id => $qty)
  {
   $tmp_write_table = $g4['write_prefix'] . $bo_table;
   $sql = "select * from $tmp_write_table where wr_id='$wr_id'";
   $list = sql_fetch($sql);
   
    $t   = 0; // 첫번째 이미지
    $row = sql_fetch(" select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$t' ");
      if($row[bf_file]){
   $i_width = "120";
      $dst = "$g4[path]/data/file/$bo_table/thumbs/" . $row[bf_file];
   $dst_img = "<img src='{$dst}' width='120' height='80' border='0'>";
  }
   $del = "<a href=\"javascript:today_del('./today.php?bo_table=$bo_table&del=$wr_id);\"><img src='./img/del.gif' onmouseover=\"this.src='./img/del_on.gif'\"
   onmousedown=\"this.src='./img/del_on.gif'\"
   onmouseout=\"this.src='./img/del.gif'\" alt=\"삭제\"
   type=\"image\" align=\"absmiddle\"  border=0></a>";
 ?>

이 질문에 댓글 쓰기 :

답변 1

$_SESSION[$today] 값을 조건에 맞게 정렬하면 됩니다. 세션값을 저장 할 때 정렬 해 놓으면 됨.

if($_SESSION[$today]&&array_count_values($_SESSION[$today])) {
  foreach ($_SESSION[$today] as $wr_id => $qty) {
....

에탄올님 답변 감사드립니다. :)
세션값을 저장할때면,
  if(isset($_POST['save']))
  { 
    foreach ($_SESSION[$today] as $wr_id => $qty)
    {
      if($_POST[$wr_id]=='0')
        unset($_SESSION[$today][$wr_id]);
      else
        $_SESSION[$today][$wr_id] = $_POST[$wr_id];
    }
    $_SESSION['total_price'] = shop_price($_SESSION[$today],$bo_table);
    $_SESSION['items']      = shop_qty($_SESSION[$today]);
  }
이 부분을 수정해야 되나요?
에고~ 어렵네요. ㅜㅜ
어떻게 수정해야 되는지 알려주실 수 있으신가요?
도움 부탁 드려요~

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로