Today I faced with a problem about html select
here is the code :
<select id="optdon" onchange="showimage(this);" name="optdon" style="width:<?php echo $drop_width; ?>px;">
<option value="">--Select don--</option>
<?php foreach($for_don as $donname) { if(isset($donname['don_name']) && $donname['status'] == 1) { ?>
<option value="<?php echo $donname['don_id']; ?>"><?php echo $donname['don_name']?></option>
<?php } } ?>
</select>
<br /><br />
<div align="center">
<?php $i = 0; foreach($for_don as $donimage) { if(isset($donimage['don_image'])) { ?>
<div class="<?php echo $i; ?>" style="display:none;" id="<?php echo $donimage['don_id']; ?>"><img src="<?php echo $donimage['don_image']?>" /></div>
<?php $i = $i + 1;} }?>
function showimage(ids){
clearall();
if(ids.value != ''){
jQuery('#'+ids.value).show();
}
}
What is the project ? I need to select first option !!!
It is easy but when i set the first option selected it's image doesn't load in the page first load . option's image appears on changing options.
I have these two answers for selecting first option (when thre is just one option )
suggestion 1
<?php $x = 0; foreach($for_don as $donname){ if(isset($donname['don_name']) && $donname['status'] == 1) { $x = $x + 1; }} ?>
<select id="optdon" onload="showimage(this);" name="optdon" style="width:<?php echo $drop_width; ?>px;">
<option value="">--Select don--</option>
<?php $z = 0; $selected='selected' ?>
<?php foreach($for_don as $donname) { if(isset($donname['don_name']) && $donname['status'] == 1) { $z = $z + 1; ?>
<option <?php if($z==1 && $x == 1)echo $selected; ?> value="<?php echo $donname['don_id']; ?>" ><?php echo $donname['don_name']?></option>
<?php } } ?>
</select>
<br /><br />
<div align="center">
<?php $i = 0; foreach($for_don as $donimage) { if(isset($donimage['don_image'])) { ?>
<div class="<?php echo $i; ?>" style="display:none;" id="<?php echo $donimage['don_id']; ?>"><img src="<?php echo $donimage['don_image']?>" /></div>
<?php $i = $i + 1;} }?>
</div>
suggestion 2 :
<?php $x = 0; foreach($for_don as $donname){ if(isset($donname['donation_name']) && $donname['status'] == 1) { $x = $x + 1; }} ?>
<?php if($x == 1) { ?>
??????
<?php } else { ?>
thank you
Add this JavaScript:
var optdon = document.getElementById('optdon');
optdon.onchange.call(optdon);
This will trigger the onChange event handler, allowing the initial option to have its effect.
Related
<div class="puffar">
<?php
//Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
//Get children
$children = ($post->post_parent) ? get_page_children($post->post_parent, $all_wp_pages) : get_page_children($post->ID, $all_wp_pages);
$i = 0;
//Build custom items
echo "<div class='row'>";
foreach ($children as $child) {
?>
<div class="col-sm-6">
<div class="puff">
<div class="puff-image-holder">
<?php echo get_the_post_thumbnail($child->ID, 'full'); ?>
</div>
<fieldset class="linedHeadline hlmedium">
<legend><?php echo get_the_title($child->ID); ?></legend>
</fieldset>
<?php echo get_field("puff_introtext", $child->ID); ?>
<?php
$values = get_field('puff_lanktext', $child->ID);
if (get_field("popup_eller_lank", $child->ID) == "popup") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage open-popup"
href="<?php echo get_page_link($child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
</fieldset>
<?php
} elseif (get_field("popup_eller_lank", $child->ID) == "extern") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage"
href="<?php echo get_field("puff_lank", $child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
<?php
$i++;
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
} else {
}
?>
</div>
</div>
<?php } ?>
</div>
</div>
I want every 2 items that's rendered out to be wrapped in a <div class="row">, however I can't figure it out. Can anyone help me?
So basically the row should wrap every 2 elements that is getting looped. I have been stuck on this forever... Hopefully anyone got better expertise than me hehe.
The div="row" should wrap the col-sm-6 and class="puff".
$i = 0;
foreach ($children as $child) {
$i++;
// your code goes here
if($i % 2 == 0) {
echo "</div><div class='row'>";
// reset the counter to 0
$i = 0 ;
}
}
use proper logic
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;
First check if its mod by 2 or not (Gives 0 value after MOD), then close div , open new.
Now increase counter . Because for the first time , i will be 0 , then you increment it and then you use logic. So in short counter shoul be incremented at the end only not in between before you do any operation/logic.
Updated
Use code as it is **: issue was you have i++ and your condition in 3rd else if which never executed. So took it outside All and just before foreach.
<div class="puffar">
<?php
//Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
//Get children
$children = ($post->post_parent) ? get_page_children($post->post_parent, $all_wp_pages) : get_page_children($post->ID, $all_wp_pages);
$i = 0;
//Build custom items
echo "<div class='row'>";
foreach ($children as $child) {
?>
<div class="col-sm-6">
<div class="puff">
<div class="puff-image-holder">
<?php echo get_the_post_thumbnail($child->ID, 'full'); ?>
</div>
<fieldset class="linedHeadline hlmedium">
<legend><?php echo get_the_title($child->ID); ?></legend>
</fieldset>
<?php echo get_field("puff_introtext", $child->ID); ?>
<?php
$values = get_field('puff_lanktext', $child->ID);
if (get_field("popup_eller_lank", $child->ID) == "popup") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage open-popup"
href="<?php echo get_page_link($child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
</fieldset>
<?php
} elseif (get_field("popup_eller_lank", $child->ID) == "extern") {
?>
<fieldset class="linedHeadline hlmedium">
<legend><a class="linktopage"
href="<?php echo get_field("puff_lank", $child->ID); ?>"><?php echo get_field("puff_lanktext", $child->ID); ?> </a>
</legend>
<?php
} else {
}
?>
</div>
</div>
<?php
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;
} ?>
</div>
</div>
First set $i=0;
if ($i % 2 == 0) {
echo "</div><div class='row'>";
}
$i++;
How do I merge two (for) in one code?
e.g first code
for ($i = 0, $n = count($options); $i < $n; $i ++) {}
and second code
for ($u = 'rel_article1'; $u <= 'rel_article5'; $u++)
here is oll code
<?php if ($display_poll) { ?>
<form action="<?php echo JRoute::_('index.php');?>" method="post" name="poll_vote_<?php echo $poll->id;?>" id="poll_vote_<?php echo $poll->id;?>">
<?php for ($i = 0, $n = count($options); $i < $n; $i ++) { ?>
<label for="mod_voteid<?php echo $options[$i]->id;?>" class="<?php echo $tabclass_arr[$tabcnt].$params->get('moduleclass_sfx'); ?>" style="display:block; padding:2px;">
<input type="radio" name="voteid" id="mod_voteid<?php echo $options[$i]->id;?>" value="<?php echo $options[$i]->id;?>" alt="<?php echo $options[$i]->id;?>" <?php echo $disabled; ?> />
<?php echo $options[$i]->text; ?> <?php for ($u = 'rel_article1'; $u <= 'rel_article5'; $u++) { ?>
<a href="<?php echo $params->get($u); ?>" onClick="return popup(this, 'notes')">
<img src="/images/stories/add.png" alt="play"></a>
<?php
} ?
I want in one poll show onle play button
now shows this
here is my xml code:
You don't really need that second for. You already have an index with $i from your first loop. (Except that it starts from 0 instead of 1, but you can easily get it working)
Remove the second for, and try this :
// echo $params->get($u);
echo $params->get('rel_article' . ($i + 1));
i am very new to Ajax and jquery.
I have already post my queston here
How can i use ajax with javascript function
but not clear to me,so i have paste my all code.
i am using the following javascript function to get the value from the list those user selected from list and pass this value to sql query to display products.
i am trying to reaload only products.
but using this function each time the page is reloading. i am trying to use ajax using this function.how can i use ajax with this need syntax.
In this 3 things Reaload my whole page are 1)Search form 2)sort by 3)view on page(limit)
<?php
/*
Template Name:Wheel
*/
?>
<?php get_header(); ?>
<script type="text/javascript" language="javascript">
function pagelim(index){
var page_lim=$('#page_num li').get(index).id;
$("#main-content-wrap").load("<?php echo get_option('head'); ?>"+'?wheel&limit=' + page_lim);
}
</script>
<script type="text/javascript" language="javascript">
function dateby(index){
var date_by=$('#sort-by-date a').get(index).id;
var cls=document.getElementById(date_by).className;
if(date_by=="ASC")
{
date_by="DESC";
}
else
{
date_by="ASC";
}
self.location="<?php echo get_option('head'); ?>"+'?wheel&sort=' + date_by ;
}
</script>
<script type="text/javascript" language="javascript">
onLoad(){
//search-option_form.removeClass('jqtransformdone');
}
</script>
<?php
$sort_by=$_GET['sort'];
if($sort_by=="")
{
$sort_by="ASC";
}
else
{
$sort_by=="DESC";
}
$page = (get_query_var('page')) ? get_query_var('page') : 1;
$lim=$_GET['limit'];
if($lim=="")
$limit = 1;
else
$limit =$lim;
$offset = ( $page - 1 ) * $limit;
if(isset($_POST['searchsubmit']))
{
$i=1;
$search_query="SELECT * FROM wp_products WHERE 1";
if($_POST['rim_size']!=0)
{$search_query=$search_query." AND rim='".$_POST['rim_size']."'"." ";}
if($_POST['studs']!=0)
{$search_query=$search_query." AND studs='".$_POST['studs']."'"." ";}
if($_POST['miles']!=0)
{
$value=$_POST['miles']-5000;
$search_query=$search_query." AND miles BETWEEN $value AND ". $_POST['miles']." ";
}
if(($_POST['min_price']!=0)&&($_POST['max_price']!=0))
{
$search_query=$search_query." AND "."price BETWEEN ". $_POST['max_price']." AND ".$_POST['min_price']." ";
}
$search_query=$search_query." LIMIT $offset,$limit";
$data=$wpdb->get_results($search_query);
}//if ends
else{$data = $wpdb->get_results("select * from wp_products order by product_id $sort_by
LIMIT $offset,$limit ");}
?>
<div class="main noborder" >
<div id="main-content-wrap">
<!-- - - - - - - - - - - - - - - Container - - - - - - - - - - - - - -
- - -->
<section class="container sbr clearfix left-section">
<!-- - - - - - - - - - - - - - - Content - - - - - - - - - - - - - - -
- -->
//here is search box
<div class="widget_custom_search">
<h3 class="widget-title"><span>Search</span> Filters</h3>
<form method="post" id="search-option-form" class="form-panel">
<fieldset>
<label>Rim Size</label>
<select name="rim_size" class="width-190">
<option value="0" >Select</option>
<option value="15" <?php if($_POST['rim_size']=="15") { ?> selected="selected" <?php } ?>>15 Inch</option>
<option value="16" <?php if($_POST['rim_size']=="16") { ?> selected="selected" <?php } ?>>16 Inch</option>
<option value="17" <?php if($_POST['rim_size']=="17") { ?> selected="selected" <?php } ?>>17 Inch</option>
<option value="18" <?php if($_POST['rim_size']=="18") { ?> selected="selected" <?php } ?>>18 Inch</option>
<option value="19" <?php if($_POST['rim_size']=="19") { ?> selected="selected" <?php } ?>>19 Inch</option>
</select>
</fieldset>
<fieldset>
<label>No. of Studs</label>
<select name="studs" class="width-190">
<option value="0">Select</option>
<option value="3" <?php if($_POST['studs']=="3") { ?> selected="selected" <?php } ?> >3</option>
<option value="4" <?php if($_POST['studs']=="4") { ?> selected="selected" <?php } ?> >4</option>
</select>
</fieldset>
<fieldset>
<span class="w110p floatLeft display-block">
<label>Min Price</label>
<select name="min_price" class="floatLeft">
<option value="0">Select</option>
<option value="1000" <?php if($_POST['min_price']=="1000") { ?> selected="selected" <?php } ?> >1000</option>
<option value="2000" <?php if($_POST['min_price']=="2000") { ?> selected="selected" <?php } ?>>2000</option>
['min_price']=="6000") { ?> selected="selected" <?php } ?>>6000</option>
</select>
</span> <span class="w110p floatLeft display-block">
<label>Max Price</label>
<select name="max_price" class="floatLeft">
<option value="0">Select</option>
<option value="1000" <?php if($_POST['max_price']=="1000") { ?> selected="selected" <?php } ?>>1000</option>
<option value="2000" <?php if($_POST['max_price']=="2000") { ?> selected="selected" <?php } ?>>2000</option>
<option value="3000" <?php if($_POST['max_price']=="3000") { ?> selected="selected" <?php } ?>>3000</option>
</select>
</span>
</fieldset>
<fieldset>
<label>Miles</label>
<select name="miles" class="width-190">
<option value="0">Select</option>
<option value="5000" <?php if($_POST['miles']=="5000") { ?> selected="selected" <?php } ?>>5000</option>
<option value="10000" <?php if($_POST['miles']=="10000") { ?> selected="selected" <?php } ?>>10000</option>
<option value="60000" <?php if($_POST['miles']=="60000") { ?> selected="selected" <?php } ?>>60000</option>
<option value="65000" <?php if($_POST['miles']=="65000") { ?> selected="selected" <?php } ?>>65000</option>
<option value="70000" <?php if($_POST['miles']=="70000") { ?> selected="selected" <?php } ?>>70000</option>
</select>
</fieldset>
<fieldset class="top-padding-30">
<button name="searchsubmit" type="submit" id="searchsubmit" class="common-button green-button-bg w90p floaL mLeft5">SEARCH</button>
</fieldset>
</form>
<!--/ .form-panel-->
</div>
</section>
<!--/.container -->
<!-- - - - - - - - - - - - - end Container - - - - - - - - - - - - - -
- - -->
<section class="container clearfix right-section">
<div id="pagination-sort-lniks">
<?php
$total=$wpdb->get_results("select * from wp_products ");
$pages = COUNT($total);
$pages = ceil($pages / $limit);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
// Pagination
?>
<?php if($sort_by=="ASC")
$class="up-arrow";
else
$class="down-arrow";
//here to select sort by and view on page ?>
<div class="sort-links"><span class="by-date" id="sort-by-date">Sort by: <a href="#" id='<?php _e($sort_by)?>' class='<?php _e($class)?>' onclick="dateby($(this).index())" >Date</a>
</span>
<span id="view-on-page">View on Page: <?php if($lim=="") { _e($limit); } else { _e($lim); } ?>
<ul id="page_num">
<li id="5" onclick="pagelim($(this).index())">5</li>
<li id="10" onclick="pagelim($(this).index())">10</li>
<li id="15" onclick="pagelim($(this).index())">15</li>
</ul>
</span>
</div>
<div class="pagination">
<?php
if( $pages > 1)
{
$range=1;
$showitems = ($range * 2)+1;
$page1=$page;
$prev=$page1-1;
if($page > 1)
{
echo "<a class=\"page gradient\" ";
echo "href=\"?{$querystring}page=$prev";
echo "\">Previous</a> ";
}
for ($i = 1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems ))
{
if($i == $page)
{
echo "<span class=\" page active\">".$i."</span>";
}
else
{
echo "<a class=\"page gradient\"";
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
}
}
if($page!=$pages)
{
if($showitems < $pages)
{
echo "..... ";
}
$page1=$page;
$next=$page1+1;
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$next";
echo "\">Next</a> ";
}
}
?>
</div>
</div>
<?php
$tim_path = get_bloginfo('template_directory')."/scripts/timthumb.php?src=";
if(count($data)>0)
{
foreach($data as $row)
{
$userid = $row->dealer_id;
$metakey="addr1";
$prod_id = $row->product_id;
$image=$wpdb->get_results("select DISTINCT(product_id),prod_image from wp_product_images where product_id=$prod_id LIMIT 1");
foreach($image as $row1)
{
$image_name = $row1->prod_image;
}
?>
<?php $location=get_usermeta( $userid, $metakey ); ?>
<ul class="product-wrap" id="product-wrap">
<li><a href="#" class="current details-link" ><img src="<?php _e($tim_path) ?><?php bloginfo('template_directory');?>/product_images/<?php _e($image_name."&w=140&h=105&zc=0&watermark=0") ?>" class="thumb" alt=""/>
<?php if($row->bestdeal==1)
{?>
<span class="best-deal-icon right100" ></span> <?php }?>
</a>
<div class="product-title clearfix">
<h3 class="textBold"><?php _e($row->product_name) ?></h3>
<span class="product-price bTextColor"><?php _e($row->price)?></span> </div>
<div class="tech-details"> <span class="span1">Technical details : </span> <span class="span2"><?php _e($row->rim) ?>"</span> <span
class="span3"><?php _e($row->studs) ?>Studs</span> <span class="span4"><?php _e($row->colour) ?></span>
<span class="span5"><?php _e($row->miles) ?>Mil</span> </div>
<div class="location-details" style=""> <span class="location-display">Location : <?php _e($location) ?> </span> <span
class="view-details">View details </span> </div>
</li>
</ul>
<?php }
}
else
{
echo '<div class="no_records">Sorry!!No Products Found You Can Search Another. </div>';
}
?>
<!--/ .adjective-->
<div id="pagination-sort-lniks">
<div class="pagination">
<?php
if( $pages > 1)
{
$range=1;
$showitems = ($range * 2)+1;
$page1=$page;
$prev=$page1-1;
if($page > 1)
{
echo "<a class=\"page gradient\" ";
echo "href=\"?{$querystring}page=$prev";
echo "\">Previous</a> ";
}
for ($i = 1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems ))
{
if($i == $page)
{
echo "<span class=\" page active\">".$i."</span>";
}
else
{
echo "<a class=\"page gradient\"";
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
}
}
if($page!=$pages)
{
if($showitems < $pages)
{
echo "..... ";
}
$page1=$page;
$next=$page1+1;
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$next";
echo "\">Next</a> ";
}
}
?>
</div>
</div>
</section>
</div>
</div>
<!--/ .main-->
<?php get_footer();?>
With Jquery/Ajax the execution flow is different, let me try to explain:
PHP is executed on the server, after the execution the result is pure HTML+CSS+javascript. This result is then send to the client, where the browser will display it.
So what you are doing here is calling the same PHP multiple times, and depending of the variables you pass to it you generate diferent HTML+CSS+javascript results.
So how would this work if we add Jquery/Ajax?
You would call your PHP once, the result generated HAS to contain the Jquery/Ajax code in the head tag. (you need the jquery JS file added as a script tag). When the user decides to do a sort you don't call the entire PHP script again. You should call a second PHP script, dedicated to only return the HTML part you want to refresh. Here's a example:
$.post("returnhtml.php", {var1: var1, var2: var2}, function(data){
// the var data contains everything "returnhtml.php" echoed
$("#div_we_want_to_refresh_id").html(data);
});
Hope this helped.
My client would prefer a currency drop-down list to the currency icon block installed on a 1.5.1 OpenCart theme. I've tried coding it but get the following error:
Parse error: syntax error, unexpected T_STRING, expecting ';' in /...file path......
I've pasted the code and used before and after the offending line.
<?php
$a = 0;
foreach ($currencies as $currency) {
$thisCurTitle[$a] = $currency['title'];
$thisCurCode[$a] = $currency['code'];
if ($currency['symbol_left']) {
$thisCurSymb[$a] = $currency['symbol_left'];
} else {
$thisCurSymb[$a] = $currency['symbol_right'];
}
$a++;
}
?>
<select name=”curselect” onchange=”$(‘input[name=\'currency_code\']‘).attr(‘value’, this.options[this.selectedIndex].value).submit(); $(this).parent().parent().submit();”>
***<?php for ($z = 0; $z <= $a – 1; $z++) { ?>***
<?php if ($thisCurCode[$z] == $currency_code) { ?>
<option value=”<?php echo $thisCurCode[$z]; ?>” selected><?php echo $thisCurTitle[$z]; ?> <?php echo $thisCurSymb[$z]; ?></option>
<?php } else { ?>
<option value=”<?php echo $thisCurCode[$z]; ?>”><?php echo $thisCurTitle[$z]; ?> <?php echo $thisCurSymb[$z]; ?></option>
<?php } ?>
<?php } ?>
Any help would be most appreciated.
$a – 1 contains something like an m-dash, or whatever it's called. Not a - minus sign. This most likely happened because you copy-pasted code that had been through an auto-formatter like some mail programs or word processors.
after 2 hours of work here is my solution
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" name="formcur" id="formcur">
<div id="currency">
<?php echo $text_currency; ?>
<?php
$a = 0;
foreach ($currencies as $currency) {
$thisCurTitle[$a] = $currency['title'];
$thisCurCode[$a] = $currency['code'];
if ($currency['symbol_left']) {
$thisCurSymb[$a] = $currency['symbol_left'];
} else {
$thisCurSymb[$a] = $currency['symbol_right'];
}
$a++;
}
?>
<select name="curselect" id="curselect" onchange="$('input[name=\'currency_code\']').attr('value', document.getElementById('curselect').value); document.forms['formcur'].submit();">
<?php
for ($z = 0; $z <= $a - 1; $z++) {
if ($thisCurCode[$z] == $currency_code) { ?>
<option value="<?php echo $thisCurCode[$z]; ?>" selected><?php echo $thisCurTitle[$z]; ?> <?php echo $thisCurSymb[$z]; ?></option>
<?php
} else {
?>
<option value="<?php echo $thisCurCode[$z]; ?>"><?php echo $thisCurTitle[$z]; ?> <?php echo $thisCurSymb[$z]; ?></option>
<?php } ?>
<?php } ?>
</select>
<input type="hidden" name="currency_code" value="" />
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
</div>
</form>
I think your problem is that the value returned in your if block is a String?
if ($currency['symbol_left']) {
Had to clean up your code to be able to make any sense of it. You had a load of odd ` chars stick to " and ' and try to keep inside PHP as much as possible.... this is not an answer yet.... I suggest you upload this and identify to us exaclty which line is at fault, I suspect its in the first echo
<?php
$a = 0;
foreach ($currencies as $currency)
{
$thisCurTitle[$a] = $currency['title'];
$thisCurCode[$a] = $currency['code'];
if ($currency['symbol_left'])
{
$thisCurSymb[$a] = $currency['symbol_left'];
}
else
{
$thisCurSymb[$a] = $currency['symbol_right'];
}
$a++;
}
echo "<select name='curselect' onchange='$('input[name=\'currency_code\']').attr('value’, this.options[this.selectedIndex].value).submit(); $(this).parent().parent().submit();'>";
for ($z = 0; $z <= $a – 1; $z++)
{
if ($thisCurCode[$z] == $currency_code)
{
echo "<option value='".$thisCurCode[$z]."' selected>".$thisCurTitle[$z]." ".$thisCurSymb[$z]."</option>";
}
else
{
echo "<option value='".$thisCurCode[$z]."'>".$thisCurTitle[$z]." & nbsp;".$thisCurSymb[$z]."</option>";
}
}
?>
found the problem.....
You have placed a calculation inside the for() statement...
$a =10; // this is to mimic your counter
$a=$a-1; // do you subtract here
//for ($z = 0; $z <= $a – 1; $z++) // this is the issue.
//for ($z = 0; $z <= ($a – 1); $z++) // doesn't work either.
for($z=0; $z <= $a; $z++)
{
echo $z." hello</br />";
}
http://php.net/manual/en/control-structures.for.php
cant see any reason why you wouldnt be able to do it the way you tried, my PHP errors in the same way, even encapsulating the subtract in ()... fixes the issue but still bothers me. Rarely use for()...
I hope that fixes your trouble!
I have a code:
<?php for ($i = 0; $i < sizeof($categories); $i = $i + 4) { ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
<?php if (isset($categories[$j])) { ?>
<img src="<?php echo $categories[$j]['thumb']; ?>" title="<?php echo $categories[$j]['name']; ?>" alt="<?php echo $categories[$j]['name']; ?>" style="margin-bottom: 3px;" /><br />
<?php echo $categories[$j]['name']; ?>
<?php } ?>
<?php } ?>
<?php } ?>
I want to place these categories in 2-column like this:
<div class="span-8">
<div class="product">
product1
</div>
</div>
<div class="span-8 last">
<div class="product">
product2
</div>
</div>
How can I do this?
<?php
for ($i = 0; $i < sizeof($categories); $i = $i + 4) {
for ($j = $i; $j < ($i + 4); $j++) {
if (isset($categories[$j])) {
if($colcount % 2){
$col1+="<div class='product'><a href='".$categories[$j]['href']."'><img src='".$categories[$j]['thumb']."' title='".$categories[$j]['name']."' alt='".$categories[$j]['name']."' style='margin-bottom: 3px;' /></a></div><a href='".$categories[$j]['href']."'>".$categories[$j]['name']."</a>";
}else{
$col2+="<div class='product'><a href='".$categories[$j]['href']."'><img src='".$categories[$j]['thumb']."' title='".$categories[$j]['name']."' alt='".$categories[$j]['name']."' style='margin-bottom: 3px;' /></a></div><a href='".$categories[$j]['href']."'>".$categories[$j]['name']."</a>";
}
$colcount++;
}
}
}
echo "<div class='span-8'>".$col1."</div><div class='span-8 last'>".$col2."</div>";
Or you could do it the easy way and make it a fluid <ul> that way they would do it automatically
I don't really see the correlation between the php and the html code, but I think you just need to output a different css class for each odd category:
$last = false;
foreach($categories as $c) {
//Output category html
?>
<div class="span <?=($last)?'last':''?>">.....</div>
<?
$last != $last;
}