deslyxia Posted June 9, 2012 Share Posted June 9, 2012 I have a query that I have run. I am able to output the dataset into a simple table it updates on my page beautifully. In the following code what I want to be able to do is along with the other columns i output have a 4th column that contains a button on each row and when a user clicks a button on the page it selects that particular row. This is the code I have creating my table atm. echo "<table alingn=\"center\" width=\"400px;\">"; echo "<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> </tr>"; while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td>".$row['ID']."</td> <td>".$row['FName']."</td> <td>".$row['LName']."</td> </tr>"; } echo "</table>"; Basically everytime it loops through I would want the row that shows the ID to be a button that would execute a php script but pass it that ID. I dont really want the ID shown on the page. Quote Link to comment https://forums.phpfreaks.com/topic/263908-formatting-output-from-a-query/ Share on other sites More sharing options...
cpd Posted June 9, 2012 Share Posted June 9, 2012 Use a hidden input tag. Quote Link to comment https://forums.phpfreaks.com/topic/263908-formatting-output-from-a-query/#findComment-1352442 Share on other sites More sharing options...
deslyxia Posted June 9, 2012 Author Share Posted June 9, 2012 Use a hidden input tag. I gave this a shot but I get an error while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td> <form id=".$row['ID']." name=".$row['ID']." method="post" action="p_select.php"> <input type="hidden" name="PID" value=".$row['ID']."> <input type="submit" value="Submit"> </form> </td> <td>".$row['FName']."</td> <td>".$row['LName']."</td> </tr>"; } the error I get is Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' Quote Link to comment https://forums.phpfreaks.com/topic/263908-formatting-output-from-a-query/#findComment-1352461 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2012 Share Posted June 9, 2012 The php string you are trying to echo starts and ends with double quotes - echo " ....... "; You are also trying to use double-quotes inside of that string around html attribute values. The first double-quote after the initial one closes the quoted string and anything after that is outside of the string and produces php syntax errors. The easiest fix would be to use single-quotes for everything that is inside of that echo " ....... "; statement. You can also put php array variables directly inside of a double-quoted string by surrounding them with {}. The following is the simplest php/html syntax that will do what you want - while ($row = mysql_fetch_assoc($result)){ echo "<tr> <td> <form method='post' action='p_select.php'> <input type='hidden' name='PID' value='{$row['ID']}'> <input type='submit' value='Submit'> </form> </td> <td>{$row['FName']}</td> <td>{$row['LName']}</td> </tr>"; } BTW - there's no need to give html elements id and name attributes unless you are actually going to reference those attributes. I did not include the id and name you had in your <form> tag. You might actually want to add a name attribute to the submit button so that you can test in the p_select.php code if a form was actually submitted. Quote Link to comment https://forums.phpfreaks.com/topic/263908-formatting-output-from-a-query/#findComment-1352541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.