frshjb373 Posted September 8, 2012 Share Posted September 8, 2012 Basically I'd like to echo "name1" in the browser, which is working fine! But I'd also like to bring over the associated "name2" field value without the user being able to see this value until the form has been processed. I am using "field_Name" to process both these variables at once on the following page so I'd also like to separate these variables as well. I'm sure it's an extremely simple fix, but I can't figure it out. Any help is much appreciated! <?php mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed"); mysql_select_db ($DB_name) or die("Connection Failed"); $query = "SELECT * FROM table"; $result = mysql_query($query); ?> <select name="field_Name"> <option value="">Select one...</option> <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <?php $row['name']; ?> <option value="<?php echo $row['name1'];?> <?php $row['name2'];?>"> <?php echo $row['name1'];?> </option> <?php } ?> </select> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 8, 2012 Share Posted September 8, 2012 remove this part <?php $row['name2'];?> Quote Link to comment Share on other sites More sharing options...
frshjb373 Posted September 8, 2012 Author Share Posted September 8, 2012 Ok, but I would like to still use the "name2" value/variable to carry over when processed. The "name2" table field is a price that I do not want the user to see until the next page. Do you have any suggestions how I may accomplish that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 8, 2012 Share Posted September 8, 2012 Do a query on the next page to get the info based on the chosen option. Quote Link to comment Share on other sites More sharing options...
frshjb373 Posted September 8, 2012 Author Share Posted September 8, 2012 Ok...I think I'm getting there, but I can't figure quite out how to associate "field_Name" variable on the next page. I think basically what I'm trying to say in my code is..."If "field_Phone" is equal to any value in "$row['name1']" then echo the associated "$row['name2"] value." I'd like to think I'm close, but I haven't nailed it yet. The code I came up with is below. Am I even close? Thanks again for all the help! <?php mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed"); mysql_select_db ($DB_name) or die("Connection Failed"); $query = "SELECT * FROM cell_brands"; $result = mysql_query($query); ?> <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($field_Phone = ($row['name1'])) { echo $row['name2']; } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 8, 2012 Share Posted September 8, 2012 Don't select all of them, just select the one the user selected. Also, = is assignment, == is comparison Quote Link to comment Share on other sites More sharing options...
frshjb373 Posted September 8, 2012 Author Share Posted September 8, 2012 Awesome! Think I figured it out. Here's what I came up with. Honestly, not sure if I even need "LIMIT 0,1" at the end of the query. <?php mysql_connect($DB_host,$DB_user,$DB_pass) or die("Connection Failed"); mysql_select_db ($DB_name) or die("Connection Failed"); $query = "SELECT name2 FROM cell_brands WHERE name = '{$field_Phone}' LIMIT 0,1"; $result = mysql_query($query); ?> <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $price = $row['name2']; } ?> Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 8, 2012 Share Posted September 8, 2012 It can be nice to have, but not necessary, no. However, this following part isn't necessary at all: ?> <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $price = $row['name2']; } First of all there's no need to close and then re-open the PHP parsing like that, you're only wasting resources. Secondly, you don't need to loop the result set, as you have only one row anyway. mysql_result () should be more than adequate for this particular need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.