RawDog Posted September 20, 2009 Share Posted September 20, 2009 This has been one million of times on other sites, but I still can't figure out how to do this. I want a search result that shows up as a link, not just plain text. I thought it came from the echo""; function, but I was wrong. Is there anyway to do this? Thanks! Link to comment Share on other sites More sharing options...
jlhaslip Posted September 20, 2009 Share Posted September 20, 2009 Does this snippet help? // Make the query.$query = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY $order_by LIMIT $start, $display"; $result = @mysql_query ($query); // Run the query.// Table header.echo '<table align="center" cellspacing="0" cellpadding="5"><tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="' . $link1 . '">Last Name</a></b></td> <td align="left"><b><a href="' . $link2 . '">First Name</a></b></td> <td align="left"><b><a href="' . $link3 . '">Date Registered</a></b></td></tr>';// Fetch and print all the records.$bg = '#eeeeee'; // Set the background color.while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> ';}echo '</table>'; Follow it through and you will see that the delete and edit links are created from the query results. Link to comment Share on other sites More sharing options...
RawDog Posted September 20, 2009 Author Share Posted September 20, 2009 But is it possible to edit it from the Database? There are billions of results, and having to edit each table every time something is inserted is rather long. Link to comment Share on other sites More sharing options...
chibineku Posted September 21, 2009 Share Posted September 21, 2009 The 'while' statement will perform the subsequent piece of code for every entry that matches the query criteria, so there is no need to rewrite it. A simpler example:If I have 1billion entries in a table with first and last names, I can display all of them like this: //fetch the records$sql = "SELECT first_name, last_name FROM names";$res = mysqli_query($connect_info, $sql) or die(mysqli_error($connect_info));//cycle through themwhile($names = mysqli_fetch_array($res)) {//the following will happen for each row in the table$first_name = $names["first_name"];$last_name = $names["last_name"];echo "$first_name, $last_name";} If you wanted to turn that into a link, you just echo differently. If you had a page called personnel that fetched the names from the URL and used that for something, you might change the echo statement to:echo "<a href='personnel.php?first_name=$first_name&last_name=$last_name'>$first_name, $last_name</a>";The while loop is your friend. Link to comment Share on other sites More sharing options...
RawDog Posted September 21, 2009 Author Share Posted September 21, 2009 Thanks, it worked a whole lot Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.