OK, i have a function that compares values and returns the results, regardless of case, ie: Interfacility Transfer = INTERFACILITY TRANSFER here is the function:
function fncResult ($expVal, $actVal)
{
$negNulls=array("-5","-10","-15","-20","-25");
if (!in_array($expVal, $negNulls))
{
if(strtolower($expVal)==strtolower($actVal))
{
echo "
<td class='match' title='The values match.'>Match</td>
</tr>";
}
else
{
echo "
<td class='notMatch' title='The values do not match.'>Not Match<br />No Match</td>
</tr>";
}
}
else
{
echo "
<td class='null' title='The value in the XML was a negative null.'>Negative Null</td>
</tr>";
}
}
It works about 99% of the time except when it comes to this:
//--Type of service requested
echo "
<tr>
<td>E02_04</td>
<td>Type of Service Requested</td>
<td>36. <Nature of Call></td>
<td>$fldServReq</td>
<td>".fncGrabNemsis("E02_04",$fldServReq,$local)."</td>
<td>".fncIsSet($CZ_E02_04[1])."</td>";
fncResult(fncGrabNemsis("E02_04",$fldServReq,$local),fncIsSet($CZ_E02_04[1]));
Although it looks more complicated, it really is just a strtolower($expVal)==strtolower($actVal), comparison. When I echo the values being compared, I get: "interfacility transfer" and "interfacility transfer" and "No Match"... WTF? Could it be because the first value is coming from a XML (UTF-8) and the second is from a DB (?) I have no idea what to do and am incredibly frustrated since this a simple task. Thanks for any help!
Is there any trailing whitespace on your strings? Perhaps nesting a trim() along with a strtolower() would clear that up? If you're looking at this in HTML output, take a look at the source and make sure there's not an HTML entity in there messing it up (i.e. "interfacility transfer" and "interfacility transfer" are not the same, but may look the same rendered in HTML).
The final option is to "upgrade" to the mb_strtolower and see if it is an encoding issue.
Print out the bytes of expval and actval (with urlencode, for example). There are a lot of different characters that look exactly the same (for example, normal space and non-breaking space, or c, es and roman 100).
Related
Trying to display the results of my post array. For line
print "<tr><td>$prodqty</td>......"
I need my {$gear{prodnum}[1]} to have that last bracket close out the array element. But for some reason the final closing bracket becomes part of my print statement (for anyone familiar with NetBeans, that bracket turns orange instead of black like it's supposed to be) and since I have a few if/else statements, the closing bracket gets moved to further down the lines (particularly after a ; which I don't understand) and I can't figure out how to get that array element to close.
I have tried both {$gear{$prodnum}[1]} and {$gear{$prodnum[1]}} and either way it will not work. I also tried () instead of brackets for $prodnum.
My professor was the one who helped me write that section and it was working until I tried to add more if statements and then it stopped.
if(array_key_exists('submit',$_POST))
{
echo "<table><table align='center'><th colspan='3'>Total</th><tr>
<td>Quantity</td><td>Item</td><td>Extended Price</td></tr>";
foreach($_POST['qty'] as $prodnum=>$prodqty){
if($prodqty>0){
print "<tr><td> $prodqty </td> <td>{$gear{$prodnum}[1]**}**</td>";
print "<td>".($prodqty*$gear{$prodnum}[3])."</td></tr>";
}
};
elseif($prodqty==null)
{;
}
else {
echo "Please enter a quantity.";
}
};
Ideally I would like the prodqty to go after the prodnum, but it would not work that way. Also any suggestions on how to print the results of the $POST that have quantities added, and forgetting those that do not, will be greatly appreciated. I'm trying to write the if statements to require the submitter to enter a number (no letters or words) and leave the other array elements out if they did not enter a quantity for them.
Thank you!
Your if and else placement seemed mis-aligned. Tried to reconstruct your statement to best i think you are trying to achieve
if(array_key_exists('submit',$_POST))
{
echo "<table><table align='center'><th colspan='3'>Total</th><tr>
<td>Quantity</td><td>Item</td><td>Extended Price</td></tr>";
foreach($_POST['qty'] as $prodnum=>$prodqty){
if($prodqty>0){
print "<tr><td> $prodqty </td> <td>".$gear[$prodnum][1]."</td>";
print "<td>".($prodqty*$gear[$prodnum][3])."</td></tr>";
} elseif($prodqty==null)
{
}
};
} else {
echo "Please enter a quantity.";
}
So I'm setting up a little page for myself to see my online transactions in dogecoin.
I have the RPC server/client connection established and working correctly.
The listtransactions method provides me with the transaction history as an array, which breaks down into its elements. I embed these in a table.
That all works correctly. what I WANT is to take the transaction ID and make it linkable to the dogecoin blockchain record.
Here is the code, and then I will note which lines have the issue:
for($i=count($json)-1; $i>=0; $i--){
echo '<tr>';
echo '<td>'.$json[$i]['address'].'</td>'."\n";
//echo '<td>'.$json[$i]['category'].'</td>'."\n";
echo '<td>'.$json[$i]['amount'].'</td>'."\n";
//echo '<td>'.$json[$i]['confirmations'].'</td>'."\n";
echo '<td>'."<a href='https://dogechain.info/tx/$json[$i]['txid']'>".$json[$i]
['txid'].'</a> </td>'."\n";
echo '</tr>';
}
echo '</table></center>';
?>
The line containing the hyperlink is where it screws up. You can see how it is displaying at http://www.suchco.in/
an example link it gives me is: https://dogechain.info/tx/Array%5B
what it should be is: https://dogechain.info/tx/ fab3b949cb3a71e79fa6b631d5d16aa7268b77dc3626e2fb2e711f1b43adc08d
how can I make this happen?
Put { } around your array variables in a string.
Try:
{$json[$i]['txid']}
Instead of:
$json[$i]['txid']
OR
Do string concatenation
echo '<td>'."<a href='https://dogechain.info/tx/".$json[$i]['txid']."'>"
I've really been racking my brain with this. I'll try to explain it to the best of my ability. It is mainly a data entry form.
First, there are three variables to start with. One is an array of regions (NYC, DC, etc) and the other to is a starting date (ex: 01/01/2012) and an ending date (ex: 1/15/2012)
In previous pages, the user selected the number of regions, selected the starting date to start recording, and the ending date. The intent is to enter 'points' and the dates are basically by week.
This is what the form is supposed to look like: http://i.imgur.com/9XflP2Z.png
In the boxes aside from the first column and first row, they are all input boxes. So, each input box is associated with the value at each end of the table (for example, the box next to NYC and under 01/01/2012 would enter data for NYC in the date range from 01/01/2012 to 01/08/2012).
My question is: How do I go about building this? Should I use a big 2d array? How would the submit button know which input boxes correspond to which date/region? My initial thought is maybe a hidden value that's like $array[0][x], $array[x][0], but I'm not sure.
I'm not really good at explaining, so I apologize in advance if anyone can't understand what I'm asking.
Try this:
// hard coding these values for example
// but for OP's case these might be coming from a previous page
$date_array = Array("01/01/2012", "01/08/2012", "01/15/2012");
$region_array = Array("NYC", "DC");
Now generate that form/table in your image like this:
<form name="test_form" id="test_form" action="submit_form.php" method="POST">
<table border="1">
<tr>
<td></td>
<?php
foreach ($date_array as $date){
echo "<td>".$date."</td>";
}
?>
</tr>
<?php
foreach ($region_array as $region){
echo "<tr>";
echo "<td>".$region."</td>";
foreach ($date_array as $date){
echo "<td><input type=\"text\" name=\"".$region."_".$date."\"></td>";
}
echo "</tr>";
}
?>
</table>
<input type="submit" name="submit">
</form>
now for submit_form.php:
if (isset($_POST['submit'])){
foreach ($_POST as $k=>$v){
if ($k != "submit"){
// split the form input on _
$input = explode("_", $k);
echo "<BR>City: " . $input[0];
echo "<BR>Date: " . $input[1];
echo "<BR>Value: " . $v;
}
}
}
This is a variant on a commonly asked question.
In principle the foreach statement is perhaps the best option. pseudocode:
Collate all possible date ranges into a single array (array_merge, array_unique, array_sort) to generate your headers
foreach($region as $dates)
{
display the button for $date['startdate'] if is in_array of dates;
display the button for $date['enddate'] if is in_array of dates;
repeat...
}
The big problem you are going to have is dealing with the layout. The obvious solution (at the risk of ire hereon) is to use an HTML table. This is simple and automatically adjusts itself.
$nextline="<TR>";
if(is in_array($datetotest,$listofdates))
{
$nextline.="<TD><CODE FOR BUTTON></TD>";
}
else
{
$nextline.="<TD><BR></TD>";
}
Your alternative (and probably slicker) solution is to enclose all your buttons in a suitable span or other tag and neatly arrange them using CSS. This gives you more layout options but can be a bit of a headache with arbitrarily large datasets.
An SQL query gives no output through AJAX page when variables are passed in the query. Even the count of number of rows gives zero (0). An echo of the same query with the passed variables shows as having values.
When copy and pasting the same (replacing) from the browser page to the query in the AJAX page it gives a result.
The code is as follows (first SQL code in AJAX page with variables as parameter):
$qu="SELECT DISTINCT bk.bookname,bk.author,bk.publisher,bk.edition,bk.description,lam.article_name,bk.keywords,bk.qtyinstock FROM lib_article_master lam, lib_book_cd_master bk WHERE bk.bookname='$arr[2]' AND bk.author='$arr[3]' AND bk.publisher='$arr[4]' AND bk.article_id=lam.article_id";//here $arr[2],$arr[3],$arr[4] are variables from another query for comparison in AJAX page
$r=QrySelect($qu);
echo " <br> ".$qu;//query is echoed in browser
echo "<br>count : ".mysql_num_rows($r);//count of number of rows
$arr1=mysql_fetch_array($r);
?>
<table width="97%" border="0" >
<tr
<td width="11%"><div align="left"><strong>Description </strong></div></td>
</tr>
</table>
<textarea name="txt_Keywords" style="width:90%; height:90px"><?php echo $arr1[4]; ?></textarea>
And the output is nothing.
The query, when taken from the browser and put back in code along with values for variables we are getting an output.
$qu="SELECT DISTINCT bk.bookname,bk.author,bk.publisher,bk.edition,bk.description,lam.article_name,bk.keywords,bk.qtyinstock FROM lib_article_master lam, lib_book_cd_master bk WHERE bk.bookname='Java Complete Reference' AND bk.author='Martin D Leuthen' AND bk.publisher='ABS Publications' AND bk.article_id=lam.article_id";//here $arr[2],$arr[3],$arr[4] are replaced as per browser output
$r=QrySelect($qu);
echo " <br> ".$qu;//query is echoed in browser
echo "<br>count : ".mysql_num_rows($r);//count of number of rows
$arr1=mysql_fetch_array($r);
?>
<table width="97%" border="0" >
<tr
<td width="11%"><div align="left"><strong>Description </strong></div></td>
</tr>
</table>
<textarea name="txt_Keywords" style="width:90%; height:90px"><?php echo $arr1[4]; ?></textarea>
We are getting an output for the above code with correct number of rows from the the database.
Any help will be great.
You should use string concatenation to build your query, like
"SELECT * FROM table WHERE param = '" . $value . "'"
So, your query should look like:
$qu="SELECT DISTINCT bk.bookname,bk.author,bk.publisher,bk.edition,bk.description,lam.article_name,bk.keywords,bk.qtyinstock FROM lib_article_master lam, lib_book_cd_master bk WHERE bk.bookname='".$arr[2]."' AND bk.author='".$arr[3]."' AND bk.publisher='".$arr[4]."' AND bk.article_id=lam.article_id";
Also, don't forget to escape string variables with mysql_real_escape_string().
Got it at last... PHEW...
Just include 'TRIM()' and comparison problem got solved .Don't know still how it managed to work when code was pasted from browser but anyways its working.
giving the code below ...
$fr0=trim($arr[0], "");//'TRIMS' ALL UNWANTED SPACES FOR COMPARISON TO BE PERFECT
$fr1=trim($arr[1], "");
$fr2=trim($arr[2], "");
$fr3=trim($arr[3], "");
$bkr0=strtolower($fr0);//HERE EVERY SINGLE CHARCTER IS TURNED TO 'LOWER CASE' TO REMOVE ALL POSSIBLE WAYS OF ERRORS IN COMPARISON
$bkr1=strtolower($fr1);
$bkr2=strtolower($fr2);
$bkr3=strtolower($fr3);
//NOW COMPARISON FOR EACH VALUE IS DONE IN A WHILE LOOP BY 'mysql_fetch_row'
thank u all for your effort... it really meant a lot !
I want to allow the user to enter a coupon number in order to get a discount. After the coupon number is entered and submitted, the page reloads withe a tick showing that they have entered a correct amount.
The way I'm trying to do this is displaying the tick if the coupon amount is not £0.00. But the string comparison doesn't seem to work, since it always thinks that it is not £0.00. The code is as follows. The function coupon_amount() returns the coupon amount. coupon_amount() returns "£0.00" (including the pound sign)
<?php $coup_amount = coupon_amount(); ?>
<?php $zero_amount = "£0.00"; ?>
<?php if(strcmp($coup_amount, $zero_amount)== 0) { ?>
<?php echo 'Enter coupon code if applicable:' ?>
<input type='text' class='couponinput' name='coupon_num' id='coupon_num' value='coupons_name' />
<input type='submit' class='update-button' value='submitcoupon' />
<?php } else { ?>
<?php echo 'Thanks.' ?><input type='text' disabled='disabled' class='couponinput' name='coupon_num' id='coupon_num' value='coupons_name' />
<div class='tick'></div>
<?php } ?>
Am I doing something wrong with the comparison?
I followed Oscar's suggestion below, and here is the output. Seems to be an encoding problem. And the pound sign is not appearing properly for the zero_amount.
coup_amount: (£0.00) zero_amount: (�0.00)
coup_len:10 zero_len:5
strcmp: -1
coup_ascii: 38 zero_ascii:163
You should really be storing/working with the discount values as numbers, this would make the comparison much easier.
Have you tried printing out all the values?
<?php $coup_amount = coupon_amount(); ?>
<?php $zero_amount = "£0.00"; ?>
//print'em out
<pre>
<?php
echo "coup_amount: ($coup_amount) zero_amount: ($zero_amount) \n";
echo "coup_len:".strlen($coup_amount)." zero_len:".strlen($zero_amount)."\n";
echo "strcmp: ".strcmp($coup_amount, $zero_amount)."\n";
echo "coup_ascii: ".ord($coup_amount[0])." zero_ascii:".ord($zero_amount[0]);
?>
</pre>
Amendment
So yes, now that we can see the output from this, it seems like the coup-string is an UTF16 (10 bytes long) and the other is something else (5 bytes long).
(Preaching follows.) When dealing with money you should really take extra care to make sure numbers are handled correctly. We've just seen that strings are subject to encoding, and like others have pointed out, floats are subject to fractional errors. Your best bet is probably to try and express it in 1/100s using an integer, and to express the currency in a separate variable. (Preaching over.)
But I'm guessing the coupon_amount-function is used everywhere and you can't change it. Then you might wanna look into converting the two strings so that the are in the same format. Take a look at iconv.
<?php if(strcmp($coup_amount, $zero_amount)== 0) { ?>
Seems very unreadable compared to:
<?php if(coupon_amount() == 0) { ?>
If coupon_amount() returned the actual value, not the formatted string representation.
Are you able to change the coupon_amount() function to get rid of the pound symbol? the php function money_format is good for adding whatever the users currency symbol is to a string for displaying on the page (or which ever symbol you set the locale to)
In the future you will find yourself having to remove the pound symbol first before you do any arithmetic on the return value from coupon_amount()
There are a lot of things that seem insignificant to user, but may break string comparison
coupon_amount() may insert some spaces somewhere in returned value
coupon_amount() may return variable number of zeros
coupon_amount() may use comma instead of dot (depending on locale)
coupon_amount() may encode pound sign using some HTML entity
Said that, it is much better to compare numeric values, and then format number as currency.
the strcmp call seems ok, my bet is on the coupon_amount function.
The absurd lengths I had to go to to get this working :) .. I changed the first if statment to:
if((ord($coup_amount[0])==38) && (ord($coup_amount[1])==35)
&& (ord($coup_amount[2])==49) && (ord($coup_amount[3])==54)
&& (ord($coup_amount[4])==51) && (ord($coup_amount[5])==59)
&& (ord($coup_amount[6])==48) && (ord($coup_amount[7])==46)
&& (ord($coup_amount[8])==48) && (ord($coup_amount[9])==48)
&& (ord($coup_amount[10])==0))
have you triend comparing it without a pound sign?..
like this
substr($coup_amount, 1) == "0.00";
i see you're having problem when retrieving the pound sign so i think it is best to try this.