How to populate values in drop down list in php postgresql - postgresql

I am getting error while populating the values in drop down list using php postgresql. Error means no output in drop down list.
Below is my code.
<!DOCTYPE html>
<html>
<body>
<form name="form1" id="form1" action="" method="post">
<select name="selectid" Id="select">
<option value="">--- Select ---</option>
<?php
// postgresql database connection
include ('dbconfig.php');
$list = pg_query($db, "select id, name from codevalue ");
while($row_list=pg_fetch_array($list)){
?>
<option value=<?php echo $row_list["id"]; ?>>
<?php echo $row_list["name"]; ?>
</option>
<?php
}
?>
</select>
?>
<button type="submit" name="submit" >Submit</button>
</form>
</body>
</html>
Thanks in advance.

Change
while($row_list=pg_fetch_array($list)){
to
while($row_list=pg_fetch_assoc($list)){
You are retrieving an array and not an associated value. As an array you'd have to reference column and row.

Change your loop to an assoc instead of an array. Try this example:
Check if you have any rows in the database.
if (pg_num_rows($list) == 0)
{
echo "<option>No rows exist</option>";
} else {
while($row_list = pg_fetch_assoc($list)){
?>
<option value=<?php echo $row_list["id"]; ?>>
<?php echo $row_list["name"]; ?>
</option>
<?php
}
}

Related

Undefined variable in Option Value CodeIgniter

What I'm I doing wrong?
application/views/pegawai_read.php
<select name="" id="" class="form-control">
<?php
foreach($nm_berkas_jn->result() as $j){
?>
<option value="<?php echo $j->id_berkas_jn;?>"><?php echo $j->nm_berkas_jn;?></option>
<?php } ?>
</select>
application/controllers/pegawai.php
public function read($id) {
$id_berkas_jn=$this->session->userdata('id_berkas_jn');
$text = "SELECT * FROM kpg_berkas_jn";
$d['nm_berkas_jn'] = $this->app_model->manualQuery($text);
$d['level']=$this->session->userdata('level');
}
application/models/app_model.php
function manualQuery($q) {
return $this->db->query($q);
}
Add the following line to the bottom of your controller. This send the data to the view
$this->load->view('pegawai_read', $d);

Opencart get select value to controller for filter

I have page called no.tpl, in this page am displaying customer name in select dropdown
this is the code:
no.tpl
<select name="customer_id" id="customer" style="width: 325px;margin-bottom:10px" class="form-control">
<?php foreach($customerData as $customer){ ?>
<option value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
<?php }?>
</select>
In controller page i have to filter selected customer list
$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='6'");
$selectedCustomer = $queryCustomer->row;
$selectedCustomerId = $selectedCustomer['customer_id'];
$selectedCustomerName = $selectedCustomer['name'];
$selectedCustomerEmail = $selectedCustomer['email'];
I want customer_id='6' as selected customer_id. I mean pass the select value to controller page
Try this code in view page
<select name="customer_id" id="input-sales-person" style="width: 325px;margin-bottom:10px" class="form-control">
<?php foreach($customerData as $customer){ ?>
<option id="temp" value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
<?php }?>
</select>
<input type="submit" id="noOrder" Onclick="return ConfirmDelete();" value="Submit" class="btn btn-primary">
Use this following script
<script type="text/javascript">
$('#noOrder').on('click', function() {
var temp1=$( "#input-sales-person option:selected" ).val();
var temp2=$( "#input-sales-person option:selected" ).text();
document.cookie = "selectedCustomerId=" +temp1;
document.cookie = "selectedCustomerName=" +temp2;
location="index.php?route=sale/no";
});
</script>
In controller pass the customer_id as $selectedCustomerId=$_COOKIE['selectedCustomerId'];
$selectedCustomerId=$_COOKIE['selectedCustomerId']; /*customer_id=6*/
$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='".$selectedCustomerId."'");

Contact page template - redirect to 'thank you page' not working

I'm trying to submit a form via custom page template but the problem is that it only works with form action="<?php the_permalink() ?>" and I need the form to be submitted and redirected to something like this form action="<?php bloginfo('url')?>/message-sent?id=<?php the_ID() ?>"
Full code:
<?php
$emailError = '';
if(isset($_POST['submitted'])) {
$email = trim($_POST['email']);
//setup self email address
$emailTo = $email;
$subject = "[reminder] Don't forget to download " . get_the_title();
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: Myemail reminders <no-reply#xyz.com>' . "\r\n";
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
} ?>
<section class="box grid_9 list_posts">
<div class="inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="entry-content">
<div class="contact-form clearfix">
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks">
<?php _e('Thanks, your email was sent successfully.', 'framework') ?>
</div>
<?php } else { ?>
<?php the_content(); ?>
<?php if(isset($hasError) || isset($captchaError)) { ?>
<p class="error"><?php _e('Sorry, an error occured.', 'framework') ?>
<?php } ?>
<form action="<?php the_permalink()?>" id="contactForm" method="post">
<ul class="contactform">
<li>
<input type="email" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" required="required" />
</li>
<li class="buttons">
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="submit" value="Remind Me!"></input>
</li>
</ul></form>
<?php } ?></div>
</div>
</div>
<?php endwhile; else: ?>
<div id="post-0" <?php post_class() ?>>
<h1 class="entry-title"><?php _e('Error 404 - Not Found', 'framework') ?></h1>
</div>
<?php endif; ?></div>
</section>
I got no php errors in log, page is redirected successfully, but no email is sent. When using the_permalink, everything works just fine.
When submitting the form data to a different script, make sure the code for (validating the input and) sending the email is in that very file.
Otherwise, your URL /message-sent might rewrite to a completely different script and the script with the above code isn't involved at all once the submit button gets clicked.
Did that held you? Feel free, to ask, if my wording is incomprehensible or if my description isn't clear to you
Maybe you forgot to put ".php" at the end of your /message-sent?id=xxx file, i.e /message-sent.php?id=xxx?
Another thought: It is always a good idea to filter the user input, because you will receive a lot of spam, put some sort of CAPTCHA validation code and sanitize/validate the whole user input text, i.e. every text, which comes from input fields of your form.
For email:
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
For name and comments:
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$comments = filter_var(strip_tags($_POST['comments']), FILTER_SANITIZE_STRING);

"Available Product Listing Sort By" will not remove options from drop-down

I want to remove/hide some attribute sort options in my categories.
For this I unchecked "use all attributes" and selected the attributes I want to display in the sort select.
After this I cleared cache and reindexed categories and products data.
But I still have all attributes showing in the sort by select. Can somone help me please?
I'm using a modified toolbar.phtml to hide the "position" sort option, but I think this has nothing to do with the problem:
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<?php if ($_order != $this->__('Position')) : // Remove "Position" from the sort option list ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" class="v-middle" />
<?php else: ?>
<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" class="v-middle" />
<?php endif; ?>
</div>
EDIT:
Here's an image from my display settings inside the category:
But inside my storeview all options are displayed
The problem for me was exactly what the error was saying, it just was hard to understand. You can't pick a default sort option that isn't enabled
Okay, fixed the problem:
I changed the settings in all store views, but it didn't changed in all sotre views. When I tried to change the setting Use Default Value in my "languagesviews". I get the error "Default Product Listing Sort by not exists on Available Product Listing Sort By".
So I "just" need to change all categorysettings of each language.
EDIT:
After editing some categories and checking/unchecking "use default values" the error is gone and I set all "use default values" to yes.

accessing request parameters inside paginator partial

1)how do i access the search $keyword inside the paginator partial to create search freindly urls ? clearly, passing the keyword as $this->view->paginator->keyword doesnt work.
2) currently, the search button's name is also send as param . for eg when searching for 'a' the url becomes http://localhost/search/index/search/a/submit//page/2. any way to stop this ?
Search Form:
<form id="search" method="get" action="/search">
<input id="searchfield" onClick="this.value=''" type="text" name="search" value="Search wallpapers"/>
<input id="searchbutton" type="submit" value="" name="submit"/>
</form>
Action inside searchController:
public function indexAction()
{
$keyword=$this->_request->getParam('search');
$alnumFilter=new Zend_Filter_Alnum();
$dataModel=new Model_data();
$adapter=$dataModel->fetchPaginatorAdapter("title LIKE '%".$keyword."%'", '');
$paginator=new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(18);
$page=$this->_request->getParam('page', 1);
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;
$this->view->keyword=$keyword;
}
index.phtml (view) file:
partialLoop('wallpaper/table-row.phtml',$this->paginator) ;?>
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml');?>
</div>
search-paginator-control.phtml file:
if ($this->pageCount){
$params=Zend_Controller_Front::getInstance()->getRequest()->getParams();
if(isset($this->previous)){
?>
Previous
<?php
}
else{
?> Previous <?php
}
foreach($this->pagesInRange as $page){
if($page !=$this->current){
?>
<?=$page;?>
<?
}
else{
echo $page;
}
}
if(isset($this->next)){
?>
Next
<?php
}
else{
?> Next <?php
}
}
The paginationControl view helper accepts a 4th parameter, that is a array of parameters, so in your case you could do something like this:
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml', array('keyword' => $this->keyword));?>
</div>
Then you access it inside your pagination using $this->keyword.