Re: [PHP-DB] radio form submission

2011-06-24 Thread Guru™
I guess if you are storing the value of post_tptest in the database, it
should return the same value what the user selected in the radio option. If
I am right in your display you are just calling the data from the database.
Check if the data is properly storing the radio button values in the
database ??



-- 
*Best,
*
*Guru™*


Re: [PHP-DB] radio form submission

2011-06-23 Thread Karl DeSaulniers

Try this...

function getSpeed($val) {
if($val != 'undefined') {
switch ($val){
case 1:
$post_tptest = 0-250kbps;
break;
case 2:
$post_tptest = 250-300kbps;
break;
case 3:
$post_tptest = 300-400kbps;
break;
case 4:
$post_tptest = 400-600kbps;
break;
case 5:
$post_tptest = 600kbps-3.8mbps;
break;
default:
$post_tptest = Speed Undetected; // or 
0-250kbps
break;
}
} else {
return(Error, no speed value set);
}
}
}

$post_speed = getSpeed($post_tptest);

$posts_sql = SELECT
posts.post_store,
posts.post_content,
posts.post_speed,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store =  . 
mysql_real_escape_string($_GET['id']) . 
ORDER BY
posts.post_date DESC ;

...

Best,
Karl


On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:


So far I am good on creating the form and  submitting it to mysql
database and calling the submitting value from a different script.

My question is: How can I make it so when a user selects radio option
value 1 it will then be displayed as 0-250kbps when I call it the
value in the bottom script?

forgive my indention. Gmail messes it up.


 My Form 


echo 'form method=post action=
	Store name: input type=text name=store_subject /br / 
br /

Market:';

echo 'select name=store_mar';
while($row = mysql_fetch_assoc($result))
{
echo 'option value=' . $row['mar_id'] 
. '' .
$row['mar_name'] . '/option';
}
echo '/selectbr /br /'; 

echo 'Broadband speed test results: br /br /
0-250kbpsinput type=radio name=post_tptest 
value=1 /|
250-300kbpsinput type=radio name=post_tptest 
value=2 /|
300-400kbpsinput type=radio name=post_tptest 
value=3 /|
400-600kbpsinput type=radio name=post_tptest 
value=4 /|
600kbps-3.8mbpsinput type=radio 
name=post_tptest value=5
/br /br /
Store visit details: br /br /
textarea name=post_content //textareabr 
/br /
input type=submit value=Add a store 
visit /
 /form';

 My display script 

$posts_sql = SELECT
posts.post_store,
posts.post_content,
posts.post_tptest,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
   

Re: [PHP-DB] radio form submission

2011-06-23 Thread Chris Stinemetz
On Thu, Jun 23, 2011 at 2:49 PM, Daniel P. Brown
daniel.br...@parasane.net wrote:
 On Thu, Jun 23, 2011 at 15:46, Chris Stinemetz chrisstinem...@gmail.com 
 wrote:

    Use an if or a switch.  For example:


 I think your suggestions are exactly what I am looking for. I am not
 sure exactly where to place it. Do I insert it after the query
 statment?

    During your while() loop.  This line here:

        td class=post-content' . $posts_row['post_tptest'] .

    If you convert it to a function as Karl suggested, you could do
 something like this:

        td class=post-content' . getSpeed($posts_row['post_tptest']) .


I must be missing something. I am just getting a blank page. Your help
is greatly apprecieated.

The function and query statement is:

function getSpeed($val) {
if($val != 'undefined') {
switch ($val){
   case 1:
$post_tptest = 0-250kbps;
break;
   case 2:
$post_tptest = 250-300kbps;
break;
   case 3:
$post_tptest = 300-400kbps;
break;
   case 4:
$post_tptest = 400-600kbps;
break;
   case 5:
$post_tptest = 600kbps-3.8mbps;
break;
   default:
$post_tptest = Speed Undetected; // or 0-250kbps
break;
   }
} else {
   return(Error, no speed value set);
}
}
}

$post_speed = getSpeed($post_tptest);

//fetch the posts from the database
$posts_sql = SELECT
posts.post_store,
posts.post_content,
posts.post_speed,   

posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store =  . 
mysql_real_escape_string($_GET['id']) . 
ORDER BY
posts.post_date DESC ; 



The call:

