?
Solved

Need certain entries in a database to be displayed in italics

Posted on 2011-05-05
5
Medium Priority
?
223 Views
Last Modified: 2012-06-27
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
Comment
Question by:NewWebDesigner
  • 3
5 Comments
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35700519

<!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
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35700525
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
 
LVL 6

Expert Comment

by:cfEngineers
ID: 35700665
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 35700954
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
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 1000 total points
ID: 35704294
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question