Jump to content

Need HTML table in PHP


farnoise

Recommended Posts

Hi Everyone.

  I have a PHP page that generates a list of records in a page, Everything works fine but I have a TINY question. When page shows the data I need them in the following table format, the one that I already use looks stupid so I want to use this format, This is the HTML code does anyone know how can I convert it into PHP echo function.

 

Thanks a lot

 

<table width="418" border="1">
  <tr>
    <td width="144" rowspan="5"><div align="center">PIC GOES HERE </div></td>
    <td width="100">Name:</td>
    <td width="152"> $name  </td>
  </tr>
  <tr>
    <td>Cell number </td>
    <td>$cellnumber</td>
  </tr>
  <tr>
    <td>DATE</td>
    <td>$date</td>
  </tr>
  <tr>
    <td>Extension</td>
    <td>$ext</td>
  </tr>
  <tr>
    <td>Address:</td>
    <td>$address</td>
  </tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/188914-need-html-table-in-php/
Share on other sites

<table width="418" border="1">
  <tr>
    <td width="144" rowspan="5"><div align="center">PIC GOES HERE </div></td>
    <td width="100">Name:</td>
    <td width="152"> <? echo $name; ?> </td>
  </tr>
  <tr>
    <td>Cell number </td>
    <td><? echo $cellnumber; ?></td>
  </tr>
  <tr>
    <td>DATE</td>
    <td><? echo $date; ?></td>
  </tr>
  <tr>
    <td>Extension</td>
    <td><? echo $ext; ?></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><? echo $address; ?></td>
  </tr>
</table>

Thanks RaythMistwalker,

But the problem is my page is doing loop so its going through my whole database and it generates New table everytime that it finds something that matches my Search creteria.

 

Just imagine a phone book so I might have 6 or 7 Search result so I cant use them in Static HTML table, I need something that Generate new table each time Here is the Table code that i' m using right now

 

while($result = mysql_fetch_array( $data )) 
{ 
echo "<table border='1' class='sample'>";
echo "<tr> <th>Name, Lastname</th> <th>Department</th> <th>Cell</th> <th>Office / Ext.</th> <th>Secondary #</th></tr>";
echo "<tr><td>";
echo $result['name'];
echo "</td><td>"; 
echo $result['dep']; 
echo "</td><td>";
echo $result['cell'];
echo "</td><td>"; 
echo $result['ext'];
echo "</td><td>";
echo $result['F63'];
echo "</td><td>";
echo $result['F2'];  
echo "</td></tr>"; 
echo "<tr> <th>";
echo $result['F6']; 
echo "<tr> <th>";

} 

 

Thganks again

I don't think I can see this issue as a problem however the way that I'm currently having my Table is not working out for me so I need to do it in this format structure,

The code that I submitted above works fine but as you said I need to it in neater way!!!!

 

 

while($result = mysql_fetch_array( $data ))
{
echo <<<HEREDOC
<table width="418" border="1">
  <tr>
    <td width="144" rowspan="5"><div align="center">PIC GOES HERE </div></td>
    <td width="100">Name:</td>
    <td width="152"> {$name}  </td>
  </tr>
  <tr>
    <td>Cell number </td>
    <td>{$cellnumber}</td>
  </tr>
  <tr>
    <td>DATE</td>
    <td>{$date}</td>
  </tr>
  <tr>
    <td>Extension</td>
    <td>{$ext}</td>
  </tr>
  <tr>
    <td>Address:</td>
    <td>{$address}</td>
  </tr>
</table>
HEREDOC;
}

All you have to do is define those variables now with the data from your database..

<link href="../css/lightstyle.css" type="text/css" rel="stylesheet" />
<?php include("../header.php"); ?>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<form name="search" method="post" action="<?=$PHP_SELF?>">
<fieldset><legend>Phonebook System</legend><input name="find" type="text" value="Search" maxlength="100" />
  <div align="left"><h5>
    
    <Select NAME="field" class="arad">
      <option value="name">Name and(or) Last name</option>
      <option value="cell">Cell Number</option>
      <option value="ext">Extension / Office</option>
      <option value="dep">Department</option>
    </Select>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" class="btt1"/>
  </div>
</form>

  
    <div align="left">
      <p>
        <? 
//This is only displayed if they have submitted the form 
if ($searching =="yes") 
{ 
echo "<h5>Results<p>"; 

//If they did not enter a search term we give them an error 
if ($find == "") 
{ 
echo "<p>You forgot to enter a search criteria"; 
exit; 
} 

// Otherwise we connect to our Database 
mysql_connect("localhost", "USER", "PASS") or die(mysql_error()); 
mysql_select_db("movedb") or die(mysql_error()); 

// We preform a bit of filtering 
$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 

//Now we search for our search term, in the field the user specified 
$data = mysql_query("SELECT * FROM sheet1sa WHERE upper($field) LIKE'%$find%'"); 

//And we display the results 
while($result = mysql_fetch_array( $data )) 
{ 
echo "<table border='1' class='sample'>";
echo "<tr> <th>Name, Lastname</th> <th>Department</th> <th>Cell</th> <th>Office / Ext.</th> <th>Secondary #</th></tr>";
echo "<tr><td>";
echo $result['name'];
echo "</td><td>"; 
echo $result['dep']; 
echo "</td><td>";
echo $result['cell'];
echo "</td><td>"; 
echo $result['ext'];
echo "</td><td>";
echo $result['F6'];
echo "</td><td>";
echo $result['F2'];  
echo "</td></tr>"; 


} 
//This counts the number or results - and if there wasn't any it gives them a little message explaining that 
$anymatches=mysql_num_rows($data); 
if ($anymatches == 0) 
{ 
echo "<h5>Sorry, but I can not find the person that you are looking for.<br><br>Thanks"; 
} 

//And we remind them what they searched for 
echo "<b><h5>Searched For:</b></b> " .$find; 
echo "<br>"; 
echo "<br>"; 
} 
?>
<head>
</head>
<body>
      </p>
      <p> </p>
      <hr width="500" size="1" />
      <p> </p>
      <p> </p>
      <p align="center">
</p>
</body>
  </html>    

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.