hyster Posted June 6, 2015 Share Posted June 6, 2015 I have a database with 2 columns, player - file PLAYER - FILE hyster - ussr-Object263.png hyster - ussr-Object268.png merc - germany-E-100.png merc - germany-JagdPz_E100.png what I want to do is create a horizontal table like this <table> <tr> <td>hyster</td><td> ussr-Object263.png ussr-Object268.png </td> </tr> <tr> <td>merc </td><td> germany-E-100.png germany-JagdPz_E100.png</td> </tr> </table> the file part is going to be an image, I can do it vertical by running 2 query's but I will be getting up to 30 names so to many for a vertical system. its the method im stuck on so any pointers in the way to do this please ?? all the code I have so far. <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "test"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM players GROUP BY player,file"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '' . $row["player"]. '<IMG src="test_files/' . $row["file"]. '"><br>'; } } else { echo "0 results"; } $conn->close(); ?> Link to comment Share on other sites More sharing options...
jamesmpollard Posted June 6, 2015 Share Posted June 6, 2015 What does this output? $sql = "SELECT * FROM players GROUP BY player"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_array()) { echo '<pre>' . print_r($row, true) . '</pre>'; } } else { echo "0 results"; } $conn->close(); Link to comment Share on other sites More sharing options...
hyster Posted June 6, 2015 Author Share Posted June 6, 2015 output is below Array ( [0] => fdg [player] => fdg [1] => ussr-Object263.png [file] => ussr-Object263.png ) Array ( [0] => hyster [player] => hyster [1] => china-Ch19_121.png [file] => china-Ch19_121.png ) Array ( [0] => merc [player] => merc [1] => germany-E-100.png [file] => germany-E-100.png ) Link to comment Share on other sites More sharing options...
jamesmpollard Posted June 6, 2015 Share Posted June 6, 2015 Slightly confused with that output as it doesn't show the "files" values you mentioned in your first post. Change the query to SELECT * FROM players SORT BY player and post back with that output. Link to comment Share on other sites More sharing options...
Barand Posted June 6, 2015 Share Posted June 6, 2015 @Hyster, Do not open two threads. You are wasting peoples' time answering two posts in parallel. Link to comment Share on other sites More sharing options...
Recommended Posts