Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
sirTemplar
Forum Commoner
Posts: 65 Joined: Wed Dec 18, 2002 1:57 am
Post
by sirTemplar » Wed Dec 18, 2002 1:57 am
hi people!
i have the following code:
if ($CNOMEN == "")
{$CNOMEN = '%';}
if ($NOMRL == "")
{$NOMRL = '%';}
// Change this to fit your database
$result = mysql_query ("SELECT * FROM friarsofmconv
WHERE CNOMEN LIKE '%$CNOMEN%'
AND NOMRL LIKE '%$NOMRL%'
",$conn);
if ($row = mysql_fetch_array($result)) {
do {
PRINT "<b>Surname:</b> ";
print $row["CNOMEN"];
print ("<br>");
PRINT "<b>Name:</b> ";
print $row["NOMRL"];
print ("<br>");
PRINT "<b>Province/Custody:</b>";
print $row["PROVEN"];
print ("<br>");
PRINT "<b>Ordination:</b>";
print $row["SACDAT1"];
print ("<p>");
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>
the result looks like this:
Surname: Cubacub
Name: Bernard M.
Province/Custody: Provincial Custody (Nap.)
Ordination:
since the ordination field is empty on the database i would like it to appear:
Surname: Cubacub
Name: Bernard M.
Province/Custody: Provincial Custody (Nap.)
what code do i need to add in order for it
not to be printed on the result. thanks.
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Wed Dec 18, 2002 7:43 am
sirTemplar,
Try something like this:
Code: Select all
<?php
if (isset($row["SACDAT1"]) && strcasecmp($row["SACDAT1"],""))
{
echo "<b>Ordination:</b>\n";
echo "$row["SACDAT1"]\n";
}
?>
This way it will only display it if it exists and is not blank.
I use echo as a preference and if you search the forums you will find some discussion as to the pros and cons of print and echo.
John M
sirTemplar
Forum Commoner
Posts: 65 Joined: Wed Dec 18, 2002 1:57 am
Post
by sirTemplar » Wed Dec 18, 2002 9:13 am
thanks for the quick reply! it worked but you see i am really a newbie and i need more help. the problem now is the spacing.
when the field is empty, it attaches itself to the former data:
Surname: Pérez Martínez
Name: Celso
Province/Custody: Spain - Province
Surname: Perez
Name: Tarsicius M.
Province/Custody: Philippines - Provincial Custody (Nap.)
Surname: Marcos Pérez
Name: César
Province/Custody: Spain - Province
this is the code right now!
do {
echo "<table border=0 cellpadding=2 cellspacing=0 style=border-collapse: collapse bordercolor=#111111>";
echo "<tr><td><b><font face=Verdana size=2 color=#0000FF>Surname: </font></b></td>
<td><b><font face=Verdana size=2 color=#800000>{$row['CNOMEN']}</td></b></tr>";
echo "<tr><td><b><font face=Verdana size=2 color=#0000FF>Name: </font></b>
<td><b><font face=Verdana size=2 color=#800000>{$row['NOMRL']}</td></b></tr>";
echo "<tr><td><b><font face=Verdana size=2 color=#0000FF>Province/Custody: </font></b></td>
<td><b><font face=Verdana size=2 color=#800000>{$row['PROVEN']}</td></b></tr>";
if (isset($row["SACDAT1"]) && strcasecmp($row["SACDAT1"],""))
{
echo "<tr><td><b><font face=Verdana size=2 color=#0000FF>Ordination: </font></b></td>
<td><b><font face=Verdana size=2 color=#800000>{$row['SACDAT1']}</td></tr></table>";
}
echo ("<p>");
echo ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>
how can i make it appear like this:
Surname: Pérez Martínez
Name: Celso
Province/Custody: Spain - Province
Surname: Perez
Name: Tarsicius M.
Province/Custody: Philippines - Provincial Custody (Nap.)
Surname: Marcos Pérez
Name: César
Province/Custody: Spain - Province
hope to hear from you again!
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Wed Dec 18, 2002 9:25 am
Add an else statement:
Code: Select all
<?php
<?php
if (isset($row["SACDAT1"]) && strcasecmp($row["SACDAT1"],""))
{
echo "<b>Ordination:</b>\n";
echo "$row["SACDAT1"]\n";
}
else
{
echo "<tr>\n";
echo "<td> \n"; // or use this echo "<td><hr size="80%''>\n";
echo "</td>\n";
echo "</tr>\n";
}
?>
?>
Something along this line should do the trick. You could also throw a horizontal rule in too.
John M