Hi!
I have a table with few thousand records on few pages in a simple html table.. I made a search function that works fine apart from one thing... It displays only one result in a table (which is great cause it means it works!).But... I was wondering is there a way to display back the table with all records, with the one that i was searching for in the middle and highlighted? Here's a simplified table that I have :

<table class="nogap" cellpadding="1" bgcolor="#00000" cellspacing="1"  style="margin:110px 0 0 5px; width:100%; border-color:#B6D6F6;" >
  <tbody>
  <?php include 'dbconn.php';?>
   $con = mysqli_connect($host,$user,$pass,$db) or  (header( 'Location: errorpage.php' ));
 if (mysqli_connect_errno($con))
  {  header( 'Location: errorpage.php' );  }

 $sql = "SELECT *
        FROM $tb1 ORDER BY  (Serial_num +1)
         LIMIT $offset, $rowsperpage";
  $result = mysqli_query($con, $sql) or (header( 'Location: errorpage.php' ));
  $row = mysqli_num_rows($result);
  while ($row = $result->fetch_assoc())
{
$product = $row['Prod_type'].$row['Serial_num'];

<tr id="mstrTable" class="lovelyrow">
<td width="5%"><?php echo $product;?></td>
<td width="5%"><?php echo $row['Customer'];?></td>
<td width="7%"><a href="#" onmouseover="ajax_showTooltip(window.event,'getptn.php?prd=<?php echo $p;?>',this);return false" onmouseout="ajax_hideTooltip()"><?php echo      $row['Prod_info'];?></a></td>
</tr>
}
</table>

Thanks!

Member Avatar for diafol

Why don't you have it at the start?

Easy enough to do - pseudocode

wanted = 12
output = ''
first_record = ''

loop

if(this_record == wanted)
   first_record = this_record
else
    output = output + this_record

end loop

show first_record + output

But that will swap the records will it not...? I need them all in the same order as before bu something like "autofocus on last modified"....

Member Avatar for diafol

OK, well just apply a class. I'm using mysql_* functions for clarity, but change those to PDO or mysqli_* or whatever you're using instead.

$id = (isset($_GET['id'])) ? (int) $_GET['id'] : 0;
$output = "<table><thead><tr><th>FIELD 1</th><th>FIELD 2</th><th>FIELD 3</th></tr></thead><tbody>";

while($data = mysql_fetch_assoc($result))
{
    $class = ($data['id'] = $id) ? " class='selected'" : '';
    $output .= "<tr$class><td>{$data['field1']}</td><td>{$data['field2']}</td><td>{$data['field3']}</td></tr>";
}
$output .= "</tbody></table>";

//then where you need the table...
echo $output;

Not tested. This is pretty horrible as it uses php to spit out the html. There are many variations for this such as html with inline php for values or even use of the heredoc syntax.

Your CSS should now be able to pinpoint 'tr.selected'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.