Jump to content

HTML in While Loop


RAFC_1990

Recommended Posts

Hey im quite new to php but im hoping you can help me sort the following code out please.

 

while ($row = mysql_fetch_array($sql_result)) 
{
$id1 = $row["id"];
$username1 = $row["username"];
$password1 = $row["password"];
$organisation1 = $row["organisation"];
$delete = echo '<a href="delete.php<a href="delete.php?id=<?php echo $row->id; ?>">Delete</a>">Delete</a>';

print "<tr><td>$organisation1</td><td></td><td>$username1</td><td>$delete</td></tr>";

 

Im trying to get a delete button at the end of every row, but i cant seem to get the right syntax for it to create the html button and loop it on every row :(

 

Please could someone help, Thanks.

Link to comment
Share on other sites

You just echo out the variable, no need to add the <?php ?> tags. You only use those if perhaps you've had a closing tag before and your writing static HTML.

 

while ($row = mysql_fetch_array($sql_result)) 
{
$id1 = $row["id"];
$username1 = $row["username"];
$password1 = $row["password"];
$organisation1 = $row["organisation"];
$delete = echo '<a href="delete.php<a href="delete.php?id=' . $row->id . '>Delete</a>">Delete</a>';

print "<tr><td>$organisation1</td><td></td><td>$username1</td><td>$delete</td></tr>";

Link to comment
Share on other sites

You just echo out the variable, no need to add the <?php ?> tags. You only use those if perhaps you've had a closing tag before and your writing static HTML.

 

while ($row = mysql_fetch_array($sql_result)) 
{
$id1 = $row["id"];
$username1 = $row["username"];
$password1 = $row["password"];
$organisation1 = $row["organisation"];
$delete = echo '<a href="delete.php<a href="delete.php?id=' . $row->id . '>Delete</a>">Delete</a>';

print "<tr><td>$organisation1</td><td></td><td>$username1</td><td>$delete</td></tr>";

 

 

Note that the above code still has an extra echo that isn't needed. Also, I would imagine that $row->id is an invalid variable. Based on the code, kenrbnsn's solution should work though.

Link to comment
Share on other sites

Thanks guys, worked a treat.

 

But now the problem is that the delete.php code doesnt seem to work for me :(

 

if (isset ($_GET['id']) && !empty ($_GET['id'])) {
   mysql_query ('delete from $tbl_name where id='.intval ($_GET['id']).' limit 1');
   header ('Location:adminadd.php');
} else {
   echo ("Error deleting account from database!");
}
exit;

Link to comment
Share on other sites

I did do above, its

 

if (isset ($_GET['id']) && !empty ($_GET['id'])) {
   mysql_query ('delete from $tbl_name where id='.intval ($_GET['id']).' limit 1');
   header ('Location:adminadd.php');
} else {
   echo ("Error deleting account from database!");
}
exit;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.