Hiding Multiple Rows with no results in php

I have a sql database returning data into a php table, on some of the results I have empty rows returning because their is no data being returned. Is it possible to use a php to hide the rows that come back without results?

[php]// Connects to your Database
mysql_connect("", “”, “”) or die(mysql_error());
mysql_select_db("") or die(mysql_error());
//Get PlayerID from URL
$iPlayerID = $_GET[“PlayerID”];
$iNationID = $_GET[“NationID”];

$oPlayerInfo = mysql_query("
SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam, Players.FullName
FROM Players
Left JOIN CNGHLTeams
ON Players.CNGHLID=CNGHLTeams.CNGHLID
Left JOIN NHLTeams
ON Players.TeamsID=NHLTeams.TeamID
Left JOIN Countries
ON Players.NationID=Countries.NationID
Left JOIN DraftTeam
ON Players.DraftID=DraftTeam.DraftID
WHERE Players.PlayerID=$iPlayerID
ORDER BY Players.LastName;
") or die(mysql_error());
$row = mysql_fetch_array($oPlayerInfo);
?>

<?PHP echo "CNGHLDB - " . $row["FullName"] ?>

img.top {vertical-align:text-top;}
img.bottom {vertical-align:text-bottom;}
a {text-decoration:none;}

<?PHP { Print ""; ECHO "
"; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO "

 

"; Print "

"; Print ""; Print ""; Print ""; Print ""; Print ""; $DOB = $row[DOB]; //dd.mm.yyyy $user_date = new DateTime($DOB); $curr_date = new DateTime(); $age_cal = $curr_date->diff($user_date); Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print " "; Print "

".$row['FirstName']." ".$row['LastName']." 

Birthdate: ".$row['DOB']." Age: ".$age_cal->y;"
"; Print "
Nation: ".$row['Nation']." CNGHL Team: ".$row['CNGHLRights']. "
Position: ".$row['Position']. " Weight: ".$row['Weight']. "
Height: ".$row['Height']. " NHL Team: ".$row['Team']. "
Draft Year: ".$row['CNDraftYR']." Draft Position: ".$row['CNDraftPOS']."
Drafted By: ".$row['DrTeam']." 
 
"; Print "
"; } $oPlayerStats = mysql_query(" SELECT SeasonStats.Sea, SeasonStats.TeamID, SeasonStats.GP, SeasonStats.Goals, SeasonStats.Assists, SeasonStats.Points, SeasonStats.PlusMinus, SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH, SeasonStats.GW, SeasonStats.GT, SeasonStats.S, Seasonteam.Team, SeasonStats.SubSeason FROM SeasonStats Left JOIN Seasonteam On SeasonStats.TeamID=Seasonteam.TeamID WHERE SeasonStats.PlayerID=$iPlayerID ORDER BY SeasonStats.Sea ASC,SeasonStats.SubSeason ASC; ") or die(mysql_error()); Print ''; Print "

"; ECHO "
"; ECHO "
"; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; ECHO ""; while($row = mysql_fetch_array($oPlayerStats)) { Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; } Print "
Season
Team
GP
G
A
P
PIM
+/-
PPG
SHG
GWG
GTG
Shots
".$row['Sea']."".$row['Team']."".$row['GP']."".$row['Goals']."".$row['Assists']."".$row['Points']."".$row['Pim']."".$row['PlusMinus']."".$row['PP']."".$row['SH']."".$row['GW']."".$row['GT']."".$row['S']."
"; [/php]

Yep, just use an if statement and empty() to filter out the empty rows. I couldn’t tell u where to put it though.

Why are you mixing echo and print? there’s nothing technically wrong with it, but its always good to be consistent. On that, you can actually do the entire page with just a few echoes. For example, lines 45 - 66 would become:
[php]echo "

SEARCH PLAYERS SEARCH GOALIES FRANCHISE HISTORY

 

 

";[/php]Also fixed the depreciated html, well most of it anyways.

$row[FirstName] $row[LastName] 

Birthdate: $row[DOB]

$row[FirstName] is wrong as well as all the other variables without the quotes.

CORRECT

$row[‘FirstName’]

How would I code it to hide the row if I for instance wanted to hide

[php]
Print “

Draft Year: “.$row[‘CNDraftYR’].””;
Print “ Draft Position: “.$row[‘CNDraftPOS’].””;
Print “”;
Print “”;
Print “ Drafted By: “.$row[‘DrTeam’].””;
Print " ";
[/php]

I have tried to do it and put it in between lines 3&4 but i get syntax errors.

[php]if empty (‘CNDraftYR’)[/php]
[php]if empty (‘CNDraftPOS’)[/php]
[php]if empty (‘DrTeam’)[/php]

[php]
Print “

”;
Print “

”.$row[‘FirstName’]." “.$row[‘LastName’].” <img src=“http://www.cnghl.org/cnghldb/nation/".$row[‘NationID’].".gif”>

";
Print “”;
Print “”;
Print “ Birthdate: “.$row[‘DOB’].””;
$DOB = $row[DOB]; //dd.mm.yyyy
$user_date = new DateTime($DOB);
$curr_date = new DateTime();
$age_cal = $curr_date->diff($user_date);
Print “ Age: “.$age_cal->y;””;
Print "<td style='vertical-align:top;'width=‘275’ rowspan=‘10’>
<img src="http://www.cnghl.org/cnghldb/images/".$iPlayerID.".jpg">";
Print “
”;
Print “”;
Print “ Nation: “.$row[‘Nation’].””;
Print " CNGHL Team: ".$row[‘CNGHLRights’]. “”;
Print “”;
Print “”;
Print " Position: ".$row[‘Position’]. “”;
Print " Weight: ".$row[‘Weight’]. “”;
Print “”;
Print “”;
Print " Height: ".$row[‘Height’]. “”;
Print " NHL Team: ".$row[‘Team’]. “”;
Print “”;
Print “”;
Print “ Draft Year: “.$row[‘CNDraftYR’].””;
Print “ Draft Position: “.$row[‘CNDraftPOS’].””;
Print “”;
Print “”;
Print “ Drafted By: “.$row[‘DrTeam’].””;
Print " ";
Print “”;
Print "
[/php]

your query is incomplete. You should not be getting back empty rows. You need to add additional AND clauses to your WHERE and use is not null on your column fields

$row[FirstName] will work just fine. I use that syntax all the time, never had an issue with it or gotten any error messages from it. What I put up there as an example will work just fine.

You can have empty columns. He’s only connecting on the id’s. Whether the query is wrong or not, I don’t know.

You were getting errors because you forgot a ) at the end
[php]if(!empty($row[‘CNDraftYR’])) {
echo "

Draft Year: “.$row[‘CNDraftYR’].”
Draft Position: “.$row[‘CNDraftPOS’].”


Drafted By: “.$row[‘DrTeam’].”
 ";
}[/php]
In this instance, I’m telling it to echo if the CNDraftYR column is not empty (! = not), anything else won’t be displayed.

Richei, turn your error reporting full on and then tell me it’s okay. I am assuming you are current on your php version.

It USED to be ok on older PHP versions. If you are current on your PHP version you will indeed get an error message if you have error reporting turned all the way on.

I did, and it does throw an error. But, error reporting is only turned on with a production server, very few live servers have it on. So while it’ll give errors when testing, once he uploads it, those will go away.

You seriously just going to go with, “It will just go away” even after validating for yourself that it is incorrect coding? I am absolutely speechless at this point.

im lazy and hate wasting space on extra stuff if it can be avoided. yesterday was the first time in probably 5 years that I had ever seen an error message.

OMG! I think we will just leave it at that.

Sponsor our Newsletter | Privacy Policy | Terms of Service