hello i have a little bit problem i am working on php4 and apache 1.1
<?php
$something="first second";
echo '<input type="checkbox" name="standard[]" value='.$something.'>first second<br>';
?>
Result:
first
and if
<?php
echo '<input type="checkbox" name="standard[]" value="first second">first second<br>';
?>
Result:
first second
i want my code is like the first one but the result is in second one, how? thanks
do something like that
echo '<input type="checkbox" name="standard[]" value="'.$something.'">'.$something.'<br>';
one way to debugg such things is to check what is their output like view on source or inspect elements
What is the difference between single-quoted and double-quoted strings in PHP? about ' and "
Related
Hy all I have this code this is printing the array in the result but not getting value in the selectin dropdown I want to get the nextgen gallery names from the database! Tell me where I am wrong
<select>
<?php
foreach($gallerylist as $galleryrow) {?>
<?php echo $galleryrow; ?>
<option value="<?php echo $galleryrow; ?>"><?php echo $galleryrow; ?></option>
<?php}
?>
</select>
global $wpdb;
$gallerydefine= $wpdb->prefix."ngg_gallery";
$query="SELECT * FROM $gallerydefine";
$gallerylist = $wpdb->get_results($query);
Try to read your code as a book:
First, you're trying to print a list of galleries (which you don't have, it's an undefined variable) as a selectbox:
<select>
<?php
foreach($gallerylist as $galleryrow) { ?>
<?php echo $galleryrow; ?>
<option value="<?php echo $galleryrow; ?>"><?php echo $galleryrow; ?></option>
<?php } ?>
</select>
After that, you're loading the list of galleries from the database, but you're not using it for anything, you just load it and then the script ends:
global $wpdb;
$gallerydefine= $wpdb->prefix."ngg_gallery";
$query="SELECT * FROM $gallerydefine";
$gallerylist = $wpdb->get_results($query);
Obviously, it doesn't make any sense. It's like having a lunch where you first "eat it" (even though you don't have it) and then you go buy ingredients, cook it and go sleep without actually eating it.
Just think about what you're doing it put everything in the right order.
Important notes
enable reporting and displaying of all errors including warnings and notices on your local development environment. If you would have it enabled, you know immediately you're doing something wrong: it would tell you you're using an undefined variable $gallerylist inside the foreach loop.
Also, it's a good idea to check if there hasn't been any database error right after you make a database query.
Always check what HTML code is your script generating. You may see just a blank web page but there may be a lot of HTML code behind that. You're for example printing text between HTML tags <select> and <option> which is not valid.
And use a debugger and go through your script step by step. You'll understand in what order the statements are being executed, what values variables contain in a particular point in the time, etc.
Your code is out of order. Change it to:
<?php
global $wpdb;
$gallerydefine = $wpdb->prefix."ngg_gallery";
$query="SELECT * FROM {$gallerydefine}";
$gallerylist = $wpdb->get_results($query);
?>
<select>
<?php
foreach($gallerylist as $galleryrow) {?>
<option value="<?php echo $galleryrow->gid; ?>"><?php echo $galleryrow->name; ?></option>
<?php}
?>
</select>
This line currently triggers an error because probably there is nothing after the second =.
What value should return from php to tell filterSubject that is empty.
ng-init="filterSubject="
In some cases filterSubject= gets populated with an id from the query string like ?subject=11
but what do I have to pass from php when the query string is not present
Thank you
Since it looks like you're generating the string in PHP, put single quotes around the filter subject:
ng-init="filterSubject='$subject'"
you can use ternary operator something like this
ng-init="filterSubject = YOUR_EXPRESSION || ''"
You can do something like this :-
<div <?php if($_GET['subject']){ ?>ng-init="filterSubject='<?php echo $_GET['subject']; ?>'" <?php }?>>
.....
</div>
or
<?php
if($_GET['subject']){
$nginit = 'ng-init="filterSubject=\''.$_GET['subject'].'\'"';
}
?>
<div <?php echo $nginit;?>>
.....
</div>
I am new to php (at 60 years old I am converting from years of VBScript and ASP) and having difficulties with form handling. I have searched this and many other forums for a solution and cannot find one. I am trying to delete a record using input from a form;
My form code ($row[0] is the field ID, which auto increments and in this instance has a value of 3):-
<form action="<?=$_SERVER[ 'PHP_SELF' ] ?>" method="post">
<input type="hidden" name="id" value="<?php echo $row[0]?>">
<input type="submit" value="Delete"></form>
The handling page then runs without producing any errors, but the record is not deleted, so I tested the input value on the handling page and the reason appears to be because the value of the variable "id" is not getting through.
I tested the input value on the form page with:
echo $row[0]
and it definitely outputs the integer 3.
The problem manifests on the handling page, and my code for checking that I have received the form input is:
$id = (INT)$_post['id'];
echo 'Form input= ', $_post['id'], '<br>';
echo '$id= ', $id, '<br>';
which displays a blank space for the form input line
and 0 as the value for $id, when both should display the number 3
Can anyone tell me why the value for "id" is not getting sent to the handling page?
I expect the answer is simple but I cannot grasp it.
I hope I have explained the problem satisfactorily but if not, please let me know.
Try this:
$id = (int) $_POST['id'];
echo 'Form input= ' . $_POST['id'] . '<br>';
echo 'id= ' . $id . '<br>';
$_POST is case sensitive in PHP. http://www.php.net/manual/en/reserved.variables.post.php
Strings is concatenated with . not ,
Also '$id= ' would render the value of $id not $id
I'm trying to hide a field and the field label if the value of the field is '0' using the field--field_start_time.tpl.php override method. My template file logic is as follows.
<?php if ($element['#object']->field_start_time != '0')): ?>
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:
</div>
<div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print
$item_attributes[$delta]; ?>><?php print render($item); ?></div>
<?php endif; ?>
This is causing chaos with my node render and is obviously wrong. Any help would be GREATLY appreciated. Thanks.
After starting out with Drupal 4 I continued because the community support was awesome.. However after waiting over a day for no answer on drupal.org nor here on what is really a simple question with really awful documentation, I guess I can conclude those days are over.
following code in node.tpl.php
if ($content['field_start_time']['#items']['0']['value'] == '0') {
hide($content['field_start_time']);
}
I am trying to modify the way CakePHP shows the error message. Below is the generic template that it uses to display errors
<div class="error-message">Please enter at least 3 characters.</div>
I want to style the error like below.
<label class="error">Please enter at least 3 characters.</label>
this did the job. i was missing the text parameter.
<?php echo $this->Form->error('name', null, array('wrap' => 'label', 'class' => 'error')); ?>
echo $this->Form->label("Please enter at least 3 xter",array('class'=>'error');