There used to be a button, when clicked, the variable $ sec was transferred to another page. Now I have links and need to do the same. I assume that you can do this using the hidden field. Maybe there are other ways?

 include('set.php'); echo "<form method='post' action='obj.php'>"; $sql = mysql_query("select * from `obj` order by `id`"); for ($i = 1; $i <= mysql_num_rows($sql); $i++) { while ($s = mysql_fetch_array($sql)) { echo '<a href="obj.php">"<img src='.$s['img']. '>'.$s['id']. '</a>'; } $sec = $s['id']; } echo "</form>"; 
  • Question on javascript , but not on php . You can process click on the link, fill in the hidden field and make submit forms. Or you can use the jQuery library's post method. - Pyramidhead
  • @Pyramidhead and if I'm not friends with js, then what should I do? - Michael
  • For example, use GET instead of POST . And, accordingly, links like <a href="obj.php?sec=значение">содержимое ссылки</a> . - Pyramidhead
  • @Pyramidhead t, e so echo '<a href="obj.php?sec='.$s['id'ylar.'"> "<img src ='. $ S ['img']. '>' . $ s ['id']. '</a>'; - Michael
  • @Pyramidhead oh yes I almost forgot it is important for me that the variable is transferred - Michael

1 answer 1

Option 1:

Add an onclick handler for the links that will fill in the hidden field and submit form.

javascript:

 function doSubmit(val) { document.getElementById("sec").value = val; document.forms["form_id"].submit(); return false; } 

jquery:

 function doSubmit(val) { $("#sec").val(val); $("#form_id").submit(); return false; } 

Option 2:

Use jQuery post library method (suitable if you don’t need to go to another page)

 $.post( 'obj.php', { sec: val } ); 

Option 3:

Use GET instead of POST . That is, the links will be

 <a href="obj.php?sec=значение">содержимое ссылки</a> 

and obj.php itself obj.php be able to get a value from the global array: $_GET['sec'] .