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;" >
  <?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>


Edited by LD-005

5 Years
Discussion Span
Last Post by diafol

Why don't you have it at the start?

Easy enough to do - pseudocode

wanted = 12
output = ''
first_record = ''


if(this_record == wanted)
   first_record = this_record
    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"....

Edited by LD-005


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'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.