SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query problem :: HELP ::

    hi all,
    the problem that i make query for the catagory from the db, and the catagory name is like to action to sort from another table the rows, but when i click on the catagory name will show me always the last row from the table

    PHP Code:
    echo "<table align=\"left\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#333333\">\n";
    echo 
    "<tr><td>\n";
    echo 
    "<b><font color=\"#ff6600\">Show  By Catagory</font></b>";
    echo 
    "</td></tr>\n";
        
    $sql_cat="select * from catagory  ";
    $result_cat=mysql_query($sql_cat,$db);

    $n=mysql_num_rows($result_cat);

    $i=0;

    while(
    $mycat=mysql_fetch_array($result_cat)){
        
    $i++;
    $cat_id=$mycat["cat_id"];
    $cat_name=$mycat["cat_name"];
    $cat_notes=$mycat["cat_notes"];

    if (
    $i  ){
    echo 
    "<tr bgcolor=\"efefef\"><td>\n";        
    echo 
    "<b> $i. <a href=\"$php_self?action=bycatagory&cat_name=$cat_name\">$cat_name </a></b>";    
    echo 
    "</td></tr>\n";}
    else {
    echo 
    "<tr bgcolor=\"#DFDFDD\"><td>\n";        
    echo 
    "<b> $i. <a href=\"$php_self?action=bycatagory&cat_name=$cat_name\">$cat_name</a></b>";    
    echo 
    "</td></tr>\n";
    }


    }

    echo
    "</table>";


    if (
    $action =="bycatagory"){
    echo 
    "[$cat_name]"// ---------> here i got the last catagory name always !! !

    $query mysql_query("select * from $table  where cat_name='$cat_name' ",$db); // ---------> so terem  is error also ! but whay !!
    $num=mysql_num_rows($query);



    //echo "<Center> <font color=\"#006600\"><B>.::</B> There are <B>$num</B> record <B>::.</B> ";
            
    $p  "<table align=\"center\" border=\"0\" cellspacing=\"3\" cellpadding=\"2\" class=\"table_border\">\n";
            
    $p .= "<tr class=\"head\"><td>ID</td><td>Catagory</td><td>Name</td><td>Email</td><td>Telefon</td><td>More</td><td>Print</td><td>Modify</td><td>Delete</td></tr>\n";
            echo 
    $p;

        while(list(
    $id,$cat_name$st_name$m_name$l_name$email$tel1$tel2$tel3$fax$address$note) = mysql_fetch_row($query)){

            
    $print  "\n<tr class=\"cells\">\n";
            
    $print .= "<td><font color=\"#999933\"><b>$id</b></font></td> <td>$cat_name</td><td><font color=\"#ff6600\"><b>$st_name $l_name </font></td>\n";
            
    $print .= "<td><a href=\"email.php?action=sendmail&email1=$email\">$email</a></td><td><b>$tel1</td>";
            
    $print .="<td><a href=\"index.php?action=more&id=$id\"><img alt=\"Read More\" border=\"0\" src=\"more.jpg\"></a></td>\n";
            
    $print .="<td align=\"center\"><a href=\"index.php?action=print&id=$id\"><img alt=\"Print\" border=\"0\" src=\"printicon.gif\"></a></td>\n";
            
    $print .= "<td align=\"center\"><a href=\"index.php?action=modify&id=$id\"><img alt=\"Modify\" border=\"0\" src=\"modify.gif\"></a></td>\n";
            
    $print .= "<td align=\"center\"><a href=\"index.php?action=remove&id=$id\"><img alt=\"Delete\" border=\"0\" src=\"delete.gif\"></a></td>\n";
            
    $print .= "</tr>\n";
            echo 
    $print;
        }
        echo
    "</table>";

    /////////////////    

    there 2 table, catagory, and $table, and it`s include cat_name row !

    thx for help !!!

  2. #2
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first, i think your're getting an error on your second query because I don't see where you are setting $table, therefore the query is invalid. Second of all...the reason your're always getting the last result is because you loop through that while statement from the first result and set $cat_name to $mycat[$cat_name]. I would suggest putting whatever you need to print within that while statement and then see if your're getting all the different results. Simply print out $cat_name within your while loop and you should see all of the results cat_name. Then put your html to print within the while loop. That should do it.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  3. #3
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem wasn`t that i found it, the for loop coz the error !

    PHP Code:


    if($action !="search"  and $action !="findit"   and $action !="print"){
    echo 
    "\n\n <!-- MENU CATAGORY-->\n\n";    
    echo 
    "<table align=\"left\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" bgcolor=\"#333333\">\n";
    echo 
    "<tr><td>\n";
    echo 
    "<b><font color=\"#ff6600\">Show  By Catagory</font></b>";
    echo 
    "</td></tr>\n";

    $query1 mysql_query("Select * from catagory  ");

       
    $count mysql_num_rows($query1);
    $c=0;
        for(
    $i =0$i $count$i++){
        
    $h mysql_fetch_array($query1);
    $h[cat_notes]=str_replace ("<br>","\n",$h[cat_notes]);    
    $c++;
    $query mysql_query("select * from $table  where cat_name='$h[cat_name] ' ",$db); 
    $num=mysql_num_rows($query);

    if (
    $i  ){


    echo 
    "<tr bgcolor=\"efefef\"><td>\n";        
    echo 
    "<b> $c. <a href=\"$php_self?action=bycatagory&cat_name=$h[cat_name]\"   TITLE=\"$h[cat_notes]\">$h[cat_name]</a></b>";    
    echo 
    "&nbsp;&nbsp; <font color=\"#006600\">(<i>$num</i>)</font>";
    echo 
    "</td></tr>\n";}
    else {
    echo 
    "<tr bgcolor=\"#DFDFDD\"><td>\n";        
    echo 
    "<b> $c. <a href=\"$php_self?action=bycatagory&cat_name=$h[cat_name]\" TITLE=\"$h[cat_notes]\">$h[cat_name]</a></b>";    
    echo 
    "&nbsp;&nbsp; <font color=\"#006600\">(<i>$num</i>)</font>";
    echo 
    "</td></tr>\n";
    }

    }

    this the right code, it`s working fine, the $table is defined in the config file

    thx for help !


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •