I am working on a project that it's a bit over my basic level of web development I am not able to understand how to get specific data from my SQL and show it follow by a button that will show the entire data of the specific row a small example how it has to look on my html its:
Name. Postcode telephone (button view more ).And the next row will be the same. Hope this it understandable I can't wait for an answer.
For the first part of your question here is how you take data from database with php and show it on the page. Read this Also there are a several way to do that, more example you can find here if you interested...
For second part of your question to show data on specific location on your page, you should't just echo data instead of that place your code in variable something like this:
if ($result->num_rows > 0) {
$myTable = "<table><tr><th>ID</th><th>Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
$myTable .= "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
}
$myTable .= "</table>";
} else {
echo "0 results";
}
end then in your page i figured out it's organized as larger table just place variable $myTable where you want to be. Something like
<td class="">$myTable</td>
GL!
P.S. note that when you continue string for my table you have .= (dot equal) sign if you miss it it won't work as you expect..
Related
I have a Drupal commerce website with about 100 000 products. Now customer wants me to change product image filenames and add alternative(alt) texts to images for all existing products - based product names and colors.
File field paths seemed to be great to changing the file names of image files. But I just cannot figure out how to add alt texts to images automatically. I've been trying hook_file_update, hook_file_presave, hook_entity_presave etc. I'm trying to add alt text during File field paths' batch update and all of the hooks are running but for some reason alt text data is not saved to entity.
Product image field is type of Image with Media browser widget.
Any help for this?
Here's hook_entity_presave() code:
if ($entity->type == 'image' && (empty($entity->alt) || empty($entity->field_file_image_alt_text))) {
$product = _get_referenced_product($entity->fid);
if ($product) {
$full_product = commerce_product_load($product->product_id);
$title = $full_product->title;
if (!empty($full_product->field_search_color)) {
$search_color = $full_product->field_search_color[LANGUAGE_NONE][0]['tid'];
$search_color = taxonomy_term_load($search_color);
$color_name = $search_color->name;
}
$entity->alt = $title . ' ' .ucfirst($color_name);
$entity->field_file_image_alt_text = $title . ' ' .ucfirst($color_name);
object_log('Entity', $entity);
object_log('Type', $type);
}
}
I had the same issue and I updated the alt tag of all images in my articles. Note, in my case I wanted to updated nodes.
And, I used following code:
https://www.gyanblog.com/gyan/34-how-add-alt-attribute-images-all-my-drupal-articles-or-other-content-type/
Actually the problem in my case was that I was trying to set alt field value in wrong way. "Field_file_image_alt_text" field the image element is using is a normal textfield so it clearly needs the following data structure.
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $title . ' ' .ucfirst($color_name);
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['safe_value'] = $title . ' ' .ucfirst($color_name);
So just a stupid mistake by me! And btw, I ended up using hook_file_presave() hook.
I want to create a module for add a dynamic grid on cms page like this:
I'm able to create custom field like text or file but I don't know how can I add (remove) multiple elements, I don't find any example/tutorial, can you give me some tips or some link?
edit:
studying magento code into Varien/data/form/gallery I find a way, I use gallery.php element as starting point and then I create my element, the problem is how to save the data, for now I save the data into a column as an array or json
$aa = "[";
foreach ($_FILES as $file)
{
$aa = $aa . $file["name"]["-1"] . ",";
}
$aa = $aa . "]";
$aa = str_replace(",]","]",$aa);
$model->setBackground($aa);
I,m able to get this value but I don't think is the best way, is better create a custom magento model?
The manualRowMove works fine visually but the underlying dom is not getting updated. After manualRowMove the HOT.getData() is showing the old sequence of data and not the latest sequence after row swap.
Please advise what I am doing wrong or is it a bug.
Turning on manualRowMove and moving rows around does not affect the original data source. HOT.getData() returns the original data source, which is not what the current state of the table is.
Plugins like manualRowMove, manualColMove, columnSorting are just abstractions that sit on top of the data layer. They maintain state on the handsontable object (ie the sortIndex attribute) which basically act as lookup tables from what the authors call "logical index" to "physical index". Read more about it here: https://github.com/handsontable/handsontable/wiki/Understanding-column-sorting-plugin
It seems like you are trying to allow users to sort the order of the table then save that order. You'll have to roll your own func to walk the table and use a method like getDataAtRow() to get data in table order.
the way I fixed this was to use a PHP script to push the new order to the database on the server (there needs to be some < / > swap logic, it isn't that easy in PHP land, but it is doable), in theory you could recollect the grid and "refresh" it but I didn't feel it was necessary. Obviously the original json from my database is listed by the order
afterRowMove: function (oldIndex, newIndex){
$.post('../ajax/partsOrder.php?id=212&new_parts_order=' + newIndex + '&old_parts_order=' + oldIndex, function(data) {
var msg = '';
if (data.err!=0 || data.url==0) {
msg = 'Error: ' + data.err;
}
else {
msg = 'Success: ' + data.msg;
}
console.log('partsOrder.php says: '+msg);
},"json");
}
PS: I think this is a major omission from handontable, I was not impressed that the getData() doesn't simply represent the gui. In fact it's borderline criminal that they even worked on the gui at all without this
I am getting MLNumbers from RETS Server but now I need to get all the fields of all the MLNumbers and store into my database. Could anybody help me to write query to get the whole property Object.
If you have all the Listing Numbers then you just need to write a search query to pull all the results back and process the results. I haven't ever seen a field name MLNumber but you will have to figure that out:
<?php
$search = $rets->SearchQuery("Property","RES","(MLNumber=11111,22222,33333)");
while ($listing = $rets->FetchRow($search)) {
echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
echo "{$listing['City']}, ";
echo "{$listing['State']} {$listing['ZipCode']} listed for ";
echo "\$".number_format($listing['ListPrice'])."\n";
}
$rets->FreeResult($search);
I think this should return the results you need. You will need to figure out the Resource/Class/Field name you need to use for your SearchQuery().
More PHRETS examples here.
Im on the page showing the products I have avaliable in my Magento store. I want to get the current ID of the order should I continue on adding the order to my cart and buy it at the end.
Since the order per say does not exist and more than one person can buy at the same time, I would have to calculate the order ID someway while making sure that it does not conflict with another person making another order at the same time.
Another thing is like I mentioned that this is on the product listing page (/../../../../../template/catalog/product/list.phtml) so a "order" per say (I mentioned this before) does not exist.
How can I get the best possible way a order ID that is not in usage?
In Magento,on creation on cart a quote object is created and for each item you add there is a quote_item object.
You can get the current quote id from session
$session = Mage::getSingleton('checkout/session');
$quote_id = $session->getQuoteId();
And subsequently load the sales_quote object
$item_quote = Mage::getModel('sales/quote')->load($quote_id);
By this you could access any attribute related to the quote table easily.
For the items in cart you can access by
$items_in_cart = $quote->getAllItems();
And run this in a loop
foreach ($items_in_cart as $item) {
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
}
Hope this helps!
For more reference you can refer here
http://inchoo.net/ecommerce/magento/magento-quote-order-invoice-workflow/
Take a look here to create a order, you can create a order and when you save your new order get the next id for order.