...

View Full Version : No second page



CoolAsCarlito
08-13-2008, 08:18 PM
Can someone figure out how this guy does this:

http://epw.e-wrestling.org/titlehistories.php

I mean how when you click on a title it doesn't have to go to another page but just brings up that titles info. I'm trying to but the only way it seems to like I have to have it have a second page.

Fou-Lu
08-13-2008, 08:25 PM
It passes the data back to itself and extracts the id from the $_GET. It can be seen in the url for it.


<?php

if (isset($_GET['id']))
{
// Do stuff to show an individual record
}
else
{
// do stuff to show all records
}

CoolAsCarlito
08-13-2008, 08:31 PM
Does this look right?



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

if (isset($_GET['id']))
{
// Do stuff to show an individual record
}
else
{
// do stuff to show all records
}



print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></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="titlehistory.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>';

//Define the query
$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="titlehistory.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>';
?>

Fou-Lu
08-13-2008, 09:37 PM
Yes and no. The code looks ok, but the logic is off. What you have posted appears to be the All records stuff that would go into the else block. You need to program the if block for if id is provided. Change the query inside the new if block to use a where on the provided id to fetch just the one record you want.

CoolAsCarlito
08-13-2008, 09:39 PM
I must apologize buddy I'm having a hard time understanding what you are saying.


Yes and no. The code looks ok, but the logic is off. What you have posted appears to be the All records stuff that would go into the else block. You need to program the if block for if id is provided. Change the query inside the new if block to use a where on the provided id to fetch just the one record you want.

Fou-Lu
08-14-2008, 08:50 AM
All of this:


print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></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="titlehistory.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>';

//Define the query
$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="titlehistory.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>';

Appears to belong in the else part of the if / else call. You need to rewrite code to place into the if section to show the individual information:


if (isset($_GET['id']))
{
// Do you're stuff for a specific record here
}
else
{
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></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="titlehistory.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>';

//Define the query
$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="titlehistory.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>';
}

CoolAsCarlito
08-14-2008, 08:32 PM
I worked with the code and for some reason I just couldn't get it to do it.

I'm trying to take a script I saw on one page and add it to my own since it's exactly what I was wanting to do in the first place.

This is what I'm wanting to happen:

http://epw.e-wrestling.org/titlehistories.php

ninnypants
08-15-2008, 04:05 AM
if (isset($_GET['id']))
{
// Do stuff to show an individual record
}
else
{
// do stuff to show all records
// This section needs to be your code
// that displays the page as normal
}

So what you need to do is


if (isset($_GET['id']))
{
// Do you're stuff for a specific record here
// This section you would write all the code for the page
// that needs to be displayed when "$_GET['id']" is defined
}
else
{
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></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="titlehistory.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>';

//Define the query
$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="titlehistory.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>';
}

CoolAsCarlito
08-15-2008, 04:23 PM
I'm getting a
Parse error: parse error, unexpected T_ELSE in /home/content/y/a/n/yankeefaninkc/html/titlehistory5.php on line 36.

Here's my 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;
}

if (isset($_GET['id']))
{
//Define the query
$query = "SELECT *, DATE_FORMAT(`datecreated`, '&#37;M %e, %Y') as datecreated FROM titlehistory";

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;<font color="white">Title Histories</font></td></tr>';
print '<tr><td></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><font color=red>&nbsp;KOW '.$row['titlename'].'</font></td></tr>';
print '<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
print '<table cellpadding="2" cellspacing="0" border="0" width=100%>';
print '<tr><td align=center bgcolor=#E0E0E0><b>Date Created</b></td></tr><tr><td align=center><font color=white>'.$row['datecreated'].'</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Status</b></td></tr>';
print '<tr><td align=center><font color=white>'.$row['status'].'</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Longest Reign</b></td></tr>';
print '<tr><td align=center><a href=bio.php?'.$row['longestreign'].'><b>'.$row['longestreign'].'</b></a> <font color=white>('.$row['numdays'].')</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Most Successful Defenses</b></td></tr>';
print '<tr><td align=center><a href=bio.php?'.$row['sucessdefenses'].'><b>'.$row['sucessdefenses'].'</b></a> <font color=white>('.$row['numdef'].')</font></td></tr>';
print '</table>';
}
else
{
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></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="titlehistory.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>';

//Define the query
$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="titlehistory.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>';
}
?>

ninnypants
08-15-2008, 04:26 PM
You're missing a curly brace right here


}
else
{

so it needs to be


}
}
else
{

CoolAsCarlito
08-15-2008, 04:31 PM
I get of one error and I get another.

Parse error: parse error, unexpected $ in /home/content/y/a/n/yankeefaninkc/html/titlehistory5.php on line 88

CoolAsCarlito
08-15-2008, 05:28 PM
Nevermind I got that fixed. However when I go to my http://www.kansasoutlawwrestling.com/titlehistory.php page and click on the first title it won't go to the post the info for the title.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum