rec0il Posted June 17, 2014 Share Posted June 17, 2014 Hi again PhpFreaks, yet again I got a problem regarding coding. I want to build somewhat a score board, which shows the latest results of matches. I've build it so that it shows all the matches on my MySQL. $query = $pdo->prepare("SELECT * FROM results ORDER BY id DESC"); But i would like an option for my readers to choose a specific team, so that only matches of this specific team is shown. How would i be able to implement this feature without having to create a new page and stay on the same? Code of HTML <div class="results"> <table style="width:800px"> <?php foreach ($results as $result) { ?> <tr> <td style="background-color:grey;"><?php echo $result['date'] ?></td> <td ><?php echo $result['team1'] ?></td> <td style="background-color:green;"><?php echo $result['result1'] ?></td> <td><?php echo $result['team2'] ?></td> <td style="background-color:red;"><?php echo $result['result2'] ?></td> <td style="opacity: 0.5;"><?php echo $result['league'] ?></td> </tr> <?php } ?> </table> </div> Examples is more appreciated that explanations, I'm not that familiar with the english terms so makes it alittle harder for me to understand. Thanks alot in advance Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 17, 2014 Share Posted June 17, 2014 If you want to run your query and show the results on the same page that your input came from you should look into using an ajax process to trigger a php script and then capture the results and use js to place them on your page with the complete refresh. Sorry - don't have an example to show you here. Quote Link to comment Share on other sites More sharing options...
rec0il Posted June 17, 2014 Author Share Posted June 17, 2014 (edited) If you want to run your query and show the results on the same page that your input came from you should look into using an ajax process to trigger a php script and then capture the results and use js to place them on your page with the complete refresh. Sorry - don't have an example to show you here. I'm not very familiar with jQuery, is it really necessary to use it? Can't it be done in php/html only? and Is there anything specific you could recommend to look into, other than Ajax? Edited June 17, 2014 by rec0il Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 17, 2014 Share Posted June 17, 2014 Who mentioned jquery? not me. If you want to update the page in front of the user without refreshing/re-displaying it, you have to use ajax. If you want to change your requirements so that you can take the input, run a php script and then display a page with new data then you don't need ajax or js or even jquery Quote Link to comment Share on other sites More sharing options...
jbonnett Posted June 18, 2014 Share Posted June 18, 2014 (edited) You could always use PHP's header function... header( "refresh:5;url=wherever.php" ); Edited June 18, 2014 by jbonnett Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 18, 2014 Share Posted June 18, 2014 (edited) But i would like an option for my readers to choose a specific team, so that only matches of this specific team is shown. you would implement some type of a selection menu, either a search text box for part/all of a team name and produce link(s) for the matching team(s) or just make a <select><option></option>....</select> menu with all the teams listed. if you then select one of the teams, via a link or the select menu, you would request the same page you are on and pass the team id in the url. if the $_GET parameter containing the team id is set, you would use that id in a WHERE clause in your query to match only the rows you want. if the $_GET parameter is not set, you would not add that WHERE clause to the query and it would then match all the rows. Edited June 18, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.