PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello,
I need to apply a hyperlink for all first element in each row of a table which is dynamically retrieved.
Assume:Select query returns 8 rows & 2 columns.But rows & columns will be changed according to the query.So my problem is ,i need to apply a hyperlink to data in first column.So can u help me to do that it will be very grateful.
This is my code....
if (isset($_POST['search'])){
/*{print_r($_POST);}*/
$tx=$_POST['sea'];
//$result =mysql_query("select * from strdet where taxt ='$tx' || odrno ='$tx'");
//$query = "select field1, fieldn from table [where clause][group by clause][order by clause][limit clause]";
//$output=mysql_query("Select * from strdet
$result =mysql_query("select * 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"$i";
echo "</tr>";
/*$myQuery = "show columns from strdet";
$result = mysql_query($myQuery);
$row = mysql_fetch_row($result);
$columnCount = count($row);
echo"$columnCount";*/
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
[b] echo '<td align="center"><a href='. $data .'>'. $data .'</a>';[/b]
}
}
}else{
echo "<td align='center'>No Results found</td></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
}
?>
bolded part will apply hyperlink to all data in retreived data...
Hope i explained everything in my mind.So please be kind enough to give a help.
Thank you.
<?php
$result =mysql_query("select * 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%' ");
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Actually thanks for your reply.
But it confused me a lot.So can u be more specific....
I couldn't understand.so can u edit it in my code?.If u do it it will be very grateful.
Actually i couldn't edit your code because i don't know what fields you want to use. What fields are in the table because if you use the asterisk in a SELECT statement (SELECT * FROM table) it means select ALL fields. If you had 20 fields, it would select all 20. What fields are in your table?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering