473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Show latest itens added, instead of oldest

matheussousuke
249 100+
Hi, I'm tring to order the subcategories of my website, but I'm not getting any sucess, tried put desc instead of asc, nothing worked, as you can see in the URL below, it is ordering from back to front, and it should from front to back, I mean, latest added itens should come first, and in the first page, but the system does the oposite, it show the oldest intens first, take a look (It is in portuguese, to see each item you can click on "Detalhes", then, after going to the other page, take a look at the date that is "Publicado em:", date format is "DD/MM/YYYY":

http://lucrebem.com.br/showCat.php?cat_id=155





The code responsible for it is this one:


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.  
  5. require_once 'path_cnfg.php';
  6.  
  7. require_once(path_cnfg('pathToLibDir').'func_common.php'); 
  8. require_once(path_cnfg('pathToLibDir').'func_checkUser.php');
  9. require_once(path_cnfg('pathToLibDir').'func_tree.php');
  10. require_once(path_cnfg('pathToLibDir').'func_getResults.php');
  11. require_once(path_cnfg('pathToCnfgDir').'cnfg_vars.php');
  12. require_once(path_cnfg('pathToLibDir').'vars_gbl.php');
  13.  
  14. $cookie = $HTTP_COOKIE_VARS['log_in_cookie'];
  15.  
  16. $content = array();
  17.  
  18. $myDB = db_connect();
  19.  
  20. checkUser('', ''); 
  21.  
  22. $content[] = 'doShow();';
  23.  
  24. // This line brings in the template file.
  25. // If you want to use a different template file 
  26. // simply change this line to require the template 
  27. // file that you want to use.
  28. require_once(path_cnfg('pathToTemplatesDir').cnfg('tmplt_showCat'));
  29.  
  30. db_disconnect($myDB);
  31.  
  32.  
  33. # --- START FUNCTIONS ---
  34.  
  35. // ************* START FUNCTION doShow() *************
  36.  
  37. function doShow()
  38. {
  39.     GLOBAL $myDB, $HTTP_GET_VARS  ;
  40.  
  41.     $cat_id = $HTTP_GET_VARS ["cat_id"];
  42.  
  43.     if ($cat_id)
  44.     { 
  45.         $query = 'SELECT cat_id,parent_id,cat_name FROM std_categories WHERE cat_id='.$cat_id;
  46.  
  47.         $result = mysql_query($query,$myDB);
  48.         $num_rows = mysql_num_rows($result);
  49.  
  50.         #echo '$num_rows = '.$num_rows.'<BR>';
  51.  
  52.         echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">
  53.               <tr><td valign="top" width="100%">
  54.               ';
  55.  
  56.  
  57.         $path = climb_tree($cat_id, 'showCat');
  58.         #echo '$path = '.$path.'<BR>';
  59.         $path_arr = split("\!\@\#_SPLIT_\!\@\#", $path);
  60.         for ($i=0; $i<count($path_arr); $i++)
  61.         {   echo $path_arr[$i] ; 
  62.             if ($i < count($path_arr)-2)
  63.             {   echo '<FONT CLASS="subCat" COLOR="#FF0000"><B>&gt;&gt;</B></FONT>'; 
  64.             }
  65.         }
  66.  
  67.         echo '<BR><BR>';
  68.         echo '</td></tr></table>';
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                 $query = 'SELECT cat_name,cat_id FROM std_categories 
  78.                   WHERE parent_id='.$cat_id.' 
  79.                   ORDER BY cat_name ASC' ; 
  80.  
  81.  
  82.  
  83.  
  84.  
  85.         $result = mysql_query($query,$myDB);
  86.  
  87.         if (mysql_num_rows($result) > 0 )
  88.         {   display_cats_sub($result, $cat_id);
  89.         }
  90.         else
  91.         {   getResults();
  92.         }
  93.  
  94.  
  95.     } // end if($cat_id)
  96.  
  97. } // end function doShow()
  98.  
  99. // ************* END FUNCTION doShow() *************
  100.  
  101.  
  102. // ************* START FUNCTION display_cats_sub() *************
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. function display_cats_sub($result, $cat_id)
  113. {
  114.     GLOBAL $myDB;
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.     $num_cols = cnfg('subCatsCols');
  125.     $col_buffer_size = cnfg('subCatsBufferCols');
  126.     $td_width = cnfg('subCatsTdWidth');
  127.     $table_width = cnfg('subCatsTableWidth');
  128.     $table_pad = cnfg('subCatsTablePad');
  129.     $table_spc = cnfg('subCatsTableSpace');
  130.     $centered_or_not = cnfg('subCatsCenter');
  131.  
  132.     if ($centered_or_not)
  133.     {   echo '<CENTER>' ; 
  134.     }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.     echo '<table cellpadding="'.$table_pad.'" cellspacing="'.$table_spc.'" ';
  141.     echo 'border="0" width="'.$table_width.'">';
  142.  
  143.     $countCols = 1;
  144.     $num_cols = $num_cols+($num_cols-1);
  145.  
  146.     for ($i=0; $i<mysql_num_rows($result); $i++  )
  147.     { 
  148.         if ($countCols==1 ) 
  149.         {   echo '<tr>'."\n"; 
  150.         }
  151.  
  152.         $num_ads = 0;
  153.  
  154.         if ( $countCols % 2 == 0 )
  155.         {   echo '<td valign=top width="'.cnfg('subCatsBufferCols').'">'."\n" ; 
  156.             echo '<img src="'.cnfg('deDir').'/images/trans.gif" ';
  157.             echo 'border="0" width="50" height="1">'."\n";
  158.             echo '</td>'."\n";
  159.  
  160.             $i-- ; // no data used from $result array, so decrement the iterator.
  161.         }
  162.         else
  163.         {   $row = mysql_fetch_array($result) ;     
  164.             get_num_ads($row["cat_id"], true, $num_ads); 
  165.  
  166.  
  167.             echo '<td valign="top" width="'.$td_width.'">'."\n";
  168.             echo '<a href="'.cnfg('deDir').'showCat.php?cat_id='.
  169.                   $row["cat_id"].'">'."\n" ;
  170.             echo '<FONT CLASS="subCat">';
  171.             echo $row['cat_name'];
  172.             echo '</FONT>';
  173.             echo '</a>&nbsp;';
  174.             echo '<FONT CLASS="subCat">('.$num_ads.')</FONT>'."\n";
  175.             echo '</td>'."\n";
  176.         }
  177.  
  178.  
  179.  
  180.             if($countCols==$num_cols || $i==(mysql_num_rows($result)-1) )
  181.         {   $countCols=1; 
  182.             echo '</tr>';
  183.         }  
  184.         else
  185.         {   $countCols++ ; 
  186.         }
  187.  
  188.     } // end while
  189.  
  190.     echo '</table>';
  191.  
  192.     if($centered_or_not)
  193.     {   echo '</CENTER>' ; 
  194.     }
  195.  
  196. } // end function display_cats_sub()
  197.  
  198. // ************* END FUNCTION display_cats_sub() *************
  199.  
  200.  
  201. ?>
  202.  






PS: I tried altering almost every part, there are some parts that are responsible for the categories, and others that I don't understand intirely, the system works with categories, and subcategories, and I guess it also works with itens.
Jul 17 '10 #1
14 2011
matheussousuke
249 100+
I'm sorry, this is the correct code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. // ************* START function get_searchable_cats() *************
  5.  
  6. function get_searchable_cats($cat_id, &$cats_arr)
  7. {
  8.     GLOBAL $myDB; 
  9.  
  10.     $query = "SELECT cat_id, cat_name FROM std_categories WHERE 
  11.               top_parent_id=$cat_id" ;
  12.     $result = mysql_query($query);
  13.  
  14.     while ($row = mysql_fetch_array($result) )
  15.     {   $query2 = 'SELECT * FROM std_categories 
  16.                    WHERE parent_id='.$row["cat_id"];
  17.         $result2 = mysql_query($query2);
  18.         if (mysql_num_rows($result2) == 0 )
  19.         {   $cats_arr[] = $row["cat_id"];
  20.         }
  21.     }
  22.  
  23. } // end function get_searchable_cats()
  24.  
  25. // ************* END function get_searchable_cats() *************
  26.  
  27.  
  28.  
  29. // ************* START FUNCTION getResults() *************
  30.  
  31. function getResults()
  32. {
  33.     GLOBAL $myDB, $HTTP_GET_VARS, $HTTP_POST_VARS  ;
  34.  
  35.     if (isset($HTTP_POST_VARS["search"]) )
  36.     {   $search = $HTTP_POST_VARS["search"] ;
  37.     }
  38.     elseif(isset($HTTP_GET_VARS["search"]) )
  39.     {   $search = $HTTP_GET_VARS["search"] ; ; 
  40.     }
  41.  
  42.  
  43.     $category   = $HTTP_POST_VARS["category"];
  44.  
  45.     $doSearch  = $HTTP_GET_VARS["doSearch"];
  46.     $cat_id    = $HTTP_GET_VARS["cat_id"];
  47.     $offset    = $HTTP_GET_VARS["offset"];
  48.  
  49.  
  50.     $bgcolor = cnfg('viewAdsRowColor1');
  51.     $topRow = true;
  52.     $searchOrShowCat = '';
  53.  
  54.     if (!$offset) 
  55.     {   $offset = 0 ; 
  56.     }
  57.  
  58.  
  59.     $expTime = time()-(cnfg('expireAdsDays')*86400);
  60.  
  61.     if ($doSearch) 
  62.     {   $cats_arr = array();
  63.         if (isset($category) && $category != 'none')
  64.         {   /* get_searchable_cats takes a reference 
  65.              * to $cats_arr and loads it up.
  66.              */
  67.             get_searchable_cats($category, $cats_arr) ; 
  68.         }
  69.  
  70.         $query = '
  71.            SELECT 
  72.            std_items.item_id as item_id,
  73.            std_items.cat_id as cat_id,
  74.            std_items.title as title,
  75.            std_items.the_desc as the_desc,
  76.            std_items.image_exists as image_exists,
  77.            std_categories.cat_id as cat_id,
  78.            std_categories.cat_name as cat_name
  79.            FROM std_items,std_categories WHERE 
  80.            (std_items.the_desc LIKE "%'.$search.'%" OR 
  81.            std_items.title LIKE "%'.$search.'%")
  82.            AND std_items.date_time>'.$expTime.'
  83.            AND std_items.cat_id=std_categories.cat_id';
  84.  
  85.         if (count($cats_arr) > 0 )
  86.         {   $query .= ' AND  (';
  87.             for ($i=0; $i<count($cats_arr); $i++)
  88.             {   $query .= 'std_items.cat_id='.$cats_arr[$i] ;
  89.                 if ($i != count($cats_arr)-1 )
  90.                 {   $query .= ' OR ' ; 
  91.                 }
  92.             }
  93.             $query .= ')';
  94.         }
  95.  
  96.         $searchOrShowCat = 'search.php';
  97.     }
  98.     else
  99.     {   $query = 'SELECT 
  100.             std_items.item_id as item_id,
  101.             std_items.cat_id as cat_id,
  102.             std_items.title as title,
  103.             std_items.the_desc as the_desc,
  104.             std_items.image_exists as image_exists,
  105.             std_categories.cat_id as cat_id,
  106.             std_categories.cat_name as cat_name
  107.             FROM std_items,std_categories 
  108.             WHERE std_items.date_time>'.$expTime.' 
  109.             AND std_items.cat_id='.$cat_id.'
  110.             AND std_items.cat_id=std_categories.cat_id'
  111.  
  112.             ;
  113.  
  114.         $searchOrShowCat = 'showCat.php';
  115.         $doSearch = 0;
  116.     }
  117.  
  118.  
  119.     $query .= ' LIMIT '.$offset.','."21" ;
  120.  
  121.     #echo '$query = '.$query.'<BR>';
  122.  
  123.     if ($offset != 0)
  124.     {   $offset += 20; 
  125.     }
  126.  
  127.  
  128.     $result = mysql_query($query,$myDB);
  129.     if (!$result)
  130.     {   echo mysql_error(); 
  131.     }
  132.  
  133.     $num_rows = mysql_num_rows($result);
  134.  
  135.  
  136.     echo "<CENTER>\n";
  137.  
  138.     if ($num_rows >0)
  139.     { 
  140.         ?>
  141.  
  142.         <table cellpadding="0" cellspacing="0" border="0" width="<?php echo  cnfg('rowsOfAdsTableWidth') ?>">
  143.         <tr>
  144.         <td width="10%" align="left">
  145.  
  146.         <?php
  147.  
  148.         if ( ($offset && $offset != 0) && ($offset != 10) )
  149.         {
  150.             echo '
  151.                 <a href="'.cnfg('deDir').$searchOrShowCat.
  152.                 '?doSearch='.$doSearch.'&search='.urlencode($search).'&offset=';
  153.             echo $offset-40;
  154.             echo "&cat_id=$cat_id";
  155.             echo '"><font color="#FF0000"> < Página anterior</font></a>
  156.               </td>';
  157.             echo "\n";
  158.         } 
  159.         else
  160.         {   echo '&nbsp;
  161.               </td>';
  162.             echo "\n";
  163.         }
  164.  
  165.         ?>
  166.  
  167.         <td width="80%">
  168.         <CENTER>
  169.         <FONT CLASS="subCat">
  170.  
  171.         <?php
  172.         echo 'Resultados, desde os anúncios mais antigos.<br>';
  173.         if ($offset==0)
  174.         {   echo ($offset+1).'-'.($offset+20);
  175.         }
  176.         else
  177.         {   echo (($offset-20)+1).'-'.$offset;
  178.         }
  179.  
  180.         ?>
  181.  
  182.         &nbsp;&nbsp;
  183.         </FONT></CENTER>
  184.         </td>
  185.  
  186.  
  187.         <?php
  188.  
  189.         if($num_rows==21)
  190.         {   echo '
  191.               <td align="right" width="10%">
  192.               <a href="'.cnfg('deDir').$searchOrShowCat.'?doSearch='.$doSearch.'&search='
  193.               .urlencode($search).'&offset=';
  194.  
  195.             if ($offset==0)
  196.             {   echo $offset+20; 
  197.             }
  198.             else
  199.             {   echo $offset; 
  200.             } 
  201.  
  202.             echo "&cat_id=$cat_id";
  203.             echo '"><font color="#FF0000">Próxima página > </font></a>
  204.                  </td>
  205.                   '; 
  206.         }
  207.         else
  208.         {   ?>
  209.             <td valign="right" width="10%">&nbsp; 
  210.  
  211.             </td>
  212.             <?php
  213.         }
  214.  
  215.         ?>
  216.         </tr>
  217.         </table>
  218.  
  219.  
  220.         <table cellpadding="4" cellspacing="0" border="0" width="<?php echo  cnfg('rowsOfAdsTableWidth') ?>">
  221.         <tr>
  222.         <td bgcolor="<?php echo $bgcolor ?>">
  223.         <FONT COLOR="#000000" FACE="Tahoma">
  224.         <CENTER>
  225.         <B>Imagem</B>
  226.         </CENTER>
  227.         </FONT>
  228.         </td>
  229.         <td bgcolor="<?php echo $bgcolor ?>">
  230.         <FONT COLOR="#000000" FACE="Tahoma">
  231.         <CENTER>
  232.         <B>Título</B>
  233.         </CENTER>
  234.         </FONT>
  235.         </td>
  236.         <td bgcolor="<?php echo $bgcolor ?>">
  237.         <FONT COLOR="#000000" FACE="Tahoma">
  238.         <CENTER>
  239.         <B>Descrição</B>
  240.         </CENTER>
  241.         </FONT>
  242.         </td>
  243.         <td bgcolor="<?php echo $bgcolor ?>">
  244.         <FONT COLOR="#000000" FACE="Tahoma">
  245.         <CENTER>
  246.         <B>Categoria</B>
  247.         </CENTER>
  248.         </FONT>
  249.         </td>
  250.         <td bgcolor="<?php echo $bgcolor ?>">&nbsp;
  251.  
  252.         </td>
  253.         </tr>
  254.  
  255.         <?php 
  256.  
  257.         if ($bgcolor == cnfg('viewAdsRowColor1') )
  258.         {   $bgcolor=cnfg('viewAdsRowColor2') ; 
  259.         }
  260.         else
  261.         {   $bgcolor = cnfg('viewAdsRowColor1') ; 
  262.         }
  263.  
  264.         $count_to;
  265.         if ($num_rows>20)
  266.         {   $count_to = 20; 
  267.         }
  268.         else
  269.         {   $count_to = $num_rows; 
  270.         }
  271.  
  272.         for ($i=0; $i<$count_to; $i++)
  273.         {   $row = mysql_fetch_array($result) ;
  274.  
  275.             ?>
  276.             <tr>
  277.             <td bgcolor="<?php echo $bgcolor?>">
  278.  
  279.             <?php
  280.             if ($row['image_exists'] && $row['image_exists'] == 'true')
  281.             {   ?>
  282.  
  283.                 <CENTER>
  284.                 <img src="<?php echo cnfg('deDir') ?>http://bytes.com/images/pic_yes.gif" border="0" width="64" height="64">
  285.                 </CENTER>
  286.  
  287.                 <?php
  288.             }
  289.             elseif(!$row['image_exists'] || $row['image_exists'] != 'true')
  290.             {   ?>
  291.                 <CENTER>
  292.                 <img src="<?php echo cnfg('deDir') ?>http://bytes.com/images/pic_no.gif" border="0" width="64" height="64">
  293.                 </CENTER>  
  294.  
  295.                 <?php
  296.             }
  297.  
  298.  
  299.             ?>
  300.  
  301.             </td>
  302.             <td bgcolor="<?php echo $bgcolor ?>">
  303.  
  304.             <?php
  305.  
  306.             if (strlen(stripslashes(strip_tags($row['title']))) > 14 )
  307.             {   echo substr(stripslashes(strip_tags($row['title'])), 0,37),'....'; 
  308.             }
  309.             else
  310.             {   echo stripslashes(strip_tags($row['title'])); 
  311.             }
  312.  
  313.             ?>
  314.  
  315.             </td>
  316.             <td bgcolor="<?php echo $bgcolor ?>">
  317.  
  318.             <?php
  319.  
  320.             $row['the_desc'] = stripslashes(strip_tags($row['the_desc']));
  321.  
  322.             if (strlen(stripslashes(strip_tags($row['the_desc']))) > 14 )
  323.             {   echo substr(stripslashes(strip_tags($row['the_desc'])),0,80).'....'; 
  324.             }
  325.             else
  326.             {   echo stripslashes(strip_tags($row['the_desc'])); 
  327.             }
  328.  
  329.             echo '
  330.                 </td>
  331.                 <td bgcolor="'.$bgcolor.'">'
  332.                 .$row['cat_name'].
  333.                 '</td>
  334.                 <td bgcolor="'.$bgcolor.'"><a href="details.php?';
  335.             if ($doSearch)
  336.             {   echo 'doSearch=true';
  337.             }
  338.  
  339.             if ($row['cat_id'])
  340.             {   echo '&cat_id='.$row['cat_id']; 
  341.             }
  342.             else
  343.             {   echo '&cat_id='.$cat_id; 
  344.             }
  345.  
  346.             echo '&item_id='.$row['item_id'].'&offset=';
  347.  
  348.             if (isset($offset) && $offset>0)
  349.             {   echo $offset-20; 
  350.             }
  351.             else
  352.             {   echo $offset;
  353.             }
  354.  
  355.  
  356.             echo '">';
  357.  
  358.             ?>
  359.  
  360.             <FONT FACE="Tahoma" STYLE="font-size:13pt; font-color:#ff0000;">
  361.             Detalhes
  362.             </FONT>
  363.             </a>
  364.             </td>
  365.             </tr>
  366.  
  367.             <?php 
  368.  
  369.             if ($bgcolor == cnfg('viewAdsRowColor1') )
  370.             {   $bgcolor=cnfg('viewAdsRowColor2'); 
  371.             }
  372.             else
  373.             {   $bgcolor = cnfg('viewAdsRowColor1') ; 
  374.             }
  375.  
  376.         } // end while
  377.  
  378.         ?>
  379.  
  380.  
  381.         </td>
  382.         </tr>
  383.         </table>
  384.  
  385.  
  386.         <table cellpadding="0" cellspacing="0" border="0" width="80%">
  387.         <tr>
  388.         <td align="left" width="20%">  
  389.  
  390.         <?php
  391.  
  392.         if ( ($offset && $offset != 0) && ($offset != 10) )
  393.         {   echo '
  394.                 <a href="'.cnfg('deDir').$searchOrShowCat.
  395.                 '?doSearch='.$doSearch.'&search='.urlencode($search).'&offset=';
  396.             echo $offset-40;
  397.             echo "&cat_id=$cat_id";
  398.             echo '"><font color="#FF0000"> < Página anterior</font></a>
  399.               </td>';
  400.             echo "\n";
  401.         } 
  402.         else
  403.         {   echo '&nbsp;';
  404.         }
  405.  
  406.         ?>
  407.  
  408.         </td>
  409.  
  410.         <td valign="top" width="60%">&nbsp;
  411.  
  412.         </td>
  413.  
  414.         <?php 
  415.  
  416.         if ($num_rows==21)
  417.         {   echo '
  418.              <td align="right" width="20%">
  419.              <a href="'.cnfg('deDir').$searchOrShowCat.'?doSearch='.$doSearch.'&search='
  420.              .urlencode($search).'&offset=';
  421.  
  422.             if ($offset==0)
  423.             {   echo $offset+20; 
  424.             }
  425.             else
  426.             {   echo $offset; 
  427.             } 
  428.  
  429.             echo "&cat_id=$cat_id";
  430.             echo '"><font color="#FF0000">Próxima página > </font></a>'; 
  431.         }
  432.  
  433.         ?>
  434.         </td>
  435.         </tr>
  436.         </table>
  437.  
  438.  
  439.  
  440.     <?php
  441.     } // end if($num_rows >0){
  442.     else
  443.     {   if ($doSearch)
  444.         {   echo '
  445.               <table><tr><td valign="top">
  446.               <BR>
  447.               Lamento, nenhum resultado.<BR>
  448.  
  449.               </td></tr></table>';
  450.         }
  451.         else
  452.         {   echo '
  453.               <table><tr><td valign="top">
  454.               <BR>
  455.               Não há itens nesta categoria.<BR>
  456.               <a href="javascript: onClick=history.go(-1);">
  457.               << Volar
  458.               </a>
  459.               </td></tr></table>';
  460.         }
  461.     }
  462.  
  463.     echo "</CENTER>\n";
  464.  
  465. } // end function getResults()
  466.  
  467.  
  468. // ************** END FUNCTION getResults() *************
  469.  
  470. ?>
  471.  
  472.  












And the parts that call for the itens are these:



Expand|Select|Wrap|Line Numbers
  1.   $query = '
  2.            SELECT 
  3.            std_items.item_id as item_id,
  4.            std_items.cat_id as cat_id,
  5.            std_items.title as title,
  6.            std_items.the_desc as the_desc,
  7.            std_items.image_exists as image_exists,
  8.            std_categories.cat_id as cat_id,
  9.            std_categories.cat_name as cat_name
  10.            FROM std_items,std_categories WHERE 
  11.            (std_items.the_desc LIKE "%'.$search.'%" OR 
  12.            std_items.title LIKE "%'.$search.'%")
  13.            AND std_items.date_time>'.$expTime.'
  14.            AND std_items.cat_id=std_categories.cat_id';
  15.  
  16.         if (count($cats_arr) > 0 )
  17.         {   $query .= ' AND  (';
  18.             for ($i=0; $i<count($cats_arr); $i++)
  19.             {   $query .= 'std_items.cat_id='.$cats_arr[$i] ;
  20.                 if ($i != count($cats_arr)-1 )
  21.                 {   $query .= ' OR ' ; 
  22.                 }
  23.             }
  24.             $query .= ')';
  25.         }
  26.  
  27.         $searchOrShowCat = 'search.php';
  28.     }
  29.     else
  30.     {   $query = 'SELECT 
  31.             std_items.item_id as item_id,
  32.             std_items.cat_id as cat_id,
  33.             std_items.title as title,
  34.             std_items.the_desc as the_desc,
  35.             std_items.image_exists as image_exists,
  36.             std_categories.cat_id as cat_id,
  37.             std_categories.cat_name as cat_name
  38.             FROM std_items,std_categories 
  39.             WHERE std_items.date_time>'.$expTime.' 
  40.             AND std_items.cat_id='.$cat_id.'
  41.             AND std_items.cat_id=std_categories.cat_id'
  42.  
  43.             ;
  44.  
  45.         $searchOrShowCat = 'showCat.php';
  46.         $doSearch = 0;
  47.     }






