Dynamically populating an UnOrdered List - php

I am attempting following code to populate an UnOrdered List dynamically. The same type of code I am successfully using to populate a DropDown. But when I changed the tags to UnOrdered List, it is not working. When run, it just displays some tags instead of the actual output.
Where is the error:
<?php
require("dbconnection.php");
require("dbaccess.php");
$divName = $_GET['DivName'];
$ulName = $_GET['ControlName'];
$query = $_GET['SqlQuery'];
echo $query;exit;
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<ul id="<?php echo $ulName; ?>" name="<?php echo $ulName; ?>">
<?php while($row=mysql_fetch_array($result))
{ ?>
<li><?php echo $row[1]; ?>"></li>
<?php } ?>
</ul>
The code that I used to populate a DropDown is below: It works absolutely fine:
<?php
require("dbconnection.php");
require("dbaccess.php");
$dropdownControlName = $_GET['DropDownControlName'];
$query = $_GET['SqlQuery'];
dbconnection::OpenConnection();
$result = dbaccess::GetRows($query);
?>
<select id="<?php echo $dropdownControlName; ?>" name="<?php echo $dropdownControlName; ?>">
<option>Select from the list</option>
<?php while($row=mysql_fetch_array($result))
{ ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php } ?>
</select>

The error is here:
<li><?php echo $row[1]; ?>"></li>
should be this:
<li><?php echo $row[1]; ?></li>

Don't know Php but what this line doing :
echo $query;exit;

Are you sure that you have to use the second field of the result set?
<li><?php echo $row[1]; ?>"></li>
There is an extra >" there.
Can you show us the resulting html code ?
SORRY: I was away from the PC for some minutes before posting, just saw that I answered the same as the following answer.

HI,
I used your code and gave some constant values and i got the following out put.
Out Put:
1">
2">
3">
4">
Used code:
`
">
`
and final Conclusion is, this prints the unordered list and i think yo may check your
echo $row[1]; part for any html out puts.
Note: "> This tag comes because of in your code having this value

Related

How to hide id and display their name's instead?

I don't how to hide the id of the running candidates which is candid, I can't remove in the value because it will handle the votes of the candidates I really need some help or any solution. I want that it will display the names in the preview.php and hide the id but don't know how?
Here's the code of plsvote.php:
value="<?php echo $rows['candid'] . "-" ."&nbsp". $rows['lastname'] .",". "&nbsp". $rows['firstname'] ?>"> <?php echo $rows['lastname'] ?>,
<?php echo $rows['firstname'] ?>
- <?php
echo $rows['party_name']?></option>
Here's the preview.php:
<?php
$resultasa = $db->prepare("SELECT * FROM candposition");
$resultasa->execute();
for($i=0; $rowasa = $resultasa->fetch(); $i++){
$exrxrxrx=$rowasa['pos_name'];
if ($exrxrxrx!='Error') {
?>
<h2 class="fs-title"><?php echo $exrxrxrx ?></h2>
//this is the part where I call the value and also the codes of my example image
<input type="hidden" value="<?php echo explode("#", $_POST[$exrxrxrx])[0] ?>" name="votes[]" /><?php echo explode("#", $_POST[$exrxrxrx])[0] ?><br>
You can use the data attrbute in HTML5 to store the id.
Example:
<span data-id="<?= $id?>"><?= $firstname?> <?= $lastname?></span>

Dynamic Dropdown option in a list with image

I was trying get Dropdown option result in a list with respective image, but that gives other than picture...here is my partial codes, any suggestion Bro?
<?php
$university=$_GET['university'];
$sql=mysql_query("SELECT univ FROM university WHERE univ='$university'");
while($row=mysql_fetch_assoc($sql)){
?>
<li>
<select>
<option value='<?php echo $row['univ'] ;?>'>
<?php echo $row['univ'] ;?> <?php echo '<img src=abu.png width:"20"height="20">';?>
</option>
</select>
</li>
<?php
}
?>
As the comments already said, your code formation is not correct. See example below for the right formation. Also a note: DONT use mysql_* anymore because it's deprecated, use mysqli_* or PDO.
<?php
$university=$_GET['university'];
$sql=mysql_query("SELECT univ FROM university WHERE univ='$university'");
?>
<select>
<?php
while($row=mysql_fetch_assoc($sql)){
?>
<li>
<option value='<?php echo $row['univ'] ;?>'>
<?php echo $row['univ'] ;?> <?php echo '<img src=abu.png width:"20"height="20">';?>
</option>
</li>
<?php
}
?>
</select>

If statment to only show one value from an array

I am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code

ZF2 form formatting?

I am using ZF2 and have a form which defines a bunch of elements, and then I render it in my phtml like this:
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formlabel($form->get('description'));
echo $this->formRow($form->get('radioButton'));
echo $this->form()->closeTag();
?>
Which draws a label and a radio button.
My question is how can I then format these elements to my liking? For example make the radio buttons displayed horizontally rather than vertically and maybe change the location of the label.
There's nothing stopping you from formatting them as you have there, you could put the elements inside a list, or andd any additional markup you want to style as you wish.
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
?>
<ul class="form-list">
<li>
<div class="form-control">
<?php echo $this->formlabel($form->get('description')); ?>
<?php echo $this->formElementErrors($form->get('description')) ?>
<?php echo $this->formElement($form->get('description')); ?>
</div>
<div class="form-control">
<?php echo $this->formlabel($form->get('radioButton')); ?>
<?php echo $this->formElementErrors($form->get('radioButton')) ?>
<?php echo $this->formElement($form->get('radioButton')); ?>
</div>
</li>
</ul>
<?php echo $this->form()->closeTag() ?>
If you wanted to have control over the actual elements/inputs themselves you could do something like this:
<label>
<?php echo $form->get('radioButton')->getLabel() ?>
<input class="bob" type="radio"
name="<?php echo $form->get('radioButton')->getName() ?>"
value="<?php echo $form->get('radioButton')->getValue() ?>"
/>
</label>

How to hide php echo in a dropdown menu?

I have a drop down box that shows the weight of the item and how much extra the heavier items cost. I also have javascript that updates the price on the page based on the value selected in the dropdown. Since the javascript updates the price shown on the page, I would like to remove the additional price shown next to the option choices.
the code is:
<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<span id="option-<?php echo $option['product_option_id']; ?>" class="option">
<select name="option[<?php echo $option['product_option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
</option>
<?php } ?>
</select>
</span>
I only want to show the product_option_id in the drop down, I don't want to show the added price for increases; I don't want this part of the code to be visable:
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
however, I have some javascript that updates price based off the $option_value['price']. So I can't just erase it.
Is there a way to keep the output from echoing onto the screen, but still have javascript be able to find it?
Yes:
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span style="display:none" id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
Also you should consider not using an ID on that span, unless you are generating a unique id for each one, as it will cause you problems when you try to grab it with document.getElementById()

Categories