My aim is to create two columns that grows automatic. The problem is that I want to compare column 1 to column2.
(i.e) if col1 contents > col2 contents add a content to col2 else if col1==col2 add next content to col1 until all unknown contents amount are laid out.
How can I keep track of the contents in the columns so that to compare the two columns?
It would look something like this, instead of numbers the would be characters
if your content is plain text use jquery to do that with two class (col1 and col2):
var co1=$('.col1').val();
var co2=$('.col2').val();
if(co1.length > co2.length)
{
$('.col1').append('some html');
}else if(co1.length <= co2.length){
$('.col2').append('some html');
}
in other case you can do this method too.
Related
We are taking simple math expression as inputs from user and want to evaluate it. Total number of fields are also dynamic. Each field contains the specific css class as per their index. For example, 1st field has css field "col1", 2nd field has "col2" and so on.
Users gives us input in the form of
"col5 = col4 * col3"
We are converting it to
jQuery(".col5").val(jQuery(".col4").val() * jQuery(".col3").val())
using str_replace function. To do so, we need to do loop for total no of fields. (below is php code example)
for($colLoop = 0; $colLoop < $total_cols; $colLoop++){
$formula = str_replace("col$colLoop","parseFloat(jQuery('.col$colLoop input').val())", $formula);
}
This works but we are looking for some proper solution as it's loops unnecessary for all fields. Is it possible using some other methods? Let us know
I have a csv file which contain two columns
first column with Part number and second one is Image Name (Multiple Image for each product and Image Name based on Part Number )
I want to check each Part number with entire second column of Image Name each time as this is not sorted properly and store that image name for that perticuler part number in another csv along with that part number.
Current CSV
PartNumber Image Name
WP35001153 35001153R.jpg
WPW10135901 35001153R_Back.jpg
WPW10184873 W10135901R.jpg
WPW10200900 W10135901R_BACK.jpg
WPW10215493 W10137702R.jpg
WPW10249237 W10137702R_Back.jpg
WPW10258402 W10141364R.jpg
WPW10477076 W10477076R.jpg
WP8194064 W10477076R_Back.jpg
W10479760R.jpg
As above csv Part one WP35001153 have two images in on right side 35001153R.jpg and 35001153R_Back.jpg
Also Part number column and Image Column is not perticulary or properly assigned.
So I want to search Part Number with Image name entrie column and if it matches then store in Image1 Column and more than two times it should be store in next column Image2 like below.
PartNumber Image1 Image2
WP35001153 35001153R.jpg 35001153R_Back.jpg
WPW10135901 W10135901R.jpg W10135901R_BACK.jpg
WPW10200900 W10200900.jpg
Please help to figure it out
Thanks
Seem you need to build a new array, using your first column (of csv), cleaned as a key and add to it all you find related too.
Exemple (not exact code)
$mynewarray = [];
foreach ($mycsv as $line) {
$id = $line['PartNumber'];
if ($id[2] == 'W') {
it's a key, clean to obtain : 35001153
mynewarray[$id] = ['pics'=>[ ... ]];
} else {
it's a pic, add the image name
clean the id image name to obtain the key 35001153
mynewarray[$id]['pics'][] = the pics;
}
}
If i understand well your need, this is the idea can solve your problem in one loop with few id analyze.
:) enjoy
I tried to find any solution or question and I didn't find anything.
I'm working on a medical directory, is a table with 3 columns and 3 td's in every row when the html is done I need to convert it to a PDF version.
So far everything is fine.
But later, I was asked for a change.
To insert an index of contents every time the city changed.
But the structure must be the same in all cases, 3 cols with 3 tds for row
This is the structure of my table:
$totals=count($bloque[$i]);
for($i=0;$i<$totales;$i++){
if($i%3 == 0) {$impression[]="<tr valign='top' >".$bloque3[$i];}
if($i%3 == 1) {$impression[]=$bloque3[$i];}
if($i%3 == 2) {$impression[]=$bloque[$i]."</tr>";}
}
After that I'm doing the comparison if the city is different then structure of the index.
if($thecity != $rows['city']){
$index='<tr><th><span class="index" style="font-size:11px;"><small><b>'.$rows2['city '].'<br><br>Index of contents</b></small></span></th></tr>';
}
else{$index='';}
Next var is the structure of every td.
$bloque3[]='<span>'.$index.'</span><td width="30%"><p>'.$rows2['provider'].'</p>'.'<p>'.$rows2['service'].'</span>'.'<span>'.$rows2['benefits'].'<br />'.$rows2['city'].'</span></td>';
.
Every index must be in a new row, but I'm including the index in the same array bloque because otherwise is not working.
The problem is every time $index exist, is inserting a row inside a row, which is not too bad in the browser, because browsers are intelligent - most of them ;)-
But in pdf version the tds looks awful, one above another, and index above another td.
I'm working on a project using the pages in php / mysql and html; I have a table that contains the data for calls made from a PBX and save the number called, the source, date, time, etc ... what I want to do is to search within this table all the phone numbers that have the first 4 digits equal to those that pass through the query, only that i have no idea how to pull off only the 4-digit or at least how to make a control character by character of the value contained in the field. I tell you now that the field is a varchar. Thank you in advance :)
To do that in MySQL query, either
SELECT *
FROM <tablename>
WHERE LEFT(<column>, 4) = "<4 digits>"
or
SELECT *
FROM <tablename>
WHERE <column> LIKE "<4 digits>%"
or in the PHP side :
if (strpos($column,'<4 digit>') !== false) {
echo 'true';
}
Use this, to get substring
SELECT aut_name,
RIGHT(aut_name,7)
FROM author
WHERE country='UK';
See more at: http://www.w3resource.com/mysql/string-functions/mysql-right-function.php#sthash.xKNwZeki.dpuf
I suggest this solution:
$variableWhereYoustoreTheFourDigits="1234"; //Use whatever you have in your code to set the value.
$result =$mysqli->query("SELECT number FROM yourtable where number LIKE \"$variableWhereYoustoreTheFourDigits%\");
I have a script that dynamically creates a table with a varying number of columns and rows based on a db query.
This is done twice, on two different db tables.
I have a row at the bottom of each table with an input whose value is the sum of the cells in the column above.
These inputs are named itotal$m (where $m is an incrementing number) for the first table and etotal$m for the second table. So what I end up with is a number of input fields with the names itotal1, itotal2 etc for the first row of totals and etotal1, etotal2 etc for the second row.
I want to perform some simple maths with these totals, subtracting etotal1 from itotal1, etotal2 from itotal2 and so on, then displaying the result in another input.
I would like to use javascript function attached to an onChange event so that the user can change the input box values and see the result.
Unfortunately, I have not managed to figure out how to do this. Any help would be appreciated!
Assuming :
the two tables to have id="iTable" and id="eTable",
all the column total fields to have class="colTotal",
the two tables to be congruous (ie. their columns are in the same order),
the target input elements to have class="diffValue", then :
jQuery:
$(function(){
var $iTableTotals = $("#iTable .colTotal");
var $eTableTotals = $("#eTable .colTotal");
var $diffValues = $(".diffValue");
$(".colTotal").on('change keyup', function() {
$iTableTotals.each(function(i){
var diff = Number($iTableTotals.eq(i).val()) - Number($eTableTotals.eq(i).val());
$diffValues.eq(i).val(diff);
});
});
$iTableTotals.eq(0).change();
});
See fiddle