I'm trying here, but getting no results, I just need to make the system order the displayied items, does anyone has any idea?


Just remembering, currently they are being showed from oldest to newest, oldest comes first, in the top of the page, and I need the oposite.

This website is ery important, it helps a lot of people around here to find jobs, please, help =/
Jul 17 '10 #2
Dormilich
8,658 Expert Mod 8TB
I’d try the ORDER BY clause on the SQL.
Jul 17 '10 #3
matheussousuke
249 100+
@Dormilich
You mean inside the db on phpmyadmin?
Jul 17 '10 #4
Dormilich
8,658 Expert Mod 8TB
inside the SQL string
Jul 17 '10 #5
matheussousuke
249 100+
I did this
Expand|Select|Wrap|Line Numbers
  1.    $query = 'SELECT 
  2.             std_items.item_id as item_id,
  3.             std_items.cat_id as cat_id,
  4.             std_items.title as title,
  5.             std_items.the_desc as the_desc,
  6.             std_items.image_exists as image_exists,
  7.             std_categories.cat_id as cat_id,
  8.             std_categories.cat_name as cat_name
  9.  
  10.             FROM std_items,std_categories 
  11.             WHERE std_items.date_time>'.$expTime.' 
  12.  
  13.             ORDER BY item_id DESC
  14.  
  15.             AND std_items.cat_id='.$cat_id.'
  16.             AND std_items.cat_id=std_categories.cat_id'        
  17.             ;

