php removing item/variable from php array using button - php

Im looking for help with this. I've tried unset and other options and nothing seems to be working. I hate to bother people but ive searched google till the cows come home and im doing it wrong.
Here is my code:
<?php
$orderArray = $_SESSION['orderVal'];
foreach($orderArray as $orderVal)
{
$valInvent = getOrderInventories($orderVal['invId']);?>
<tr><td><?php echo $valInvent['itemnumber'];?></td>
<td><?php echo $valInvent['description'];?></td>
<td><?php echo $valInvent['cp'];?></td>
<td><?php echo $orderVal['price'];?></td>
<td><?php echo $orderVal['qty'];?></td>
<td></td>
</td>
I want to remove an item from this array using one of the variables.

This should work.
I am using
unset($valInvent['itemnumber']);

Related

Can I carry more than one variable in an href? [duplicate]

This question already has answers here:
How to pass multiple parameters in a querystring
(7 answers)
Closed 1 year ago.
I'm carrying one variable in "reserva" wich I later I use $_GET('reserva'), but I also need another one of the rows,how could I do it?
<?php
while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['idps'];?></td>
<td><?php echo $row['Descrição'];?></td>
<td><?php echo $row['dia'];?></td>
<td><?php echo $row['dataini'];?></td>
<td><?php echo $row['datafim'];?></td>
<td><?php echo $row['tblstaff_idPrestador'];?></td>
<td><a href='marcar.php?reserva=<?php echo $row['idps'];?>'>Marcar</a></td>
</tr>
<?php endwhile;?>
Yes, you can append multiple values in a GET request using &:
<a href='marcar.php?reserva=<?php echo $row['idps'];?>&key=value'>Marcar</a>
^^^^^^^^^^
as #raina77ow pointed out, be aware that & is a "reserved" char, so if your string contains that, you have to encode it, and for that, in PHP you have the function urlencode

Opencart display attrbutes of related products

I need help with a loop in opencart.
I want to display 2 - 3 product next to each other other on the product page. similar to how products are displayed in on the compare page. I've achieved the product limit via code already and I've managed to display everything else, pictures, price etc. My issue is the attributes.
I know that i need to reach into this array
$this->data['products'][] = array(
......
'attribute' => $attribute_data,
I've also included this line of code
$attribute_groups = $this->model_catalog_product->getProductAttributes($product_id);
my loop is
<?php foreach ($attribute_group['attribute'] as $key => $attribute) { ?>
<tbody>
<tr>
<td><?php echo $attribute['name']; ?></td>
<td><?php echo $attribute['text']; ?></td>
<?php } ?>
<?php } ?>
This gets me all attributes of the current product but displays errors for any attributes not filled in if there are any related products.
Then I have no idea on how to reach into the array and display the related product attribute details.
please help
<?php if isset($attribute['name'];); {?>
<td><?php echo $attribute['name']; ?></td>
<?php } ?>
Try this; the error will not be shown.

PHP + HTML in MySQL echo

This will in this case echo multiple authors, release dates, and covers for a book on a single page.
My question is: How do I make it look nice with a table, and my CSS file? I just can't get it right, kinda almost made it work once, but it showed just the one book and then started on a new row, and I want at least 4 books/row, and the borders were completely off.
Really silly question I know, and I've tried googling and experimenting but I'm having serious trouble making it really work.
Also, if I want to echo a variable ($genre) in a link-text, say
Home > Books > CurrentGenreVariable($genre)
how'd I do that neatly? I need a slight kick-start, that's all I think.
Thanks in advance.
You follow the generic looping patterns. I presume you're doing this with a while() loop?
<table>
<?php while ($row = FETCH_THE_DATA): ?>
<tr>
<td><?php echo $row['author']; ?></td>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['cover']; ?></td>
</tr>
<?php endwhile; ?>
</table>

Export specified text in CSV to HTML

I have a CSV file with this information: CSV Link
As you can see it is a lot of data here, and I am asking if it is possible to convert some of the data to a table in HTML. Like if I only would convert the data in "Kamp" "Række" "Navn1" "Navn2" and "Resultat"
Would it be possible or do I need to convert everything to html?
I have not access to edit the CSV file because it automatically imports new data.
Hopefully there are someone with a gifted mind here who has the solution.
If anything is not clear then please ask me.
You can start from here, you'll have the data of each row inside a php array, then you can echo what you want inside html.
<table>
<?php
$handle=fopen('filename.csv', r);
while($data=fgetcsv($handle, 1000, ';', '"')){?>
<tr>
<td><?php echo $data[0];?></td>
<td><?php echo $data[1];?></td>
<td><?php echo $data[2];?></td>
<td><?php echo $data[3];?></td>
</tr>
<?php }
fclose($handle);
?>
</table>
But I see you have too many " in your csv file.

PHP Symfony Convert Propel Choice to String

I am using a propel form to allow a user to create an account, the form has two parts; the entering and then the preview.
On my preview page I declare the values of the form as usual and these are provided by the previous form
public function configure() {
//Preview page no fields are displayed anyway xD
$this->useFields(array('email', 'user_gender_id', 'search_gender_id', 'content', 'age', 'location'));
But instead of outputting the fields I am trying to render the values on the page:
<?php echo $form->renderHiddenFields(); ?>
<?php foreach($form as $field): ?>
<?php if(!$field->isHidden()): ?>
<tr>
<th><?php echo $field->renderLabel() ?></th>
<td><?php echo $field->getValue(); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php echo $form; ?>
<?php endif; ?>
Unfortunately for my sfWidgetFormPropelChoice / sfWidgetFormChoice fields it just outputs the chosen ID rather than a string representation of it.
Is there a proper way in Symfony to output the text representation of a widget's value? Or do I have to hack something together? (any ideas?)
Many thanks,
Pez,
Try:
$obj = $form->getObject();
to have the values of your object. Then:
echo $obj[$field->getName()];
this can work in most cases. But, if it won't, you'll have to write all the preview fields by hand and display them using the $obj above.
I got around this problem by doing the following:
<td><?php if(method_exists($field->getWidget(), "getChoices")) {
$choices = $field->getWidget()->getChoices();
echo $choices[$field->getValue()];
} else
echo $field->getValue();
?></td>
I hope this is of use to someone as it has been driving me crazy!

Categories