This is my query. I want to display the submit button with name depending on its ID.
<?php
$sql = mysql_query("SELECT * FROM tb_topic");
while($row=mysql_fetch_assoc($sql)){
$t_id = $row['t_id'];
$t_title = $row['t_title'];
$t_desc = $row['t_desc'];
echo "<a class='list-group-item'><input type='submit' name='$t_id' class='submitLink' value='$t_title'></a>";
}
?>
Now i want to display the data using the ID from the link.
<?php
if($_POST['$t_id']){
echo "$";
$sql = mysql_query("SELECT * FROM tb_topic WHERE t_id='$t_id'");
while($row=mysql_fetch_assoc($sql)){
$t_title = $row['t_title'];
$t_desc = $row['t_desc'];
echo $t_title;
echo $t_desc;
}
?>
is this possible?
i can make it display if i use:
<?php
if($_POST['1']){
echo "1";}
if($_POST['2']){
echo "2";`*enter code here*`
}
?>
Yes use variable variables
<?php
foreach($_POST as $key=>$value){
${$key} = $value;
// or something like
if(${$key} == "1"){
// do something
}
}