Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    View Only Active Titles

    I have two different types of status: active and inactive. I want it to only show the active titles together. How is this done.

    Here's the page it's located at http://www.kansasoutlawwrestling.com/titlehistories.php

    I guess I'd have to loop it as well but I'm not sure how and what else I'd have to do.

    PHP Code:
    <?php

    // Connects to your Database
    $link mysql_connect("?""?""?") or die(mysql_error());
    mysql_select_db("?",$link) or die(mysql_error());
     
    if (!
    mysql_select_db("?"$link)) {
    echo 
    'Could not select database';
    exit;
    }
    //Define the query
    $query "SELECT * FROM titles";

    if (
    $r mysql_query ($query)){ // Run the query. 

    while ($row mysql_fetch_array ($r)){
    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;Title Histories</td></tr>';
    print 
    '</table>';
    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Active Titles</td></tr>';
    print 
    '<tr><td><a href="titlehistories.php?id=' $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
    print 
    '<img src="/images/' $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td></tr>';
    print 
    '</table>';
    print 
    '<img src=images/spacer.gif><br>';
    print 
    '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Inactive Titles</td></tr>';
    print 
    '<tr><td></td></tr>';
    print 
    '</table>';
    }

    } else {
    die (
    '<p>Could not retrieve the data because <b>' mysql_error() . '</b>. The query was $query.</p>');
    //End of query IF 


    ?>

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    What do you mean by status'? I mean, do the db rows have a field in it 'Active' or 'Inactive', or is it defined elsewhere? How are you checking at the moment as I couldn't really see it in your code.

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    There is a row in my database called status and in the records it's either active or inactive.

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Try a query like this maybe?
    PHP Code:
    $query "SELECT * FROM titles ORDER BY status ASC;"
    It'll display all the rows, but put all active ones first, and together, followed by all inactive ones?

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Well I have it viewing all my titles right now but I want them lined up across not done like like it is shown.

    http://www.kansasoutlawwrestling.com/titlehistory3.php

    PHP Code:
    <?php

    // Connects to your Database
    $link mysql_connect("?""?""?") or die(mysql_error());
    mysql_select_db("?",$link) or die(mysql_error());
     
    if (!
    mysql_select_db("?"$link)) {
    echo 
    'Could not select database';
    exit;
    }

    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;Title Histories</td></tr>';
    print 
    '</table>';
    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Active Titles</td></tr>';

    //Define the query
    $query "SELECT * FROM titles";

    if (
    $r mysql_query ($query)){ // Run the query. 

    while ($row mysql_fetch_array ($r)){

    print 
    '<tr><td><a href="titlehistories.php?id=' $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
    print 
    '<img src="/images/' $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a>';

    }

    } else {
    die (
    '<p>Could not retrieve the data because <b>' mysql_error() . '</b>. The query was $query.</p>');
    //End of query IF 

    print '</td></tr>';
    print 
    '</table>';
    print 
    '<img src=images/spacer.gif><br>';
    print 
    '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Inactive Titles</td></tr>';
    print 
    '<tr><td></td></tr>';
    print 
    '</table>';



    ?>

  • #6
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    I have them aligned right but how do I get them to just put the active titles under active and then create my other loop for the inactive titles to post under inactive titles.

    Here's my updated code:

    PHP Code:
    <?php

    // Connects to your Database
    $link mysql_connect("?""?""?") or die(mysql_error());
    mysql_select_db("?",$link) or die(mysql_error());
     
    if (!
    mysql_select_db("?"$link)) {
    echo 
    'Could not select database';
    exit;
    }

    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;Title Histories</td></tr>';
    print 
    '</table>';
    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar3.gif" height=35 colspan=4>&nbsp;Active Titles</td></tr>';
    print 
    '<tr>';

    //Define the query
    $query "SELECT * FROM titles";

    if (
    $r mysql_query ($query)){ // Run the query. 

    while ($row mysql_fetch_array ($r)){

    print 
    '<td><a href="titlehistories.php?id=' $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
    print 
    '<img src="/images/' $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';

    }

    } else {
    die (
    '<p>Could not retrieve the data because <b>' mysql_error() . '</b>. The query was $query.</p>');
    //End of query IF 

    print '</tr>';
    print 
    '</table>';
    print 
    '<img src=images/spacer.gif><br>';
    print 
    '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Inactive Titles</td></tr>';
    print 
    '<tr><td></td></tr>';
    print 
    '</table>';



    ?>

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    I would say your best bet is to do two queries, like so:
    PHP Code:
    <?php

    // Connects to your Database
    $link mysql_connect("?""?""?") or die(mysql_error());
    mysql_select_db("?",$link) or die(mysql_error());
     
    if (!
    mysql_select_db("?"$link)) {
        echo 
    'Could not select database';
        exit;
    }

    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;Title Histories</td></tr>';
    print 
    '</table>';
    print 
    '<table border=0 cellspacing="0" cellpadding=3 width=575>';
    print 
    '<tr><td background="images/bg_bar3.gif" height=35 colspan=4>&nbsp;Active Titles</td></tr>';
    print 
    '<tr>';

    //Define the query
    $query "SELECT * FROM titles WHERE status = 'active'"// Active rows

    if ($r mysql_query ($query)){ // Run the query. 

        
    while ($row mysql_fetch_array ($r)){
        
            print 
    '<td><a href="titlehistories.php?id=' $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
            print 
    '<img src="/images/' $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
        
        }

    } else {
        die (
    '<p>Could not retrieve the data because <b>' mysql_error() . '</b>. The query was $query.</p>');
    //End of query IF 

    $query "SELECT * FROM titles WHERE status = 'inactive'"// Inactive Rows

    if ($r mysql_query ($query)){ // Run the query. 

        
    while ($row mysql_fetch_array ($r)){
        
            print 
    '<td><a href="titlehistories.php?id=' $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
            print 
    '<img src="/images/' $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
        
        }

    } else {
        die (
    '<p>Could not retrieve the data because <b>' mysql_error() . '</b>. The query was $query.</p>');
    //End of query IF 

    print '</tr>';
    print 
    '</table>';
    print 
    '<img src=images/spacer.gif><br>';
    print 
    '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Inactive Titles</td></tr>';
    print 
    '<tr><td></td></tr>';
    print 
    '</table>';

  • Users who have thanked NeoPuma for this post:

    CoolAsCarlito (08-08-2008)

  • #8
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Thank you that helped me.

  • #9
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    To list all the active titles, you will need a loop.


  •  

    Posting Permissions

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