while($posts_row = 
mysql_fetch_assoc($posts_result))
{
echo 'tr class=topic-post
td class=user-post' 
. $posts_row['first_name'] . ' ' .
$posts_row['last_name'] . 'br/' . date('m-d-Y h:iA',
strtotime($posts_row['post_date'])) . '/td
td 
class=post-content' .
getSpeed($posts_row['post_tptest']) . 'br/' .
htmlentities(stripslashes($posts_row['post_content'])) . '/td
  /tr';
}
}


Thank you!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] radio form submission

2011-06-23 Thread Karl DeSaulniers

I also think you need to use the mysql_free_result like so..

echo 'select name=store_mar';
while($row = mysql_fetch_assoc($result))
{
echo 'option value=' . $row['mar_id'] 
. '' .
$row['mar_name'] . '/option';
mysql_free_result($result);
}
echo '/selectbr /br /';

If I am incorrect, please, someone interject. :)

Best,
Karl

On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:


echo 'select name=store_mar';
while($row = mysql_fetch_assoc($result))
{
echo 'option value=' . $row['mar_id'] 
. '' .
$row['mar_name'] . '/option';
}
echo '/selectbr /br /';


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] radio form submission

2011-06-23 Thread Daniel P. Brown
On Thu, Jun 23, 2011 at 15:46, Chris Stinemetz chrisstinem...@gmail.com wrote:

    Use an if or a switch.  For example:


 I think your suggestions are exactly what I am looking for. I am not
 sure exactly where to place it. Do I insert it after the query
 statment?

During your while() loop.  This line here:

td class=post-content' . $posts_row['post_tptest'] .

If you convert it to a function as Karl suggested, you could do
something like this:

td class=post-content' . getSpeed($posts_row['post_tptest']) .

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] radio form submission

2011-06-23 Thread Chris Stinemetz

    Use an if or a switch.  For example:


I think your suggestions are exactly what I am looking for. I am not
sure exactly where to place it. Do I insert it after the query
statment?

Thank you,

Chris

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] radio form submission

2011-06-23 Thread Tamara Temple


On Jun 23, 2011, at 2:32 PM, Karl DeSaulniers wrote:


Try this...

function getSpeed($val) {
if($val != 'undefined') {
switch ($val){
case 1:
$post_tptest = 0-250kbps;
break;
case 2:
$post_tptest = 250-300kbps;
break;
case 3:
$post_tptest = 300-400kbps;
break;
case 4:
$post_tptest = 400-600kbps;
break;
case 5:
$post_tptest = 600kbps-3.8mbps;
break;
default:
$post_tptest = Speed Undetected; // or 
0-250kbps
break;
}
} else {
return(Error, no speed value set);


Just to point out, this is the only return from this function. The  
$post_tptest is never returned. You could actually just say:


return 0-250kbps;

above instead of setting the $post_tptest *local* variable. (You  
wouldn't need the break statements, then, either, but it's still  
probably a good idea to code them in.)



}
}
}
$post_speed = getSpeed($post_tptest);



Or, you know, an array:

speed = array(
'1'='0-250kbps',
'2'='250-300kbps'.
'3'='300-400kbps',
'4'='400-600kbps',
'5'='600kbps-3.8mbps',
);

//$post_speed = isset($speed[$post_tptest])? 
$speed[$post_tptest]:Speed undetected;


(See below for inline usage.)

Of course, you could also avoid all this translation by putting the  
string values you want in the radio button on the form itself. This  
may have implications for your database and how you store it, however.


You can also avoid the problem with an empty return if no radio button  
is checked by making sure one is checked when your form loads, by  
using the 'checked' attribute on one of the items. If you want them to  
have a not tested option, you can include that as one of your  
buttons and add it to the array above as well. (That might be a good  
place to use the zero value.)





$posts_sql = SELECT
posts.post_store,
posts.post_content,
posts.post_speed,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store =  . 
mysql_real_escape_string($_GET['id']) . 
ORDER BY
posts.post_date DESC ;

...

Best,
Karl


On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:


So far I am good on creating the form and  submitting it to mysql
database and calling the submitting value from a different script.

My question is: How can I make it so when a user selects radio option
value 1 it will then be displayed as 0-250kbps when I call it the
value in the bottom script?

forgive my indention. Gmail messes it up.


 My Form 


