All welcome. There is a form of adding "uslugi" and in it the field "idOpis" and now when I add to the table "uslugi" a number is selected from the field "idOpis", and how do I get to choose not a number, but a letter designation corresponding to this Id in another the table with which it is associated? Those. in this case, the data was taken from the note field of the "opisanie" table

enter image description here

form code now:

$connection=mysql_connect("localhost","reklama","reklama") ; $db=mysql_select_db(reklama); mysql_set_charset("utf8"); if (!$connection || !$db) { exit(mysql_error());} include_once("db1.php"); function names() { $query="SELECT `idOpis` FROM `uslugi`ORDER BY `uslugi`.`idOpis` ASC"; $query_res=mysql_query($query); $names = array(); while($row = mysql_fetch_assoc($query_res)) { $names[] = $row; } return $names; } $names = names(); echo "<select name='idOpis'>"; foreach($names as $item) { echo "<option value=' ".$item['idOpis']." '>".$item['idOpis']." </option>"; } echo "</select><br/><br/>"; ?> Цена:<br/> <input type="text" name="cena" /><br/><br/> <input type="submit" name="add" value="Добавить" /> </form> <?php include_once("db1.php"); if (isset($_POST['add'])) { $naimenUslugi=strip_tags(trim($_POST['naimenUslugi'])) ; $idOpis = $_POST['idOpis']; $cena = $_POST['cena']; $result = mysql_query(" INSERT INTO uslugi (naimenUslugi,idOpis,cena) VALUES ('{$naimenUslugi}', '{$idOpis}', '{$cena}') "); if($result==TRUE){ echo 'Новость успешно добавлена'; } else echo mysqli_connect_error() . 'Ошибка БД. Обратитесь к администратору' ; mysql_close(); } ?> </body> </html> 
  • You decide where and what does not work for you. “When added to a table” and “a number is selected” are two phrases that are difficult to imagine in one context. Try to more precisely describe what exactly you can not. It is desirable to indicate directly in the code in which lines the problem. - rjhdby
  • It’s not at all clear why you choose description identifiers from services? - fens
  • One more thing, if you have one to one connection between opisanie and uslugi, then this indicates that this is the same table. - fens

2 answers 2

 SELECT `uslugi`.`idOpis`, `opisanie`.`поле описания` FROM `uslugi` JOIN `opisanie` ON `opisanie`.`idOpis` = `uslugi`.`idOpis` ORDER BY `uslugi`.`idOpis` ASC 
  • Please try to leave a little more detailed answers. - aleksandr barakin

1. How to do this inside a while that is, at each output, make a request to another table with the received id.

2. Select method inside select'a: http://www.mysql.ru/docs/man/ANSI_diff_Sub-selects.html

Example:

 SELECT * FROM xxx WHERE xxx = (SELECT xxx FROM xxx WHERE xxx = xxx)