Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
not being able to decrement numbers via user input
Old 04-13-2011, 06:05 PM not being able to decrement numbers via user input
Junior Talker

Posts: 2
Trades: 0
I am trying to be able to have the numbers in the rows(columns) to be able to either increment or decrement via user input by radio button on the HTML form page.I have included both the HTML page and the PHP page.

HTML Code:
<html>
<head>
    <title>form</title>
    <style type="text/css">
body {background-color:yellow}
</style>
    
</head>
<body>
<form name="input" action="formout.php" method="post">
number of rows: <input type="text" name="rows" />
number of cells: <input type="text" name="cells" /></br>
Beginning Number: <input type="text" name="beginning" />&nbsp;
Ending Number: <input type="text" name="ending" /><br />
<input type="radio" name="count" value="up" /> Up<br />
<input type="radio" name="count" value="down" /> Down<br />
Skip Number: <input type="text" name="skip" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
PHP Code:
<?php
$rows_incoming
=$_POST['rows'] ;
$cells_incoming=$_POST['cells'] ;
$count_start=$_POST['beginning'];
$count_end=$_POST['ending'];
$skip=$_POST['skip'];
$across_start=$_POST['across'];
$across_end=$_POST['toacross'];
$count_up=$_POST['up'];
$count_down=$_POST['down'];


echo 
"<table  border=1 width=100%>";
$starting_integer=0;
for(
$rows=1;$rows<=$rows_incoming;$rows++){
    echo 
"<tr>";
    for(
$cells=1;$cells<=$cells_incoming;$cells++){
        echo 
"<td>";
        for (
$count=$count_start+$starting_integer $count<=$count_end+$starting_integer $count++) {
        
        elseif
            (
$count=$count_up+$starting_integer $count>=$count_down+$starting_integer $count--) {
            else
                (
$count%$skip)
                    echo 
"<br />" $count "<br />" ;
            }
        }
        echo 
"</td>";
        
    }
    echo 
"</tr>";
}
echo 
"</table>";
?>

any help would be appreciated.
BiggyE is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-13-2011, 08:37 PM Re: not being able to decrement numbers via user input
Junior Talker

Posts: 2
Trades: 0
here is the modified code i just tried, but im getting a parse error.

Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\formout.php on line 21

HTML Code:
<html>
<head>
    <title>form</title>
    <style type="text/css">
body {background-color:yellow}
</style>
    
</head>
<body>
<form name="input" action="formout.php" method="post">
number of rows: <input type="text" name="rows" />
number of cells: <input type="text" name="cells" /></br>
Beginning Number: <input type="text" name="beginning" />&nbsp;
Ending Number: <input type="text" name="ending" /><br />
<input type="radio" name="increment" value="1"> Increment<br />
<input type="radio" name="increment" value="0"> Decrement<br />
Skip Number: <input type="text" name="skip" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
PHP Code:
<?php
$rows_incoming
=$_POST['rows'] ;
$cells_incoming=$_POST['cells'] ;
$count_start=$_POST['beginning'];
$count_end=$_POST['ending'];
$skip=$_POST['skip'];
$across_start=$_POST['across'];
$across_end=$_POST['toacross'];


echo 
"<table  border=1 width=100%>";
$starting_integer=0;
for(
$rows=1;$rows<=$rows_incoming;$rows++){
    echo 
"<tr>";
    for(
$cells=1;$cells<=$cells_incoming;$cells++){
        echo 
"<td>";
        if(isset(
$_POST["increment"])){
    if(
$_POST["increment"]==1){
     for(
$count=$count_start+$starting_integer $count<=$count_end+$starting_integer $count++) // do increment what you need
    
    
else{
     (
$count=$count+$starting_integer $count>=$count+$starting_integer $count--) // otherwise decrement
        
}
    }
                    echo 
"<br />" $count "<br />" ;
            
    }    
        echo 
"</td>";
        
    }
    echo 
"</tr>";
}
echo 
"</table>";
?>
BiggyE is offline
Reply With Quote
View Public Profile
 
Old 04-13-2011, 10:41 PM Re: not being able to decrement numbers via user input
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
It seems like your logic is messed up, and you are unable to use a for statement as a conditional statement which is why you are getting the fatal error. I tried to manipulate the logic below, which made more sense to me.

I tried to make coments to explain what the sections are doing in the processing section.

PHP Code:
<html>
  <head>
  <title>form</title>
  <style type="text/css">
  body {background-color:yellow}
  label {display:block}
  </style>
  </head>
  <body>
  
<?php
  
if (empty($_POST))
{
  
?>
  <form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label for="rows">Number of rows: <input type="text" name="rows" id="rows" /></label>
    <label for="columns">Number of columns: <input type="text" name="columns" id="columns" /></label>
    <label for="starting">Starting number: <input type="text" name="starting" id="starting" /></label>
    <label for="display">Display count: <input type="text" name="display" id="display" /></label>
    <label for="skip">Multiply skip count by: <input type="text" name="skip" id="skip" /></label>
    <label for="order-asc"><input type="radio" name="order" id="order-asc" value="asc" /> Increment</label>
    <label for="order-desc"><input type="radio" name="order" id="order-desc" value="desc" /> Decrement</label>
    <input type="submit" value="Submit" />
  </form>
<?php
  
}
else
{
  
  
// Prepare input:
  
$rows = ($_POST['rows'] > 1) ? (int)$_POST['rows'] : 1;
  
$columns = ($_POST['columns'] > 1) ? (int)$_POST['columns'] : 1;
  
$display = ($_POST['display'] > 1) ? (int)$_POST['display'] : 1;
  
$skip = ($_POST['skip'] > 1) ? (int)$_POST['skip'] : 1;
  
$starting = (int)$_POST['starting'];
  
$starting = (int)$_POST['starting'];
  
  
  
// Create number sequence array:
  
$numbering = array();
  
  
// Increment or decrement logic
  
if ($_POST['order'] == 'desc'$skip = -$skip;
  
  
// Numbering logic
  
for ($num $starting$i 0$i $display$i++, $num += $skip)
  {
    
$numbering[] = $num;
  }
  
?>
  <table border="1" width="100%">
<?php
  
  
// Rows
  
for ($r 0$r $rows$r++)
  {
    
?>
    <tr>
<?php
    
    
// Columns
    
for ($c 0$c $columns$c++)
    {
      
?>
      <td><?php echo implode('<br />'$numbering); ?></td>
<?php
      
    
}
    
?>
    </tr>
<?php
    
  
}
  
?>
  </table>
<?php
  
}
  
?>
  
  </body>
</html>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to not being able to decrement numbers via user input
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42353 seconds with 12 queries