I am trying to make a link with PHP and I am not sure what is wrong with this code.
$product_list .= "\n\r " . 'Ticket Download: ' . ": " . <a href=$single_link["url"]>($single_link['name'])</a> . "\n\r";
I know the issue is with the link (meaning between the opening and closing html tags). What am I doing wrong?
Edit: I have tried using the code you have all provided, and I still can't get it to work. I am not sure why.
$product_list .= PHP_EOL . 'Ticket Download: ' . $single_link['name'] . '' . PHP_EOL;
You should include the anchor tags in the string
$product_list .= "\n\r " . 'Ticket Download: ' . ": <a href={$single_link['url']}>({$single_link['name']})</a> \n\r";
You are not opening and closing quotes in the right places. You can use this:
$product_list .= "\n\r Ticket Download: : ('. $single_link['name'] . ")\n\r";
There are a bunch of other ways to do it too. No doubt someone else will have a more elegant answer. But that's a quick first-pass cleanup of your code to get it working.
Adding quotes around the data in the href will also help.
$product_list .= "\n\r " . 'Ticket Download: ' . ": " . <a href='{$single_link["url"]}'>($single_link['name'])</a> . "\n\r";
There's a much easier to read syntax for this which uses curly braces instead of string concatenation:
$product_list .= "\n\r Ticket Download: <a href={$single_link['url']}>({$single_link['name']})</a>\n\r";
Related
I have a custom field called code on Accounts module and I want to enable it on the Global Search such that its searches without wildcards entered in the search bar.
So suppose I have some records with values like "88990","23477" and "12347".
If some one uses global search and enters 347 it should return me the account with code 23477 and 12347.
I dont want to enter %347 yo the the results.
How can I achieve this?
I have code on
custom/Extension/modules/Account/Ext/Vardefs/sugarfield_code_c.php
$dictionary['Account']['fields']['code_c']['inline_edit']='1';
$dictionary['Account']['fields']['code_c']['labelValue']='test code';
$dictionary['Account']['fields']['code_c']['unified_search']=true;
and on custom/modules/Accounts/SearchFields.php I have
$searchFields['Accounts'] = array(
'code_c' =>
array(
'query_type' => 'default'
)
);
SuiteCRM Version: 7.10.4
Solution is NOT upgrade safe.
Navigate to include/SearchForm/SearchForm2.php and look for the following inside the generateSearchWhere() function:
$where .= $this->seed->db->concat($concat_table, $concat_fields) . " LIKE " . $this->seed->db->quoted($field_value . $like_char);
$where .= ' OR ' . $this->seed->db->concat($concat_table, array_reverse($concat_fields)) . " LIKE " . $this->seed->db->quoted($field_value . $like_char);
I changed this line to concatenate the $like_char variable before $field_value:
$where .= $this->seed->db->concat($concat_table, $concat_fields) . " LIKE " . $this->seed->db->quoted($like_char . $field_value . $like_char);
$where .= ' OR ' . $this->seed->db->concat($concat_table, array_reverse($concat_fields)) . " LIKE " . $this->seed->db->quoted($like_char . $field_value . $like_char);
I use Microdata attributes in HTML code.
How can I add Microdata attributes to the following tag (PHP)?
if (!empty($speciality)) {
echo "<p><strong>" . __('Speciality', 'framework') . "</strong><span>" . $speciality . "</span></p>";}
The page will not load when I enter the following way :
echo "<p itemscope itemtype="https://schema.org/medicalSpecialty"><strong>" . __('Speciality', 'framework') . "</strong><span itemprop="medicalSpecialty" >" . $speciality . "</span></p>";
you are using double quotes in a double quotes which is wrong, use backslash or single quote when you need.
Try This code
echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>" . __('Speciality', 'framework') . "</strong><span itemprop='medicalSpecialty' >" . $speciality . "</span></p>";
You're mixing single and double quotes but you need to reserve either single or double quotes to escape the string so that your PHP isn't read as HTML when echoed. The below snippet will work without any errors:
if (!empty($speciality)) {
echo "<p itemscope itemtype='https://schema.org/medicalSpecialty'><strong>'".
__('Speciality', 'framework') . "'</strong><span itemprop='medicalSpecialty'
>'" . $speciality . "'</span></p>";
}
This appears right to me but it is incorrect (code hint coloring around '{$row["type"]}' is wrong wrong -- from the color it is in my IDE it's been considering a string, and it's throwing an error when i run it in the browser). I've spent hours trying to figure this out on my own to no avail. Any help would be greatly appreciated.
echo "<select selected = '{$row["type"]}' name='expense[" . $id . "][type]' >" . $type_options . "</select>";
When using arrays in strings, you can't use quotes. Just skip them.
echo "<select selected = '{$row[type]}' name='expense[" . $id . "][type]' >" . $type_options . "</select>";
Your quotes arren't right.
echo '<select selected ="'.$row["type"].'" name="expense['.$id.'][type]">'.$type_options.'</select>';
You currently have a problem with unescaped double quotes terminating your string. My suggestion would be to use the more standard double-quotes for your HTML element properties, and use single quotes to delineate your strings, with variable concatenated. Liek this:
echo '<select selected = "' . {$row["type"]} . '" name="expense[' . $id . '][type]">' . $type_options . '</select>';
or for even better readability, use printf
$format = '<select selected = "%s" name="expense[%d][type]">%s</select>';
printf($format, $row['type'], $id, $type_options);
$type_options = "options";
echo $type_options;
Have you not tried this?
echo "This works: {$row['type']}";
Your code wont work because you have an empty string before you echo your variable.
echo "#EMPTY STRING HERE!" . $type_options . "#EMPTY STRING HERE!";
Why are you doing that?
Use this
echo $type_options;
Or even this if you want content in your string
echo "Content" . $type_options . "Content";
This is my PHP/MySQL script:
<?php
mysql_connect('localhost', 'root', 'test') or die (mysql_error());
mysql_select_db('info1') or die (mysql_error());
$result = mysql_query("SELECT * from automobiles");
//Table starting tag and header cells
while($row = mysql_fetch_array($result)){
//Display the results in different cells
echo "<dd><dl><img src=' " . $row['image'] . " '>" . $row['manufacturer'] ." " . $row['model'] . "</dd></dl>";
echo "<dd><dl>" . $row['carinfo'] . "</dd></dl>";
}
//Table closing tag
echo "</table>";
?>
However, would it work if I did it this way:
{$myvariable}
Is it a good idea to code the variables with the braces, or as:
echo " . $row['variable']. "
Any help is appreciated, thanks!
You can do this:
echo "<dd><dl>{$row['carinfo']}</dd></dl>";
You cannot do this:
echo "<dd><dl>$row['carinfo']</dd></dl>";
This also wont work:
echo '<dd><dl>{$row['carinfo']}</dd></dl>';
Your output would actually be:
<dd><dl>{$row[ SOME PHP ERROR
This is due to using single quotes instead of double quotes. And the error would be because you did not escape the single quotes inside the variable.
If you did this:
echo '<dd><dl>{$row["carinfo"]}</dd></dl>';
Your output would actually be:
<dd><dl>{$row["carinfo"]}</dd></dl>
For the same single quote vs double quote reasoning.
I personally prefer using the " " . $row['variable']. " " syntax because it's easier to read code, specially if you have a code syntax highlighter. But using this syntax is acceptable: "{$var['field']}".
I am using fusion maps in one of my application.
In one of the example i have to pass the value from one map to another charts,
I am facing one problem if the data passed is numeric its displaying alert message correctly but if it is a string it generates an error:
NM is not defined
javascript:alert(NM)()
My code is as below:
$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] / $sumdata) * 100),2) . "' link='javascript:alert(".($rs1['Internal_Id']) . ")' />";
If i change the link part (passing single quotes in alert)that is:
$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] / $sumdata) * 100),2) . "' link='javascript:alert('".($rs1['Internal_Id']) . "')' />";
It displays invalid xml data.
Please help me on this
Thanks
Pankaj
Use \" rather than ' to surround the JavaScript string.
$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] / $sumdata) * 100),2) . "' link='javascript:alert(\"".($rs1['Internal_Id']) . "\")' />";
What is happening is that the xml produced is like so:
<entity id='NM' value='1' link='javascript:alert('NM')'/>
Which as you should be able to see from SOs syntax highlighting ends the value for the link attribute after javascript:alert(' as you are using the same quotes for the javascript as you are using for surrounding the attribute values.
Using a different quote (" rather than ') doesn't end the attribute value (again see the syntax highlighting)
<entity id='NM' value='1' link='javascript:alert("NM")'/>
In PHP we have to escape the quote (Using \) so it isn't interpreted as a special character by the php interpreter and used to end the string, which is why in php you have to write \"
You should change your
ink='javascript:alert('".($rs1['Internal_Id']) . "')'
by
ink='javascript:alert(\"".($rs1['Internal_Id']) . "\")'
Try:
$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] / $sumdata) * 100),2) . "' link='javascript:alert(\"".($rs1['Internal_Id']) . "\")' />";
Basically escaping your alert quotation marks :)