Jump to content

Recommended Posts

Hello

 

I hope someone can help me

 

I am really struggling with PHP and don't quite understand what I am doing, so please bear with me

 

I am trying to display a message if the result is greater than 12

 

Please see my attempts below

 

//$BoxTotal =  "{qty{$row[$heading_column]}}"; // doens't seem to let me write it without the "" and is now text

$BoxTotal +=  "{qty{$row[$heading_column]}}"; // += trying to convert it to number - still string

$BoxTotal += $BoxTotal; // += trying to convert it to number - still string

if ($BoxTotal >= 12) { // picks up 15 if it is a string - not the number

$warning = "warning only 12 bottles per box please " . $BoxTotal ;

}

 

I only seem to be able to get $BoxTotal if I enclose it in quotation marks, which, I think is turning it into text

I scoured the Internet and found that perhaps += might convert it back into a number but this doesn't seem to work

 

I expect its really simple when you know how

 

If if helps to see the whole thing I have attached a pdf file, the bit I am looking at is at line 415 (commented out at the moment)

 

Any help really appreciated

 

Cheers

Jayne  :confused:

 

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/244038-converting-text-to-numbers/
Share on other sites

The following code might help you if it does the post is solved  ;):

 

<html>

<head>

<script>

 

function calculate( length, width,height)

{

  var x = length.value; 

  var y = width.value;

var z = height.value

 

var t=  parseInt(x)+parseInt(y);

 

  if (x==900)

  alert(x);

  else

alert(y);

 

document.frm.textfield.value = t*z;

}

</script>

</head>

<body>

 

<form name="frm">

<table>

<tr>

<td>Length</td>

<td><input name="len" type="text" /></td>

</tr>

 

<tr>

<td>Width</td>

<td><input name="wid" type="text" /></td>

</tr>

<tr>

  <td>Height</td>

  <td>

    <input name="hit" type="text" id="hit" />

  </td>

</tr>

<tr>

  <td>Result</td>

  <td><input type="text" name="textfield" id="textfield"></td>

</tr>

<tr>

  <td> </td>

  <td><input type="button" name="Submit" value="Submit" onClick="calculate(document.frm.len, document.frm.wid, document.frm.hit)"

 

/></td>

</tr>

</table>

</form>

 

</body>

</html>

Thanks guys but I am still drowning

 

The first two seem to work independently but not when I try put them in my code.

The third, I think I understand the idea, but I can't integrate it so it doesn't much everything else up.

The fourth one looks like the sort of thing I was looking for but the qty part of the equation is missing

 

Is my code fundamentally flawed?

 

Cheer

Jayne

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.