PVM Posted January 16, 2016 Share Posted January 16, 2016 First i would like to thank you for accepting me in this large community, I have learned a lot from this website, but now I have a problem that I am trying to solve for like a couple days so I think I really need your help guys My problem is displaying results from SQL database to one XHTML file, here's the code, strings in code are mostly writent on my native language, if that is a problem i will easly translate it ofcourse... This is my XHTML part: <div id="content"> <form action="ispis.php" method="POST" style="margin-top: 2%;float: left;margin:2%;padding:2%;height: 100%;border: solid thin"> <label>Choose products group:</label><br/><br/> <select name="pd"> <option value="komp">Racunari</option> <!-- Computers --> <option value="laps">Laptopovi</option> <!-- Laptops --> <option value="moni">Monitori</option> <!-- Monitors --> </optgroup> </select> <input type="button" name="sd" value="Go"/> </form> </div> This is the PHP part writen in "ispis.php" <?php include("admin/db_config.php"); $pd=$_POST["pd"]; if ($pd=="komp") { $sql = "SELECT * FROM racunari"; $result = $connection->query($sql); if ($result->num_rows > 0) { // output data of each row $output = ""; while ($row = mysqli_fetch_array($result)) { $output .= "<b>Model:</b>" . $row['Model'] . "<br />"; $output .= "<b>Opis:</b>" . $row['Opis'] . "<br />"; $output .= "<b>Slika:</b>" . $row['Slika'] . "<br />"; $output .= "<b>Cena:</b>" . $row['Cena'] . "<br />"; } echo $output; } else { echo "Nema rezultata"; } } elseif ($pd=="laps") { $sql = "SELECT * FROM laptopovi"; $result = $connection->query($sql); if ($result->num_rows > 0) { // output data of each row $output = ""; while ($row = mysqli_fetch_array($result)) { $output .= "<b>Model:</b>" . $row['Model'] . "<br />"; $output .= "<b>Opis:</b>" . $row['Opis'] . "<br />"; $output .= "<b>Slika:</b>" . $row['Slika'] . "<br />"; $output .= "<b>Cena:</b>" . $row['Cena'] . "<br />"; } echo $output; } else { echo "Nema rezultata"; } } else { $sql = "SELECT * FROM monitori"; $result = $connection->query($sql); if ($result->num_rows > 0) { // output data of each row $output = ""; while ($row = mysqli_fetch_array($result)) { $output .= "<b>Model:</b>" . $row['Model'] . "<br />"; $output .= "<b>Opis:</b>" . $row['Opis'] . "<br />"; $output .= "<b>Slika:</b>" . $row['Slika'] . "<br />"; $output .= "<b>Cena:</b>" . $row['Cena'] . "<br />"; } echo $output; } else { echo "Nema rezultata"; } } $connection->close(); ?> This is my XHTML file and i would like to see results from SQL databases on this page: http://www.upslike.net/imgdb/rezsss-d17d85.png Link to comment Share on other sites More sharing options...
COBOLdinosaur Posted January 16, 2016 Share Posted January 16, 2016 The action on the form need to be the url of the target page which is where the script should be inside the container element that you want to hold the data. Link to comment Share on other sites More sharing options...
PVM Posted January 16, 2016 Author Share Posted January 16, 2016 Ok man thanks, i have managed to solve this problem now i am dealing with some other stuff... I need to output image from database, this is what happends when i try that, i only get path to the image: http://i.imgur.com/A9Ew2Sf.png This is my output code: if ($result->num_rows > 0) { // output data of each row $output = ""; while ($row = mysqli_fetch_array($result)) { $output .= '<table style="width: 45%;margin: 2%;"border="1">'; $output.= '<tr>'; $output.= '<td style="color: crimson">'; $output .= "<b>Model:</b>" . $row['Model'] . "<br />"; $output.= '</td>'; $output.= '</tr>'; $output.= '<tr>'; $output.= '<td style="max-height: 120px;height: 100px;text-align: justify">'; $output .= "<b>Opis: </b>" . $row['Opis'] . "<br />"; $output.= '</td>'; $output.= '</tr>'; $output.= '<tr>'; $output.= '<td style="height: 120px;max-height: 120px">'; $output .= "<b>Picture:</b>" . $row['Slika'] . "<br />"; //Picture is here! $output.= '</td>'; $output.= '</tr>'; $output.= '<tr>'; $output.= '<td style="color: green">'; $output .= "<b>Cena:</b>" . $row['Cena'] . "<br />"; $output.= '</td>'; $output.= '</tr>'; $output .= '</table>'; } echo $output; Link to comment Share on other sites More sharing options...
Ingolme Posted January 16, 2016 Share Posted January 16, 2016 Try putting the path as the src attribute of an <img> element. Link to comment Share on other sites More sharing options...
PVM Posted January 16, 2016 Author Share Posted January 16, 2016 I am trying that for like an 40 mins... can someone please write me that part of code where $row['Slika'] is my src of <img> tag ? Link to comment Share on other sites More sharing options...
john_jack Posted January 17, 2016 Share Posted January 17, 2016 replace this : $output .= "<b>Picture:</b>" . $row['Slika'] . "<br />"; with this : $output .= "<b>Picture:</b><img src='" . $row['Slika'] . "'><br />"; 1 Link to comment Share on other sites More sharing options...
PVM Posted January 17, 2016 Author Share Posted January 17, 2016 replace this : $output .= "<b>Picture:</b>" . $row['Slika'] . "<br />"; with this : $output .= "<b>Picture:</b><img src='" . $row['Slika'] . "'><br />"; Thank you man you saved me, best wishes !!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now