and got this error



You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND std_items.cat_id=19 AND std_items.cat_id=std_categories.cat_id L' at line 15
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lucrebem/public_html/lib/func_getResults.php on line 139
Jul 17 '10 #6
Dormilich
8,658 Expert Mod 8TB
ORDER BY std_items.item_id DESC

don't forget to specify the table you’re using
Jul 17 '10 #7
matheussousuke
249 100+
@Dormilich
I did this
Expand|Select|Wrap|Line Numbers
  1.  {   $query = 'SELECT 
  2.             std_items.item_id as item_id,
  3.             std_items.cat_id as cat_id,
  4.             std_items.title as title,
  5.             std_items.the_desc as the_desc,
  6.             std_items.image_exists as image_exists,
  7.             std_categories.cat_id as cat_id,
  8.             std_categories.cat_name as cat_name
  9.  
  10.             FROM std_items,std_categories 
  11.             WHERE std_items.date_time>'.$expTime.' 
  12.  
  13.                 ORDER BY std_items.item_id DESC
  14.  
  15.             AND std_items.cat_id='.$cat_id.'
  16.             AND std_items.cat_id=std_categories.cat_id'
  17.  
  18.  
  19.  
  20.             ;


And got this error, I guess it's the same one as the other:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND std_items.cat_id=19 AND std_items.cat_id=std_categories.cat_id L' at line 15
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lucrebem/public_html/lib/func_getResults.php on line 142
Jul 17 '10 #8
zorgi
431 Expert 256MB
because you specified: std_items.item_id as item_id
you should be able to use
ORDER BY std_items.item_id DESC
or
ORDER BY item_id DESC.
Just stick it at the end of your sql command and not in the middle of your where clause
Jul 17 '10 #9
matheussousuke
249 100+
I did this:
Expand|Select|Wrap|Line Numbers
  1.    {   $query = 'SELECT 
  2.             std_items.item_id as item_id,
  3.             std_items.cat_id as cat_id,
  4.             std_items.title as title,
  5.             std_items.the_desc as the_desc,
  6.             std_items.image_exists as image_exists,
  7.             std_categories.cat_id as cat_id,
  8.             std_categories.cat_name as cat_name
  9.  
  10.             FROM std_items,std_categories 
  11.             WHERE std_items.date_time>'.$expTime.' 
  12.  
  13.                 ORDER BY std_items.item_id DESC
  14.  
  15.             AND std_items.cat_id='.$cat_id.'
  16.             AND std_items.cat_id=std_categories.cat_id'
  17.  





Got the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM std_items,std_categories WHERE std_items.date_time>-8.63999998' at line 15
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lucrebem/public_html/lib/func_getResults.php on line 142






And did this:
Expand|Select|Wrap|Line Numbers
  1.   {   $query = 'SELECT 
  2.             std_items.item_id as item_id,
  3.             std_items.cat_id as cat_id,
  4.             std_items.title as title,
  5.             std_items.the_desc as the_desc,
  6.             std_items.image_exists as image_exists,
  7.             std_categories.cat_id as cat_id,
  8.             std_categories.cat_name as cat_name
  9.  
  10.  
  11. ORDER BY item_id DESC
  12.  
  13.  
  14.             FROM std_items,std_categories 
  15.             WHERE std_items.date_time>'.$expTime.' 
  16.  
  17.  
  18.  
  19.             AND std_items.cat_id='.$cat_id.'
  20.             AND std_items.cat_id=std_categories.cat_id'
  21.  

And got this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM std_items,std_categories WHERE std_items.date_time>-8.63999998' at line 10
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lucrebem/public_html/lib/func_getResults.php on line 142
Jul 17 '10 #10
matheussousuke
249 100+
@zorgi
You mean I should exchange

Expand|Select|Wrap|Line Numbers
  1. # std_items.item_id as item_id
for

Expand|Select|Wrap|Line Numbers
  1. ORDER BY item_id DESC

??
Jul 17 '10 #11
matheussousuke
249 100+
Yes, I understand now, I have std_items.item_id as item_id, and cause that, I'm able to use the command ORDER BY item_id DESC in the code, but as you can see, I did it, and did not work, and I also put the code before the ";", like this
Expand|Select|Wrap|Line Numbers
  1.   FROM std_items,std_categories 
  2.             WHERE std_items.date_time>'.$expTime.' 
  3.  
  4.  
  5.  
  6.             AND std_items.cat_id='.$cat_id.'
  7.             AND std_items.cat_id=std_categories.cat_id'
  8.  
  9.             ORDER BY std_items.item_id DESC
  10.  
  11.             ;
Jul 17 '10 #12
zorgi
431 Expert 256MB
You placed ORDER BY std_items.item_id DESC outside your quotation marks ''
Jul 17 '10 #13
matheussousuke
249 100+
hahahahahahahahaha


I did it, I did it, I did it, I'm crying of so happy.


Man, you came from heavennnnnnnnnnnnnnnnnnn


Thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu


omg


I will faint if I keep like that



holy jesusssss


Now everyone is going to be able to see the latest jobs vacancies!!!!!!
Jul 17 '10 #14
matheussousuke
249 100+
And I'd like to thank Dormilich too, he always help me when I post somthing here. Thx a lot, you guys are amazing
Jul 17 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Aardwolf | last post by:
I've had PHP on my Win2K server running IIs 5 for about 2 weeks now. I have an annoying problem in that I can not run the php scripts/pages locally, instead they open up in the browser as a...
2
by: Thomaz | last post by:
Hi i need some help to solve a problem with the DataSource in a COMBOBOX. The question is "How can i clear all the itens in a Combobox if i use the DataSource to browse data in a database????"....
6
by: Vern | last post by:
I'm adding twenty nodes (Parent and child) to a tree view. Only 10 items are viewable in the window at at time. So when it initially shows the tree, it shows the last ten items forcing me to use...
5
by: Sukhanov Volodya | last post by:
Hello, all! Does anybody knows, how I can show an image field SQL Server using VB. NET ? I have an database, which has an table with an field which has type 'image' (the type of field) I want...
1
by: Marco Roberto | last post by:
Hi, is there anyway to add itens into a combobox after this control be bound with a dataset? Regards, Marco
1
by: BrianDH | last post by:
Hi Is there a way to, when using the "MessageBox.Show", to have the focus NOT set to the OK buton? I want to make the users read the message, and use the mouse to close the window. Thanks ...
4
by: dheerajsah | last post by:
hi all, I have created a DIV tag using DOM ..... Element div = DOM.createDiv(); and appended Label inside it. .... Element label = DOM.createLabel(); DOM.setAttribute(label, "value",...
4
by: Dan | last post by:
Hi, I know how to show and hide text, but I want to make it so that the page shifts up when I hide my text. Right now with the simple code, it only leaves a blank space. Thanks, Daniel
4
by: Apple1 | last post by:
Hello! I would like to switch elements on the fly. Dynamicly turn "A" elenent an "input" tag. This is what I tried: <html> <head> <script>
4
by: markh | last post by:
Hi Can anyone tell me how I get an html page to show my latest user control. I created a simple user control in c# (vs2008 pro), copied the dll to the web site and added the html object tags to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.