-
Posts
253 -
Joined
Everything posted by alexandre
-
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
i could use this pagination example here but the pdo extension cannot connect i think because the rest of my code is using mysqli extension . is it forced to be with pdo extension or there is a way to convert it to mysqli extension? -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
yeah thats what i was thinking.. but i decided to simply limit the number of records to 50 and add a search bar to search for any users records. i will also add a button to display directly the user its own record maybe along with calculating the number of records before his, so it would give the user his position in the ranking. there is just one problem left and it is that the number of winners is going up by one for every 10 participants registered, so if i limit the number of rows to 50, the number of winners can get higher and not display some records that others below this rank need to see to keep up.. from where i would need that load more button instead of this pagination. i think javascript it will be in this case, i dont think i will have a choice unless anyone have an alternative to ajax to make a load more button? -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
if this is all you need to put in place your pagination , it seems like a cleaner way to do it. also i would like to know if this is a problem to use mysqli and pdo for different queries. would it interfere or have unexpected behavior or it would simply not work? -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
there is something i am wondering .. how many rows like that would it take to make a page hard to load , if there is nothing else than that on the page, do i really need to make a pagination or an easier way would be to simply make a 'load more' button instead. i dont expect the users to oftenly go through tons of records but more that they look for their own records so from there i might want to find a way to make anchors to their names so i could use the search bar to get their record. -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
yes sorry for repeating the messages, it was kind of to show that i was answering you. and i think that i will have to go look at heredocs manual to understand your function but it looks interesting, i dont really understand how you get to not have to be using php tags everywhere in your html i will look more into this. -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
yes it seems like a nice way to go about it , do you have a sample of that function that you could show here or it is a privacy matter ? -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
thanks a lot for your instructions. and i get what you mean by the age isnt a fixed number , and this isnt going in my code , i just got angry not understanding that example and never finished to make the adjustement , i was more looking to get an example that would not be mixing php and html document like this one. usualy i have been using only the php side of the file to display and process. i dont like playing with the html document since it can get messy real quick and if i am making my script exit, the html code wont show up so i prefer doing all in php. just a little example of my data being pulled and displayed in my code: if ($donationclash == true) { $donationclashcompleted = false; $stmt = "SELECT total_participant, sum(total_participant) as total_participant FROM random_donation_clash"; $num_participant = mysqli_query($con, $stmt); if (mysqli_num_rows($num_participant) > 0) { while ($num_row = mysqli_fetch_assoc($num_participant)) { $participant_num = $num_row['total_participant']; }} $stmt = 'SELECT total_donated, sum(donation) AS total_donated FROM random_donation_clash'; $WINNERS_1 = mysqli_query($con, $stmt); if (mysqli_num_rows($WINNERS_1) > 0 ) { while ($WINNERS_ROW1 = mysqli_fetch_assoc($WINNERS_1)) { $total_participations_amount = $WINNERS_ROW1['total_donated']; }} $stmt = 'SELECT total_received, sum(total_received) AS total_received FROM random_donation_clash WHERE total_participant = 1'; $WINNERS_2 = mysqli_query($con, $stmt); if (mysqli_num_rows($WINNERS_2) > 0 ) { while ($WINNERS_ROW2 = mysqli_fetch_assoc($WINNERS_2)) { $total_received_amount = $WINNERS_ROW2['total_received']; }} echo " <div class='rankingtrue2'> <table class='rankingtable4'><tr> <th>Total participants</th><th>total donated by the participants</th><th>total received by the participants</th> </tr> <tr> <td class='remain1'>". $participant_num . "</td> <td class='remain2'>". $total_participations_amount . "</td> <td class='remain4'>". $total_received_amount . "</td> </tr></table></div><br><br><br>"; $stmt = 'SELECT DISTINCT users_name, donation, total_donated, total_received FROM random_donation_clash GROUP BY participation_id ORDER BY total_received DESC'; $result = mysqli_query($con, $stmt); if (mysqli_num_rows($result) > 0) { while ($result_row = mysqli_fetch_assoc($result)) { echo"<div class='rankingtrue2'> <div class='ranking_wrapper'> <table class='rankingtable3'> <tr> <td>username</td><td>total donated</td><td>total_received</td> </tr> <tr> <td class='remain1'>" . $result_row['users_name']. "</td> <td class='remain3'>" . $result_row['total_donated']. "</td> <td class='remain4'>" . $result_row['total_received']. "</td> </tr></table></div></div><br><br>"; } } i am not touching the html sidee at all.. is that possible or it is a bad practice to do so? -
looking for an easy way to implement pagination
alexandre replied to alexandre's topic in PHP Coding Help
yeah the example you just shown look much more easier to read but to do this i will have to get a better understanding of this code.. this isnt written by me and i think it looks terribly messy, even with the tutorial i wasnt able to make it work with my code but thank you for the precisions. -
i am thinking about making the two events running with a timer set for 5 days , then take two days to let people claim their rewards if they didnt when the timer goes on again the prizes will be sent to another participant(i dint figured out yet how to make the balances update automaticly without the user being on the actual page ). so long story short, this weekend with the timer off will be used to make updates and everything that needs to be done like creating a new round for the events. but this is more to give a mental break to the users since all of this looks like gambling games, i dont want people to go addicted ...
-
thats another thing i wanted to ask about performance is it faster to just pull the whole table or to reduce the amount of data processes? i could just aim for the data i want? i am not sure about that anymore but i am trying to see this with a high traffic scale just to ensure that it is prepared to every eventuality ..
-
i need something with php and html separated. when i look around google there is a lot of exmples but they all seems a bit messy.. if anyone knows an easy way to achieve this would be appreciated. the less messy i could find yet looks like that: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // If the user is not logged in redirect to the login page... // Get the total number of records from our table "students". $total_pages = $mysqli->query('SELECT * FROM random_donation_clash')->num_rows; // Check if the page number is specified and check if it's a number, if not return the default page number which is 1. $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; // Number of results to show on each page. $num_results_on_page = 25; if ($stmt = $mysqli->prepare('SELECT * FROM random_donation_clash ORDER BY name LIMIT ?,?')) { // Calculate the page to get the results we need from our table. $calc_page = ($page - 1) * $num_results_on_page; $stmt->bind_param('ii', $calc_page, $num_results_on_page); $stmt->execute(); // Get the results... $result = $stmt->get_result(); ?> <!DOCTYPE html> <html> <head> <title>PHP & MySQL Pagination by CodeShack</title> <meta charset="utf-8"> <style> html { font-family: Tahoma, Geneva, sans-serif; padding: 20px; background-color: #F8F9F9; } table { border-collapse: collapse; width: 500px; } td, th { padding: 10px; } th { background-color: #54585d; color: #ffffff; font-weight: bold; font-size: 13px; border: 1px solid #54585d; } td { color: #636363; border: 1px solid #dddfe1; } tr { background-color: #f9fafb; } tr:nth-child(odd) { background-color: #ffffff; } .pagination { list-style-type: none; padding: 10px 0; display: inline-flex; justify-content: space-between; box-sizing: border-box; } .pagination li { box-sizing: border-box; padding-right: 10px; } .pagination li a { box-sizing: border-box; background-color: #e2e6e6; padding: 8px; text-decoration: none; font-size: 12px; font-weight: bold; color: #616872; border-radius: 4px; } .pagination li a:hover { background-color: #d4dada; } .pagination .next a, .pagination .prev a { text-transform: uppercase; font-size: 12px; } .pagination .currentpage a { background-color: #518acb; color: #fff; } .pagination .currentpage a:hover { background-color: #518acb; } </style> </head> <body> <table> <tr> <th>Name</th> <th>Age</th> <th>Join Date</th> </tr> <?php while ($row = $result->fetch_assoc()): ?> <tr> <td><?php echo $row['name']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['joined']; ?></td> </tr> <?php endwhile; ?> </table> <?php if (ceil($total_pages / $num_results_on_page) > 0): ?> <ul class="pagination"> <?php if ($page > 1): ?> <li class="prev"><a href="pagination.php?page=<?php echo $page-1 ?>">Prev</a></li> <?php endif; ?> <?php if ($page > 3): ?> <li class="start"><a href="pagination.php?page=1">1</a></li> <li class="dots">...</li> <?php endif; ?> <?php if ($page-2 > 0): ?><li class="page"><a href="pagination.php?page=<?php echo $page-2 ?>"><?php echo $page-2 ?></a></li><?php endif; ?> <?php if ($page-1 > 0): ?><li class="page"><a href="pagination.php?page=<?php echo $page-1 ?>"><?php echo $page-1 ?></a></li><?php endif; ?> <li class="currentpage"><a href="pagination.php?page=<?php echo $page ?>"><?php echo $page ?></a></li> <?php if ($page+1 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="pagination.php?page=<?php echo $page+1 ?>"><?php echo $page+1 ?></a></li><?php endif; ?> <?php if ($page+2 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="pagination.php?page=<?php echo $page+2 ?>"><?php echo $page+2 ?></a></li><?php endif; ?> <?php if ($page < ceil($total_pages / $num_results_on_page)-2): ?> <li class="dots">...</li> <li class="end"><a href="pagination.php?page=<?php echo ceil($total_pages / $num_results_on_page) ?>"><?php echo ceil($total_pages / $num_results_on_page) ?></a></li> <?php endif; ?> <?php if ($page < ceil($total_pages / $num_results_on_page)): ?> <li class="next"><a href="pagination.php?page=<?php echo $page+1 ?>">Next</a></li> <?php endif; ?> </ul> <?php endif; ?> </body> </html> <?php $stmt->close(); } ?> and still i have no idea how i can implement this to my code without breakig everything .. so any advice is greatly welcome.
-
trying to make a div parent of all rows pulled from database
alexandre replied to alexandre's topic in PHP Coding Help
no , i wanted to make a div serve as body like kind of background for the whole table, so it doesnt look like a set of rows floating in the void -
trying to make a div parent of all rows pulled from database
alexandre replied to alexandre's topic in PHP Coding Help
i think i can fix that boxing issue by simply setting the css and adding divs for each section of the table making it form a boxing background style . -
trying to make a div parent of all rows pulled from database
alexandre replied to alexandre's topic in PHP Coding Help
i tried all the properties i know in css to try and make the div expand but there is nothing that makes it move, just as if it was again affecting a single row. and for the headings i want to keep them repetitive do you think it is affecting the wrapping div if i leave the headings inside the loop and just put the table around the loop with the needed divs? (the other divs are simply for adding some borders to the design). also i didnt know that i could use brackets to isolate a variable in a string, if i understood right , thank you for the advice it seems like a good practice . -
trying to make a div parent of all rows pulled from database
alexandre replied to alexandre's topic in PHP Coding Help
it worked , the div is under the ranking but i cant give it a height it will stay the size of the row, i tried to set the height and max height but it wont move, could it be needing a css property to expand it over a certain limit or am i missing something? i also want to keep the repetitive headings , i believe this way it is adding a bit of a separation and readability between the records and their meanings. -
trying to make a div parent of all rows pulled from database
alexandre replied to alexandre's topic in PHP Coding Help
yes i was indeed trying to open and close a div around the while loop but without any success . this seems more like what i need and will try it right away. i just havve one more question, do i echo just once or both when i open the div and when i close it ? -
i am not sure how i should proceed , as far as i went on this , it turned out that i am unable to make a div go underneath all the rows diplayed so it can serve as body for the ranking section. echo "<div class='rankingtrue2'> <div class='ranking_wrapper'> <table class='rankingtable'> <tr> <td>username</td><td>last donation</td><td>total donated</td><td>total_received</td> </tr> <tr> <td class='remain1'>" . $result_row['users_name']. "</td> <td class='remain2'>" . $result_row['donation']. "</td> <td class='remain3'>" . $result_row['total_donated']. "</td> <td class='remain4'>" . $result_row['total_received']. "</td> </tr> </table> </div> </div><br><br>"; } } this is an example of the grid formatting, now whatever i try the divs are acting only on a single row. if anyone have an idea how to do that i would appreciate.
-
cant get the authentication to work anymore..
alexandre replied to alexandre's topic in PHP Coding Help
it is fixed it was the database row for the password who has a too short lenght for the hashed password , sorry for the disturbance. -
cant get the authentication to work anymore..
alexandre replied to alexandre's topic in PHP Coding Help
i just verified and this is the password not matching. it is a hashed password stored in database after registration . -
since i had to redo my database everything is messed up.. now i cant get to login to my website anymore but my file didnt changed from the time it was working fine , except for the database credentials. if anyone could take a look at this very small code i would appreciate, no matter what i do it keeps returning that i entered a incorrect password or username, it wont succeed to make the match with the data pulled from the database. heres the authenticate.php: <?php session_start(); include 'connect_db2.php'; if (!isset($_POST['username'], $_POST['password'])) { // Could not get the data that should have been sent. exit('Please fill both the username and password fields!'); } // Prepare our SQL, preparing the SQL statement will prevent SQL injection. if ($stmt = $con->prepare('SELECT id, username, password FROM accounts WHERE username = ?')) { // Bind parameters (s = string, i = int, b = blob, etc), in our case the username is a string so we use "s" $stmt->bind_param('s', $_POST['username']); $stmt->execute(); // Store the result so we can check if the account exists in the database. $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($id, $username, $password); $stmt->fetch(); // Account exists, now we verify the password. // Note: remember to use password_hash in your registration file to store the hashed passwords. if (password_verify($_POST['password'], $password)) { // Verification success! User has logged-in! // Create sessions, so we know the user is logged in, they basically act like cookies but remember the data on the server. session_regenerate_id(); $_SESSION['loggedin'] = TRUE; $_SESSION['name'] = $username; $_SESSION['id'] = $id; header('location: home.php'); exit; } else { // Incorrect password echo 'Incorrect username and/or password!'; } } else { // Incorrect username echo 'Incorrect username and/or password!'; } $stmt->close(); } ?>