How to make this code make all samples from the database, and not just the last added record?

<?php require 'connect.php'; mysql_set_charset( 'utf8' ); $sql_select = "SELECT * FROM users"; $result = mysql_query($sql_select); $row = mysql_fetch_array($result); do { printf ("<script type=\"text/javascript\"> $(function(){ $('#mydiv').text('Номер телефона: ' + ($('#cp_id_626').text().indexOf('" .$row['name'] . "') != -1 ? '".$row['email'] ."' : '+77777777')); }); </script>" ); } while($row = mysql_fetch_array($result)); ?> 
  • The most strange thing is that if you insert several identical scripts, then none of them work - Vitaly Nosikov
  • And if you insert without request directly into html everything works - Vitaly Nosikov
  • Note that you are using unsupported mysql_ * functions declared as deprecated several years ago. Use mysqli or PDO. - Nikolaj Sarry

1 answer 1

What about

 while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<script type=\"text/javascript\"> $(function(){ $('#mydiv').text('Номер телефона: ' + ($('#cp_id_626').text().indexOf('" .$row['name'] . "') != -1 ? '".$row['email'] ."' : '+77777777')); }); </script>"; } 

?