SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: How to view just 1 article ?

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

    How to view just 1 artical ?

    Hi all

    if i have in catagory table,and there 20 catagory and in each catgory 10 campany, and for each company there are 20 artical , how can i view for each company 1 artical in page ?

  2. #2
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the structure of the database and the action :

    Code:
    Field        Type         Attributes   Null Default Extra 
    ID           int(7)       UNSIGNED     No    auto_increment  
    title        varchar(20)               Yes      
    date         date                      Yes      
    company_id   int(7)                    No        0    
    catagory     varchar(30)               Yes    
    news         blob                      Yes      
    readmore     blob                      Yes      
    link         blob                      Yes      
    act          varchar(30)               No      
    filename     varchar(30)               No      
    counter      mediumint(8)  UNSIGNED    No         1
    and here is the action :

    PHP Code:
    <?
    if($action == "showcat"){

      if(!
    $catagory){
                 
    error();
        }
        
    $query mysql_query("Select * from $table where catagory='$catagory' ");

        
    $count mysql_num_rows($query);
        for(
    $i =0$i $count$i++){
        
    $h mysql_fetch_array($query);


        
    arttable("$h[title]","$h[news]","$h[readmore]");
         echo 
    "<br> $h[company_id] ";
         echo 
    "<a href=\"?action=showmore&company_id=$h[company_id]\">cccccc</a>";
    }

    }

    ?>

  3. #3
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your query...(the mysql query) use LIMIT 1 at the end of it...plus I have a small change in your for loop, so it looks better than a for() loop.
    PHP Code:
    <?
    if($action == "showcat"){

      if(!
    $catagory){
                 
    error();
        }
        
    $query mysql_query("Select * from $table where catagory='$catagory' ");

        while (
    $h mysql_fetch_array($query)) {

        
    arttable("$h[title]","$h[news]","$h[readmore]");
         echo 
    "<br> $h[company_id] ";
         echo 
    "<a href=\"?action=showmore&company_id=$h[company_id]\">cccccc</a>";
    }

    }

    ?>
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

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
  •