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');
});
Related
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
I need help in identifying how I should set up this non public website.
Basically there are around 2000 images referenced in a database.
Each user will be able to check or uncheck each image with the use of a checkbox.
Some users might have different images checked or unchecked.
I want the checkbox to process an AJAX request to a user specific XML (PHP generated from the db) which contains a boolean variable for each image entry.
The PHP then references the XML and highlights checkedboxes and disables the uncheckedboxes.
Again each user will have different references for each image.
Im not sure if the above is the correct method to use.
I want the page to dynamically load the first 20 images and if the checkbox is changed, instantly updated and refreshed without a page reload. Then I'll paginate to the next 20.
If I'm on the right track I'll attempt a demo and post an update.
Thanks,
Depends how you want to do it. You'll need to brush up on your javascript as well to track the on change event. If you're bring in the images with ajax to begin with I would create an object for each and attach the event to element. Then on click you could post the image_id or what have you to the server. Alternatively you could use an attribute on the checkbox/image like data-imageid="1"
JSON or XML, both will work, it just depends how you want to design it. Though from my experience I would use JSON instead.
The JSON array you would return might look something like {1:true,2:false,3:true} etc, so foreach key value pair you would either check it be it true or not on false.
Consider editing your tags for javascript or jquery to see if you get some better answers. Or I could elaborate further if I'm on the right track.
I have piece of code which refresh data periodically (after 5 sec.), and put it into a table.
This table has sorting option, and checkbox to select a particular row.
Now problem is when i want to sort or choose a row using checkbox, because of auto refresh it set whole table data in previous position. Means if any data i had sorted will not show sorted and/or checked row will be unchecked again.
Please provide me some suggestion how to handle this issue.
Thanks
Your alternative might be to do an AJAX call to pull the data periodically instead of refreshing the whole page via PHP. That way you'll be able to send the correct parameters to handle the sort towards the logic within PHP.
OR
You can push named parameters/actions within the url for sorting purposes. Then use URL's on the table header and the page reloads with a url of something like:
http://example.com/table/sort:asc
http://example.com/table?sort=asc
And then your logic could appropriately pick the previously selected areas up.
if (isset($_GET['sort'])) {
//Do sorting stuff
}
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
I have a advertisement website with alot of records stored in a mysql db.
On my main page, I have a form where users may specify their search criteria.
Action is set to myPhp.php file.
myPhp.php contains NO HTML, only php code, and it is basically something like this:
1- get values from FORM and build a SQL query
2- query MYSQL db.
3-display all results in a table using
`while($row=mysql_fetch_array($res))`
4- echo the table.
In this table which is created in PHP, I have several links also, and whenever they are clicked, a javascript function on the parent page is called, which sets a hidden input value to something, and then submits the form again with the chosen variable.
Ex: Whenever users want to go to the next page in the search results, they have to click on a 'next' link created in PHP, and then the javascript gets called, which sets a hidden input value to 'next', and then the form is submitted again, and PHP file GETS the variable from the hidden input and detects that its value is set to 'NEXT' and then displays the next results.
Is there really not another way to do all this ? (that is, a better way when it comes to performance and reliability)
Im still learning so I am very thankful for your help!
I will update this Question whenever you need more input.
Thanks
Replace the next javascript call with a link to
http://yourdomain/myPhp.php?page=2
Then check the get parameter in myPhp.php:
if(isset($_GET['page']) AND is_numeric($_GET['page'])){
$limit = (int) $_GET['page'] * MAX_RECORDS . ', ' . MAX_RECORDS;
} else {
$limit = MAX_RECORDS;
}
//...
$query .= 'LIMIT '. $limit;
Of course you have to change it as your constants change and such.
This method called paginating. Take a look at the Zend Framework's Paginator module to the better understanding.
When creating the link you can use a querystring to specify the parameter that you would like to send to the server rather than submitting a form. So if you have a hidden input in a form called next then you can accompish the same thing like this:
Next
On the myPhp.php page you can get the value of next in a similar way as when you send a form.
If these links have at least one same class across board (with a title attribute) you can attach to them to can attach all these links to a single click event and test to see what title is on the element clicked.
With that you can use a switch to trigger the right function to perform the task (I suppose using JQuery/Ajax).
This should work. At least no hidden fields.
Example:
Next
Ad Details