echo 'form method=post action=
	Store name: input type=text name=store_subject /br / 
br /

Market:';

echo 'select name=store_mar';
while($row = mysql_fetch_assoc($result))
{
echo 'option value=' . $row['mar_id'] 
. '' .
$row['mar_name'] . '/option';
}
echo '/selectbr /br /'; 

echo 'Broadband speed test results: br /br /
0-250kbpsinput type=radio name=post_tptest 
value=1 /|
250-300kbpsinput type=radio name=post_tptest 

Re: [PHP-DB] radio form submission

2011-06-23 Thread Daniel P. Brown
On Thu, Jun 23, 2011 at 16:08, Chris Stinemetz chrisstinem...@gmail.com wrote:

 I must be missing something. I am just getting a blank page. Your help
 is greatly apprecieated.

This is why you're supposed to take the advice and write it out
yourself, not copy and paste the code.  ;-P

By copying and pasting the stuff, you broke your query.  Karl
suggested you use a column which doesn't exist.  Instead, change the
query back to what it was before, add the function (you should be able
to copy and paste that part though) at the end of the file, and then
use the line of code I gave you.  Obviously, I can't write it out for
you, but you'll get the idea.



 The function and query statement is:

                        function getSpeed($val) {
                                if($val != 'undefined') {
                                        switch ($val){
                       case 1:
                            $post_tptest = 0-250kbps;
                            break;
                       case 2:
                            $post_tptest = 250-300kbps;
                            break;
                       case 3:
                            $post_tptest = 300-400kbps;
                            break;
                       case 4:
                            $post_tptest = 400-600kbps;
                                                        break;
                       case 5:
                            $post_tptest = 600kbps-3.8mbps;
                            break;
                       default:
                            $post_tptest = Speed Undetected; // or 
 0-250kbps
                            break;
                       }
                                        } else {
                       return(Error, no speed value set);
                                        }
                                }
                        }

                        $post_speed = getSpeed($post_tptest);

                        //fetch the posts from the database
                        $posts_sql = SELECT
                                                posts.post_store,
                                                posts.post_content,
                                                posts.post_speed,
                                                posts.post_date,
                                                posts.post_by,
                                                users.user_id,
                                                users.user_name,
                                                users.first_name,
                                                users.last_name
                                        FROM
                                                posts
                                        LEFT JOIN
                                                users
                                        ON
                                                posts.post_by = users.user_id
                                        WHERE
                                                posts.post_store =  . 
 mysql_real_escape_string($_GET['id']) . 
                                        ORDER BY
                                                posts.post_date DESC ;


 The call:

                                while($posts_row = 
 mysql_fetch_assoc($posts_result))
                                {
                                        echo 'tr class=topic-post
                                                        td 
 class=user-post' . $posts_row['first_name'] . ' ' .
 $posts_row['last_name'] . 'br/' . date('m-d-Y h:iA',
 strtotime($posts_row['post_date'])) . '/td
                                                        td 
 class=post-content' .
 getSpeed($posts_row['post_tptest']) . 'br/' .
 htmlentities(stripslashes($posts_row['post_content'])) . '/td
                                                  /tr';
                                }
                        }


 Thank you!




-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/


Re: [PHP-DB] radio form submission

2011-06-23 Thread Daniel P. Brown
On Thu, Jun 23, 2011 at 14:18, Chris Stinemetz chrisstinem...@gmail.com wrote:
 So far I am good on creating the form and  submitting it to mysql
 database and calling the submitting value from a different script.

 My question is: How can I make it so when a user selects radio option
 value 1 it will then be displayed as 0-250kbps when I call it the
 value in the bottom script?

Use an if or a switch.  For example:

?php

// Using if/elseif/else

if ($row['tp_test'] == '1') {
echo '0-250Kbps';
} elseif ($row['tp_test'] == '2') {
echo 'The second value.';
} elseif ($row['tp_test'] == '3') {
echo 'The third value.';
} else {
echo 'I have no clue.  I give up.';
}


// Using switch

switch ($row['tp_test']) {
  case '1':
echo 'First case.';
break;
  case '2':
echo 'Second case.';
break;
  case '3':
echo 'Third case.';
break;
  default:
echo 'No idea whatsoever.';
break;
}

?

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php