[Solved] Use PHP to render multiple images to the browser [closed]

You use a while loop in to fetch the results. $coverpic=””; $sql = “SELECT filename FROM photos WHERE user=”$u””; $query = mysqli_query($db_conx, $sql); if(mysqli_num_rows($query) > 0){ while($row = mysqli_fetch_row($query)) { $filename = $row[0]; $coverpic .= ‘<img src=”https://stackoverflow.com/questions/16442747/user/”.$u.”https://stackoverflow.com/”.$filename.'” alt=”pic”>’; //notice the .= to append to the string instead of overwrite } } But if you want … Read more

[Solved] joins in MySQL for leave management in PHP and MySQL [closed]

Let’s take it step-by-step… First, the entities you’re selecting are in the leave_request table. So let’s start there: SELECT leave_request.* FROM leave_request Now, you need to know the data for the applied_by column in the desired results. So you join the staff table: SELECT applied_staff.name AS applied_by FROM leave_request INNER JOIN staff AS applied_staff ON … Read more

[Solved] How to properly optimise mysql select statement

Unless there’s more to the picture, why not just query everything, ordered by section, to have the A-Z: SELECT * FROM Main_Section ORDER BY section … and then process the results with one loop, which could look something like this: $sections = $connect->query(“SELECT * FROM Main_Section ORDER BY section”); while ($row = $sections->fetch_array()) { echo … Read more

[Solved] Php, mysql coding error

You are getting that error simple because you are using a newer version of php that does not support mysql_* functions, those functions have been depreciated and completely removed from the latest version of php. You should use mysqli prepared functions or pdo prepared statements. using mysqli to connect to database you will use it … Read more

[Solved] How to get the sum in a joined table when using group by – getting wrong results

I understand that you want, for each day: the sum of order_items.energy_used for all orders created that day the created_at and order_sum that correspond to the latest order created on that day Your sample data is not very representative of that – it has only one order per day. Also it is unclear why created_at … Read more

[Solved] Why is it saying no database selected?

Your final code should be identical to: <?php $con = mysqli_connect(“localhost”, “root”, “”, “radian”); if (!$con) { exit(“Couldn’t connect: ” . mysqli_connect_error()); } mysqli_set_charset($con, “utf8”); $insert_data = “UPDATE enquiries SET ResponseDate=”” . $current_date . “”, Response=”” . $txtResponse . “”,Enquiry_No = ‘” . $_SESSION[‘ses_staff’] . “‘ WHERE Enquiry_No = ‘” . $txtStudentId . “‘”; $execute … Read more

[Solved] mySQL Largest number by group

In general ORDER BY in a sub-query makes no sense. (It only does when combined with FETCH FIRST/LIMIT/TOP etc.) The solution is to use a correlated sub-query to find the heaviest fish for the “main query”‘s current row’s username, location, species combination. If it’s a tie, both rows will be returned. SELECT * FROM entries … Read more

[Solved] most efficient way to write this sql query?

This is a little more difficult because MySQL doesn’t have Row_Number() so you’ll need to simulate it. One way is use a self join and a count. You could also use the @rownumber technique described here In my example I used animal_id to find the most recent but you may want to change the JOIN … Read more