Jump to content

Help needed to make this code work. Thank you!


bchandel

Recommended Posts

I have the following script a display of which can be seen at

 

http://chandel.com/try/try3.php

 

How can it be modified so the records which does not have particular field values does not print that field name. Like if a record has only First Name, Last Name then it should only print is as below:

 

First Name:Jagrup

Last Name:Parihar

 

and not like:

 

First Name: Jagrup

Last Name: Parihar

Home Phone: 

Mobile: 

Email:

Web Site:

State: 

Country: UK

 

 

 

 

 

 

 

<html>

<head>

<style type="text/css">

body{

background-color:#b0c4de;

border-top:blue solid 50px;

border-left:blue solid 50px;

}

</style>

</head>

 

<body>

<?php

$db_connect = mysql_connect("XXXX.com", "XXXX_user", "password");

mysql_select_db("XXXX_database");

$query="SELECT * FROM Directory";

$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

 

Print "<h1>My Directory</h1>";

echo "<h3>Search Results: $num records found</h3>";

 

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"Name");

$LastName=mysql_result($result,$i,"LastName");

$FirstName=mysql_result($result,$i,"FirstName");

$LastName=mysql_result($result,$i,"LastName");

$Phone=mysql_result($result,$i,"Phone");

$Mobile=mysql_result($result,$i,"Mobile");

$Email=mysql_result($result,$i,"Email");

$Web=mysql_result($result,$i,"Web");

$State=mysql_result($result,$i,"State");

$Country=mysql_result($result,$i,"Country");

 

echo "<b>$Name</b><hr>

First Name: $FirstName<br>

Last Name: $LastName<br>

Home Phone: $Phone<br>

Mobile: $Mobile<br>

Email: $Email<br>

Web Site: $Web<br>

State: $State<br>

Country: $Country<br><hr>";

 

$i++;

}

 

?>

</body>

</head>

You're mixing html and php code all over the place.

 

record 1

Name=

FirstName=Joe Bob

 

record 2

Name=Billy Bob

FirstName=

 

record3

Name=Peggy Sue

FirstName=Peggy

 

echo "<b>Database Contents</b>";

foreach ($rec as $record) {
   if ($Name) {
      echo "Name: " . $Name[$rec] . <br />";
   }

   if ($FirstName) {
      echo "First Name: " . $FirstName[$rec];
   }

   echo "<br />";
}

 

Is that what you are looking for?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.