I've been doing searches on how to make php output sections but couldn't find anything.
Let me explain my project and what kind of help I'm looking for exactly. I'm working on a player database that saves player results from tournament matches for a specific video game. The database will then be used by tournament commentators for pre-game analysis for the viewers. Here's the part I'm stumped on, I want the tables to be displayed in a way that's super easy and quick to find specific results.
My current setup is PHP displays data from the mySQL server in a table, which is functional but super hard to sift through, especially later on when there will be three to five more variables.
Example:
Event : -EVENT NAME-
Date : 5/19/2013
Map Names : -Map 1- -Map 2- -Map 3-
Results : -Winner- -Loser-
Event : -EVENT NAME-
Date : 5/19/2013
Map Names : -Map 1- -Map 2- -Map 3-
Results : -Winner- -Loser-
I would like to know how to make it where the information is displayed in tournament name sections, such as:
Event: -Tournament Name 1-
Event: -Tournament Name 2-
Then when you click on the specific tournament you want, it'll show you all of the results for that tournament. Could anyone point me in the right direction as to where to learn how to make this happen?
Seems like you want to display events, that expand event-related information when clicked. The jQuery UI accordion widget might be an appropriate way to handle such a data display. Have a look here:
http://jqueryui.com/accordion/
The section names shown in the demo are your events, and the text shown when they're clicked is your event text
make Event: -Tournament Name 1- a link like Tournament Name 1
then in tour.php, you check the $_GET['name'] and use that in your db query to look up the results
I'm not totally clear on how you want to achieve this but I can think of a couple options. You can use Javascript to expand a section below the Tournament Name without ever requiring the browser to do a postback, or you can simply have the tournament name linked to another page.
Option 1 (DHTML):
<script>
function showSection(tournamentID) {
document.getElementById('section' + tournamentID).style.display = 'block';
}
</script>
<?PHP
...
while ($row = ... ) {
?>
<a href="#" onclick="showSection(<?PHP echo $row['tournamentID']; ?>);return false;">
<?PHP echo $row['tournamentName'];?>
</a>
<div style="display:none" id="section<?PHP echo $row['tournamentID']; ?>">
Event: ... <br />
Date: ... <br />
Map Names: ... <br />
</div>
<?PHP
}
?>
You can use JQuery to do some cool effects, like slide down or fade in. The example above is just straight javascript and will simply show the section - but won't use any transition effects.
Option 2 (Link):
<?PHP echo $row['tournamentName'];?>
On tournamentDetails.php you would process the $_GET['id'] variable and query the database for the remaining information about that tournament and display it on the page.
To me it sounds like you want to output the data with a javascript/css accordion collapse. You can search for accordion collapse code snippets using javascript libraries like JQuery. An example of an accordion can be found on the Twitter Bootstrap site at: http://twitter.github.io/bootstrap/javascript.html#collapse
This should help alleviate the long table listing you have now, and only display the Tournament names initially unless a user wants to view more info on it, selecting the tournament to drop down more information about that tourny only.
Related
I'm really new to jQuery so I need your professional help in solving some of the issues I have.
I want to create an application for checking out events.
User chooses type of events (choose_type.php) -> user chooses city (choose_city.php) -> user chooses event(choose_event.php) -> user sees event details (event.php)
I have a user interface which is done with jQuery Mobile. I have created it based on Restaurant Picker application here
All of the choices in these html files are displayed as <li> elements with href links.
PHP code for my index page is given below.
if (!isset($_POST['SUBMIT'])){ //ERROR: Undefined index
$typequery= "SELECT * FROM eventtype ";
$typeresult = mysql_query($typequery);
while($row=mysql_fetch_array($typeresult))
{ $typeid=$row['TypeID'];
$typeimg=$row['Image'];
$typename=$row['TypeName'];
?>
<li> <img src="<?php echo $typeimg?>"/><h3><?php echo $typename ?></h3></li>
<?php } } ELSE {} ?>
This reads all types and their image paths from the DB, however, when I click on a link to go to choose_city.php, I am returned a blank screen which only says UNDEFINED.
How should I continue working on this? I need to keep passing parameters like typeid to next query, and typeid,cityid to the next one in order to get to event details.
my database is structured like City --< Events , EventType ---< Events, Event (contains only PK and FK ) ---- Description.
Any guidance would be really helpful. Thank you in advance,
Ok, I know this can be done, for I've seen it before. Yet I have no idea how to make it work I have searched everywhere for an answer.
What I need is for my form to randomly change positions when the page loads from 3 different spots on the page. So for example....
[Here] [Here] [Here]
Could all be possible spots the form could load in but only in 1 spot for each time it loads. I don't know what information you need to help me. I will just give my form for now.
<form name="inputt" action="" method="post">
<div align="center">
<input type="submit" class="catch" value="Catch Pokemon" name="catch">
</div>
</form>
If you need more just ask.
Just my inital thought, but you could write CSS for the 3 different position class, and call them things like 'position1', 'position2','position3'. Then on page load in javascript (or in PHP) if you want, generate a random number between 1 and 3, add the class "position"+randomNumber to the element, and then it will be in one of those places. This is similar to a technique I used for random background images.
Update
Also, if you want to use more descriptive class names for the locations, you could keep a mapping of a number to a class name (or use something like position in an array), to relate a a random number to the class to apply.
Code
CSS:
<style>
.position1 {
// Whatever style you want for position 1
}
.position2 {
// Whatever style you want for position 2
}
.position3 {
// Whatever style you want for position 3
}
</style>
JS:
$(document).ready( function () {
var randomIndex = Math.floor(Math.random()*3)+1; //3 is the number of options you have; +1 makes the range 1 - 3 instead of 0 - 2
$('#my-form').addClass('position'+randomIndex); //Adds the new class the element with id = 'my-form'
}
If you mean by "load" a page refresh than you will have to persist the previous location of the form either in cookie or some other mechanism. Based on the last location of the form you can decide which location should be next.
If the form is being reloaded based on ajax calls, then I would advise using a var to store the previous location of the form and make the next location not be the same as previous by checking the value of the var. If each time form loads position should be unique than use an array to store previously used display locations.
HTH.
I'm looking to build a site which will have multiple options, for example;
NOTE** These are images not any forms or input type
Pick from one of the 5 images
Pick from one of the 3 images
Pick from one of the 2 images
Pick from one of the 6 images
and so on...
What I need to do is record which option (image) the user clicked on and then output a message.
For example if you picked a b c d, msg = hello
I'm not sure how to record this data, thanks!
You could link each image to a seperate page or reload the current page with a query string appended for example adding the following to your images as links
<img src="set1-image3.png" />
You could then save this information using PHP by processing only if the GET string contains the parameters image and set and could then split out which set/image has been clicked this way.
You could also use this to choose which image set to show on the screen (show set 2 if set=1 is in the query string etc.)
Using $_GET['set'] and $_GET['image'] you would have access to this information very easily in PHP.
For example you could do:
if( isset($_GET['image']) && isset($_GET['set']) ) {
echo "You clicked image" . $_GET['image'] . " from set " . $_GET['set'];
}
That would be the only pure PHP answer. The other way to do this is with Ajax or JavaScript but I'm guessing by your part about it being done in PHP this may not be what you want.
You could add a parameter to the link you click.
For example <img>
In page2.php you could read that variable using:
$_REQUEST["clickedImage"]
For example:
<p>The clicked image is: <?php echo $_REQUEST["clickedImage"] ?>
H_i
I have a question about possible simple and good working solution width jquery. How to append ajax table from sql like
https://www.inforegister.ee/BACEXSQ-ARGOS-KRACHT
with 'scrolling down'-event (width after ajax-reloaded table) width a find form?
First i have a mysql table creat table tbl1(id int auto_increment,name varchar(200)); having many hundred records. From it appends automatically e.g 10 records.
Html-code would looks like:
<form>
<input type="text" id="find" >
<input type="buttom" id="findb" >
</form>
<table></table>
Thank you
If you look at the source, you'll see that they're making use of the scroll event:
jQuery(window).scroll(function(){
if(jQuery("#nextCompaniesCount").val() > 0) {
if (jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()){
loadNextCompanies();
}
}
});
Look at the source and you'll also see the loadNextCompanies() function, which performs an AJAX request and then adds any HTML to the body.
If you're wanting to add new items to the end of a table, you can use something like:
$('#id_of_table > tbody > tr:last').after(newRow);
newRow would contain the tr html that you want to add.
Hey here is the plugin you are looking for.
http://masonry.desandro.com/demos/infinite-scroll.html.
Take a look at above example.
Wayne Whitty's answer is the way to go, but I'd like to add to it:
If you scroll fast on the page that you linked to, you will see that the loading image appears multiple times. This is happening because the user has reached the bottom of the page again, before the new content has been loaded.
You can make this more efficient by checking to see if you are already waiting on a response from the server before calling loadNextCompanies() (or your equivalent) again.
Update:
You asked for a plugin- although I have never used any plugins to achieve this so I can't make any recommendations, I can tell you that this is called Lazy Loading and a quick search turns up this plugin: https://code.google.com/p/jquerylazyscrollloading/
I'm trying to renew my company intranet using jquery, ajax and php. General aspect of the site is a drop down menu at the top loaded into a div and a content div where i load pages clicked on drop-down menu. The problem come out when inside content i load a page which inside have a tab menu, what i do when a tab is clicked is to load a html structure page with form and fill it by POST call.
The question is it correct load data when requested instead of pre-load it and show them when called as seen in a lot of example in the web? Working in my way I get a lot of data cached so when i click for confirm some data I send request several data instead of one..
what is the best way to work with this languages?
I find my goal solution suggested by Nathan I pre-load all data in one time for all forms, here is the code:
$("#div_0").show();
$("#scheda_eti > div").css({"background-color": "white", "color": "black","cursor":"hand"}); //tabs div
$("#"+schemi[0]).css({"background-color": "red", "color": "white","cursor":"default"});
for (var x=0; x<schemi.length; x++)
{
$("#div_"+x).load("./schemi/sch_"+schemi[x]+".php", {azione: "vedi"});
}
$.post("./php/global.php",
{azione:"vedi", contratto: $("#suggest_hidden").val() },
function(xml)
{
if ($("status", xml).text()=="1")
{
$(xml).find("form").each(function()
{
var id_form=$(this).attr("id");
scorriDati(xml, "form_"+id_form);
});
}
else
{
$("#scheda_ris").html("<img src='./img/validno.png' alt='errore'> <span style='color:red'><p>Attenzione!<br>codice non trovato!</p></span>");
}
$(xml).find("errore").each(function()
{
$("#scheda_ris").append("<img src='./img/validno.png' alt='errore'> <span style='color:red'>"+$(this).text()+"<br></span>\n");
});
},'xml'
);
To see some code you ca watch to my previous posts linked here:
question1
question2
thanks in advance
ciao
h
I think jQuery UI Tabs is what you're looking for. You need to include jQuery UI in your code, certainly after jQuery.
Order:
<link rel='stylesheet' href='http://jquery-ui.googlecode.com/svn/tags/latest/themes/ui-lightness/jquery-ui.css' />
<script src='http://code.jquery.com/jquery-latest.min.js'></script>
<script src='http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/jquery-ui.min.js'></script>
If you don't like the UI lightness theme, you can choose any from the Theme Gallery. For example, if you want the UI darkness theme, just replace ui-lightness with the theme's name in lowercase, and with hyphens instead of spaces.
I guess the answer to "is it correct load data when requested instead of pre-load it and show them when called?" is "which will the user prefer when switching to a different tab?"
no delay (all content loaded during initial page load)
short delay (ajax lookup of the new tab's content)
a full page load (a full round trip, no ajax needed)
In many cases you can get good results with the first or the third approach. Don't overuse Ajax.
Here's a blog rant about overuse/correct use of Ajax... I haven't honestly read it and don't necessarily endorse the whole thing, but it might help.