• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Need certain entries in a database to be displayed in italics

Where ever a row has a '1' for 'isUniversitySystem', I need the universityName to print in italics.  I cannot figure out how to do this.   below is the the data dump from my database.  Bear in my I need it done programmatically. Below the code from my database is the php code that i want modified.  Thanks


-- Table structure for table `alaska`
--

CREATE TABLE IF NOT EXISTS `alaska` (
  `universityID` int(11) NOT NULL AUTO_INCREMENT,
  `universityName` varchar(30) DEFAULT NULL,
  `stateID` int(11) DEFAULT NULL,
  `isUniversitySystem` int(2) DEFAULT NULL,
  PRIMARY KEY (`universityID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dumping data for table `alaska`
--

INSERT INTO `alaska` (`universityID`, `universityName`, `stateID`, `isUniversitySystem`) VALUES
(1, 'Alaska Bible College', 2, 0),
(2, 'Alaska Pacific University', 2, 0),
(3, 'University of Alaska System', 2, 1),
(4, 'Anchorage', 2, 0),
(5, 'Fairbanks', 2, 0),
(6, 'Southeast', 2, 0);

Open in new window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
  {
  echo $row['universityName'];
  echo " " . $row['universityID'];
  echo "<br />";
  }
mysql_close($con);
?>

Open in new window



0
NewWebDesigner
Asked:
NewWebDesigner
  • 3
2 Solutions
 
cfEngineersCommented:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
  {
  if ($row['universityID'] = "1"){
  	echo "<em>".$row['universityName']."</em>";)
  else {
  	echo $row['universityName'];)
  }
  echo " " . $row['universityID'];
  echo "<br />";
  }
mysql_close($con);
?>

Open in new window

0
 
cfEngineersCommented:
typo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
  {
  if ($row['universityID'] == "1"){
  	echo "<em>".$row['universityName']."</em>";)
  else {
  	echo $row['universityName'];)
  }
  echo " " . $row['universityID'];
  echo "<br />";
  }
mysql_close($con);
?>

Open in new window

0
 
cfEngineersCommented:
another typo lol
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
  {
  if ($row['universityID'] == "1"){
  	echo "<em>".$row['universityName']."</em>";
  else {
  	echo $row['universityName'];
  }
  echo " " . $row['universityID'];
  echo "<br />";
  }
mysql_close($con);
?>

Open in new window

0
 
Ray PaseurCommented:
Maybe something like this...

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
{
    extract($row);
    $alpha = $omega = NULL;
    if ($isUniversitySystem == 1)
    {
        $alpha = '<i>';
        $omega = '</i>';
    }
    echo $alpha . $universityName . $omega;
    echo "<br />";
  }

Open in new window

0
 
Jagadishwor DulalBraces MediaCommented:
First I want to show one mistake in your post that is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

Open in new window

Here you already have closed your body tag that is not good html your content should be inside <body></body> tag.
And Your solution is:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM alaska");

while($row = mysql_fetch_array($result))
  {
	  if($row['isUniversitySystem']==1){
	 echo "<em>".$row['universityName']."</em>"; 
	  }else{
		   echo $row['universityName'];
	  }
  echo " " . $row['universityID'];
  echo "<br />";
  }
mysql_close($con);
?>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now