...

View Full Version : View Only Active Titles



CoolAsCarlito
08-08-2008, 05:46 PM
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

// 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


?>

NeoPuma
08-08-2008, 05:52 PM
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.

CoolAsCarlito
08-08-2008, 05:57 PM
There is a row in my database called status and in the records it's either active or inactive.

NeoPuma
08-08-2008, 06:01 PM
Try a query like this maybe?

$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?

CoolAsCarlito
08-08-2008, 06:34 PM
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

// 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>';



?>

CoolAsCarlito
08-08-2008, 07:54 PM
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

// 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>';



?>

NeoPuma
08-08-2008, 08:58 PM
I would say your best bet is to do two queries, like so:

<?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>';

CoolAsCarlito
08-08-2008, 09:24 PM
Thank you that helped me.

masterofollies
08-09-2008, 04:39 AM
To list all the active titles, you will need a loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum