Jump to content

Show results from MySQL without leaving page


rec0il

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by rec0il
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.