Trying to call the projects controller and the editproject function and pass an id number. Can anyone tell me why the second line doesn't work? When I echo the value in the first line, it does give me the correct integer as a string
<?php echo $list[0]->id; ?>
<?php echo form_open('projects/editproject/',$list[0]->id ) ;?>
The error I keep getting is "Missing argument 1 for Projects::editproject()" My editproject function is function editproject($id).
I did try:
<?php echo $list[0]->id; ?>
<?php $pdata = (int)$list[0]->id; ?>
<?php echo form_open('projects/editproject/',$pdata ) ;?>
Thinking the call to the controller needed a variable for the data. Same error message as above. THanks for any help.
Did you mean to do this instead ?
<?php echo form_open('projects/editproject/'.$list[0]->id ) ;?>
The second argument of form_open() accepts an associative array of attributes, hence, you're mistakenly passing in the id into the second argument when it needs to be concatenated with the url instead.
Related
I'm trying to get the value of some URL parameters in PHP and can't seem to get [] to detect this in the URL.
This works:
<?php if ($params['sms_banner'] === 'true') { ?><div id="sms-banner-legacy"> SMS Banner </div><?php } ?>
This doesn't work:
<?php if ($params['payday[sms_banner]'] === 'true') { ?><div id="sms-banner-legacy"> Legacy SMS Banner </div><?php } ?>
When I go to http://someurl.com/page?payday[sms_banner]=true it should then show the <div> on the page, but instead it can't pick up the value.
As you are passing array in url, you can get the value of same using
$_GET['payday']['sms_banner']
php translates that syntax to an array key value, try $_GET['payday']['sms_banner'] or params['payday']['sms_banner'] in your case.
My problem is that I need to save a value from the link as a variable which will then do something. Below is my main code for this problem.
<table>
<? foreach ($csv as $row) : ?>
<tr>
<td><? echo $row[0]; ?></td>
</tr>
<? endforeach; ?>
</table>
Basically, it prints the first column from my array $csv. However I want to save the '$row[0]' for each link - depending on which one is clicked.
This happens here:
<?php
if (isset($_GET['GoToProfile'])) {
}
?>
This works. E.g. when something is clicked it prints something. But I cannot find a way to save the values from each link. Depending on which one is clicked. I have tried many different methods online, but none seem to work.
I have even tried:
<? echo $row[0]; ?>
Any help would be greatly appreciated.
Thanks!
Use an ampersand (&) instead of a question mark
<? echo $row[0]; ?>
The ? indicates the beginning of the query string, which is the data sent on a GET request. In most cases it is a collection of name/value pairs, separated with & s.
A simple example of a GET request
http://example.com?first=1&second=fifty
You would get the value of the parameters in PHP with $_GET
$first = $_GET['first'];
$second = $_GET['second'];
To see what the server is receiving, you can use var_dump
var_dump($_GET)
<?php echo form_dropdown('ord_id',$pacc_ord, $value['pac_cod'], 'id="IdPac" onchange="func1(this),func2(this, echo $value['prod_id'];);"')?>
i need to print the value of $value['prod_id'] (number)
in my function arguments. but it doesn't work
how can i solve that?
<?php echo form_dropdown('ord_id',$pacc_ord, $value['pac_cod'], 'id="IdPac" onchange="func1(this),func2(this, '.$value['prod_id'].');"')?>
You don't have to use echo when passing the values as parameters. Just concatenate (using '..') the prod_id into the last parameter.
I have a php function which displays a rating bar with the arguments. I have a variable called itemID inside my php page which holds the unique item number. I need to send this value to my function and also echo command must stay. Is there a way to achieve this?
Here is the code, which does not work. When I try it on the server, it does not show the id of item, it prints the variable name as it is.
<?php echo rating_bar('$as',5) ?>
What I get at html file:
<div id="unit_long$as">
instead of the item id in place of $as.
Single Quotes do not support variable replace,
$as = "test";
echo '$as'; //$as in your end result
echo "$as"; // test in your end result
echo $as; // test in your end result
//For proper use
echo " ".$as." "; // test in your end result
Update for newer PHP versions you should now use Template Syntax
echo "{$as}"
If I get what you are saying, this is what you are asking.
<?php echo rating_bar($itemID,5); ?>
With the limited code you are providing, thats what looks like you are asking.
I'm trying to make update form, that is going to retrieve the data for the specific ID selected, and fill in the form, so its going to be available for updating.
When I click edit on the specific entry (Product in my case), it takes me to the edit_product_view, but states the error "Trying to get property of non-object" for every variable that I use in set_values of the form elements.
Using print_r, I get the correct associative array, so it's passed correctly.
This is excerpt of my edit_product_view.
<h2><?php echo $heading; ?></h2>
<hr>
<table id="newproduct">
<?php echo form_open('products/edit/'.$product->id); ?>
<tr>
<td class="label"><?php echo form_label('Name:');?></td>
<td><?php echo form_input('prodname', set_value('prodname', $product->prodname));?></td>
</tr>
<tr>
<td class="label"><?php echo form_label('Product Type:');?></td>
<td><?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product->ptname_fk));?></td>
</tr>
$product is the array holding all the key-value pairs, but I cannot fill the form for some reason.
Thank you in advance!
To access the elements in the array, use array notation: $product['prodname']
$product->prodname is object notation, which can only be used to access object attributes and methods.
To get the value:
$query = $this->db->query("YOUR QUERY");
Then, for single row from(in controller):
$query1 = $query->row();
$data['product'] = $query1;
In view, you can use your own code (above code)
In my case, I was looping through a series of objects from an XML file, but some of the instances apparently were not objects which was causing the error. Checking if the object was empty before processing it fixed the problem.
In other words, without checking if the object was empty, the script would error out on any empty object with the error as given below.
Trying to get property of non-object
For Example:
if (!empty($this->xml_data->thing1->thing2))
{
foreach ($this->xml_data->thing1->thing2 as $thing)
{
}
}