Page 1 of 1

file viewer functionality to dynamic data

Posted: Tue Jan 18, 2011 5:11 am
by ishakya
Hello every one,
I have created a table to retrieve details dynamically.Retrieving part is okay.And all the values in the first column are hyper linked.So now i want to apply File viewer functionality to get more details of the data which a user want.I have no idea about to do that when a user click on the hyperlink.
Here is the code.......

Code: Select all

$result =mysql_query("select $fieldStr from strdet where styid  LIKE '%$tx%' || styname LIKE '%$tx%' || odrno ='$tx' ||  odrdet LIKE '%$tx%' || date LIKE '%$tx%' || merch LIKE '%$tx%' || gen LIKE '%$tx%' || taxt  LIKE  '%$tx%' ");


 if (($result)||(mysql_errno == 0))
{
  echo "<table width='100%' border='0' cellspacing='1'><tr>";
  if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    
    echo "</tr>";

    //display the data
    
    while ($rows = mysql_fetch_assoc($result))
    {
        $j = 0;
        foreach ($rows as $data)
        {
          
            if ($j++ <= 0)
            {  echo "<tr>";
			
               printf('<td align="center"><a href="%s">%s</a></td>', $data, $data);
            }
            else
            {
                printf('<td align="center">%s</td>', $data);
				echo "</td>";
            }
			
        }
		echo "</tr>";
    }
	
  }else{
    echo "<td align='center'>No Results found</td></tr>";
  }

  echo "</table>"; 
}else{
  echo "Error in running query :". mysql_error();
}  
So if anyone have some idea please do share with me..
Thanks.

Re: file viewer functionality to dynamic data

Posted: Tue Jan 18, 2011 3:25 pm
by mpetrovich
What do you mean by File View functionality? Do you mean you want to see the record details?

You probably want to have a link like this: /mypage.php?record=XXX, where XXX is the record ID

Then you want to use $_GET['record'] and clean it, with something like preg_replace('/[^0-9]/', '', $str), to make you only get integer values.

Then if $_GET['record'] is not empty, output the record, otherwise, output the table.

Good luck.

Re: file viewer functionality to dynamic data

Posted: Wed Jan 19, 2011 9:50 pm
by ishakya
Thanks,
Yes i want to see the record details.it happens when i click or move mouse over it,should display detail records.
My problem is href is only applied to data of first column.
here is the code....

Code: Select all

$result =mysql_query("select $com from strdet where styid  LIKE '%$tx%' || styname LIKE '%$tx%' || odrno ='$tx' ||  odrdet LIKE '%$tx%' || date LIKE '%$tx%' || merch LIKE '%$tx%' || gen LIKE '%$tx%' || taxt  LIKE  '%$tx%' ");
This part gonna select the data.

Code: Select all

if (($result)||(mysql_errno == 0))
{
  echo "<table width='100%' border='0' cellspacing='1'><tr>";
  if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    
    echo "</tr>";
This part will print the headers.

Code: Select all

while ($rows = mysql_fetch_assoc($result))
    {
        $j = 0;
        foreach ($rows as $data)
        {
          
            if ($j++ <= 0)
            {  echo "<tr>";
			
               printf('<td align="center"><a href="%s">%s</a></td>', $data, $data);
            }
            else
            {
                printf('<td align="center">%s</td>', $data);
				echo "</td>";
            }
			
        }
		echo "</tr>";
    }
This part will print details.
And most necessary part is printing data with a hyperlink

Code: Select all

if ($j++ <= 0)
            {  echo "<tr>";
			
               printf('<td align="center"><a href="%s">%s</a></td>', $data, $data);
            }
            else
How should i apply above mentioned functionality?. Hope you will help to figure it out....
Thanks again......

Re: file viewer functionality to dynamic data

Posted: Thu Jan 20, 2011 8:02 am
by mpetrovich
You are missing some details.

1) In your select statement, you need to get the record id. I assume it is: styid. That number should be an autoincrement index of the database.

2) You need the page you are using, so you can use, href="/mypage.php?record=$row_id"

3) I think your code should be something like this:

Code: Select all

<?php
while ($row = mysql_fetch_assoc($result)) {
    echo '<tr>';
    foreach ($row as $key => $value) {     
        if ($key == 'styid') {                     
           echo '<td align="center"><a href="/mypage?record=' . $value . '">View</a></td>';
        } else {
           echo '<td align="center">' . $value . '</td>';
        }                   
    }
    echo '</tr>';
}