I have created a page with Mysql rows displayed as a dynamicly created image grid.
The grid display i have full control over, but i need to take the (Mysql) Row ID from each image displayed and use it in a pop up of some sort.
I don't like having a full page for each Mysql row.
It could be passing it on to a new smaller info page(dynamic) or it could be a popup with the info(dynamic).
I would prefer the popup, since i would guess this is easier on the eyes.
So what i need a suggestion on a popup function, which will load/set the row ID on click.
I have seen Jquery solutions for making popups, but i need to pass in the variables allready set by each displayed image. and this is where i fail.
Thanks in advance.
/Niels
**
This is one of the things i have tried, but i can't really figure out the way to pass it in the right way:
echo "<p>Show"
When you render the page in PHP, you could use a data attribute <div data-mydata='foo' /> to store the ID you need. Then, with jQuery, use the data() function to access the data and render whatever popup you need.
HTML 5 data attribute: http://ejohn.org/blog/html-5-data-attributes
jQuery Reference: http://api.jquery.com/data
Related
Ive been researching online for a couple days and I cant seem to find out the answer to my question. I would like to append a div or insert a pre populated form from my database depending on a drop down menu (selecting from a row in my DB). Once you press a button it will add the form field to a div or area above. Any suggestions? How should I tackle this? Im extremely new to Jquery and Ajax but know PHP fairly well.
One way is to populate the fields when the page is being loaded. (pass the values on to your html page with "value=<$php echo $someData %>"
if you want to load the data without refreshing the page each time, I'd suggest you make a different page that will load the data from the database through POST-requests and retrieve the data as JSON, so you can parse it with Javascript and update the fields accordingly.
updating the fields can be done like so:
json = YourJSONData;
$('.some-class').val(json['someData']); // if populating a form field
$('.some-other-class').html(json['someOtherData'); // if populating a div or other DOM element.
etc...
What I have is a list of client names which when I click them I want some mysql data to load in the div next to their names and so on,
I know already I can do this with an AJAX request by binding an onlclick function to divs that their names are stored in and then using that to trigger the Ajax request to get the data and then append it to the DIV on the page.
I'm wondering if there's any other way to do the same thing which is light weight and fast and efficient?
You have either:
AJAX
iframe
Load whole page
Those are really your only choices.
I have been trying to pull some information from the database and using them to generate highcharts and then show generated highcharts in certain divs on my page onchange event of the drop down. I cannot use ajax call as it doesnot support pulling highchart from another page (I already tried that). I want to do
Something like, I somehow get $_POST['dropdown'] value then use that value to get output from sql queries and then pass those values to highcharts javascripting function to generate highcharts WITHOUT PAGE LOADING.
Its very easy to do if the page gets loaded as i can generate the result in the sequence mentioned above on behalf of $_POST['dropdown'] value. Kindly Help.
Thanks,
I cannot use ajax call as it doesnot support pulling highchart from
another page (I already tried that)
Your only other option would be to load an iframe's src with JS. Why exactly can't you use Ajax?
I'm displaying tabular data populated via loop from a database.
I know that I could edit/delete etc in the usual manner, where
Edit Record
But I would really like to do this using the modal-message feature of jquery.
However, what I can't seem to figure out is how to indicate to the modal-message window/div the correct record number from the database (whereas in php, I'm simply using the print function.
Is it feasible to set maybe an onClick event that sets a variable ($id) to equal whatever the $row['abstract_id'] number is?
The idea being that when I click on the Edit button, I can put php within the div and it will call up the correct record.
EDIT for clarity: I don't want to actually edit it, it's to pull up the text of the abstracts, which are too big to fit in the tabular format (but there are too many abstracts to give each submission its own page).
The key here is how I can pass the record id from the database/php side to the javascript side even if it's setting/resetting some variable. I thought about using .load(read_abstract.php) but then realized that I don't think that .load(read_abstract.php?id=' . $row['abstract_id']') would work- and don't know what the JS equivalent would be (or if it exists).
You can move the id into a data attribute in the HTML tag:
echo '<span class="edit-button" data-abstract-id="'.$row['abstract_id'].'">edit</span>'
Then in the modal, you'll be able to reference it with:
jQuery('.edit-button').click(function() {
id = jQuery(this).attr('data-abstract-id');
});
i found it difficult,,,, fetching data from database while a buttons are randomly generated in for each how can i fetch
Without understanding what your question really is, you could go trough the mysql query result like this:
// button_text is a database column in this example
while ($row = mysql_fetch_row($result)){
echo "<button type="button">".$row['button_text']."</button>";
}
But to really help you, you need to rephrase your question!
I'll make some assumptions for what you are trying to do:
1. You have buttons that fetch more info from a db
2. The buttons are "randomly" generated, and each calls different info (pets, cars, etc).
You may or may not be using ajax, but I will describe it basically assuming straight php, and you are using a single page (for clarity in my explanation).
What you need to do is have each button either be a link or a submit for a form. This just depends on whether you want to use GET or POST. The buttons will have php generated links (if GET) or values (if POST). For example, using get the link could be "www.file.php?cat=cars". The button would just have the value of "Cars", and since bother are generated, that shouldn't be an issue keeping them the same.
When the page is now reloaded based on the click, the top of the page has a query in it to get the new info. For example, it would run a query looking for all items that have the car category. Then the new information would be displayed, and the new random buttons would show.
VERY IMPORTANT: Sanitize all GET and POST values before using them in a query