简体   繁体   中英

Select two tables from Mysql server

I'm trying to make an evaluation stars system and I have two tables: user and evaluation. Now I would like to show my vote for every user? Every answer is welcome. Thanks in advance!

Are you looking for what SQL query you want to use to show the evaluation rate for every user? If yes, this will help you:

SELECT user.name AS username, evaluation.value AS evaluation_value
FROM user  
INNER JOIN evaluation ON user.id = evaluation.user_eval

I think that user_val in the evaluation table is the user id. If yes you can use the above query. If not modify the query to target the column where you save the user ID.

make a file "list_all_values.php" this is code -

<?php
$sql="SELECT * FROM evaluation";
$result = $conn->query($sql);
// $conn is your connection to database
echo '
<html>
<table>
<tr>
<th>user_eval</th>
<th>value</th>
</tr>';
while($row = $result->fetch_assoc()){
echo '<tr><td>'.$row['user_eval'].'</td><td>'.$row['value'].'</td></tr>';
}
echo '</table>
</html>';
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM