Page 1 of 1

php/mysql, drop down menus and changing variables

Posted: Thu Mar 16, 2006 12:28 pm
by inklestinkle
I'm still a beginner when it comes to php/mysql, but I need to make a script that will help me with something on my site.

I have these fields: id, name, info, website

I need a drop down menu that lists all the names. And I sort of know how to do that, but it's the next step where I get totally lost.

I have these different print functions for name, info and website that will show up on the page after you submit it, and I need those variables to change to correspond to the unique id of the name selected. So, if I select "Bob the Monkey" the three different print functions will all change his name, his info and his website.

Does anyone know where I could find some helpful tutorials or who could explain how to do this? (The drop down menu, the changing variable in three places with the menu, and all of that showing up with the print function?)

Thanks for your time.

Posted: Thu Mar 16, 2006 2:06 pm
by Burrito
what do you mean by 'print function'?

you have a drop down (<select>) box, when that is changed you want something to change on the currently loaded page? or you want it to submit to another page with dynamic information?

Posted: Thu Mar 16, 2006 2:36 pm
by inklestinkle
Sorry about that.

It's supposed to be an add on to a blog that you can control from the "post a new entry part". So you'd choose a selection (which would be listed as names, but each name has a unique id), write your entry, click submit and on the post created... well, here's an example of how it would show up:

title
name pulled from mysql by id chosen on post page.
post
info pulled from mysql by id chosen on post page.
website pulled from mysql by id chosen on previous page.

Does that explain what I'm trying to do a little better?

Posted: Thu Mar 16, 2006 3:52 pm
by Burrito
I still dont' understand the question.

you have a select box with names that are associated with ids (the select's value). You then submit that form and query the db based on the ip of the user.

you can then use that row's information on your page in question.

do you just not understand how to do that or is there something else your'e needing?

Posted: Fri Mar 17, 2006 12:16 pm
by inklestinkle
I don't understand how to do that. I have very limited php/mysql knowlege and haven't been able to find any tutorials.

Posted: Fri Mar 17, 2006 12:20 pm
by Burrito

Code: Select all

<select name="user">
  <option value="1">Bob Smith</option>
  <option value="2">Larry Holmes</option>
  <option value="3">Judy Jones</option>
  <option value="4">Kyle Johnson</option>
</select>

Code: Select all

mysql_connect("localhost","username","password")
  or die(mysql_error());
mysql_select_db("youruserdatabase")
  or die(mysql_error());
$result = mysql_query("select * from `users` where `id` = ".$_POST['user'])
  or die(mysql_error());
$row = mysql_fetch_assoc($result);
print_r($row);
give something like that a try....