Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a link with a table output 1

Status
Not open for further replies.

M8KWR

Programmer
Aug 18, 2004
864
GB
Hi all,

I currently have this code

Code:
 echo "<table border='1'><thead><tr>";
            for($i = 0;$i < mysql_num_fields($sql_result);$i++)
            {
             echo "<th>".mysql_field_name($sql_result,$i).
                  "</th>";
            }
     echo "</tr></thead>
           <tbody>";
     for ($i=0;$i < mysql_num_rows($sql_result);$i++)
     {
        echo "<tr>";
        $row = mysql_fetch_row($sql_result);
        foreach($row as $value)
        {
           echo "<td>".$value."</td>";
        }
        echo "</tr>";
     }
     echo "</tbody></table>";

The code outputs the table that the user searches on, which does change depending on what table they selects.

What i am now trying to do is let the user edit a entry.

I am new to PHP - but my thinking was to use the "ID" field from each table, and turn this column into a hyperlink, so i can carry the ID number across to my next page in my site to update that line within the table; which i am struggling to do, could someone help or point me in the right direction.....

Also can you carry more then one think across within a hyperlink???

Any help would be appreciated, thanks in advance.
 
Sure, why not just surround the value with link tags?
 
not to sound stupid or anything, but how would i do that.....

thanks
 
i guess you did not write the code you posted above. i'd suggest generally restructuring it. but anyway ...
change

Code:
  echo "<td>".$value."</td>";
to
Code:
foreach($row as $key=>$value){
	if ($key === "ID"){
		echo "<td><a href=\"somepage.php?id=$value\">$value</a></td>";
	} else {
		echo "<td>$value</td>";
	}
}

this assumes that ID is the name of the primary key.
 
Brilliant.


I had to mess about with the formatting as copying and pasting did not seem to work, but fantastic, made my day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top