![]() |
PHP, MySQL, and Dropdown lists
I have a question. Is it possible to get all the fields from a table inside a MySQL database, and display 'em, one by one, inside a dropdown list? I'm pretty sure it is, but I don't want to do 3+ hr.'s of coding to find out it won't work.
|
Re: PHP, MySQL, and Dropdown lists
Quote:
|
Re: PHP, MySQL, and Dropdown lists
Quote:
I'll try that and see what happens. |
Re: PHP, MySQL, and Dropdown lists
Quote:
PHP Code:
|
Re: PHP, MySQL, and Dropdown lists
Thank you :)
What I mean here though (I dunno if you stated this, I'm really tired today so...), is something like this: Inside a table (named "Bob"), there's 4 fields ("Hi", "I", "Love", "ChiefDelphi"). what I want to do is search through Bob, and for each field, I want to put each into a dropdown list. So, the choices would be like: "Hi", then next one is "I", then "Love", finally "ChiefDelphi". |
Re: PHP, MySQL, and Dropdown lists
Quote:
|
Re: PHP, MySQL, and Dropdown lists
After trying your code, I realized it's not exactly what I'm looking for. I'm trying to directly output the fields, not the field values.
|
Re: PHP, MySQL, and Dropdown lists
Quote:
|
Re: PHP, MySQL, and Dropdown lists
Quote:
But a new question has arisen. My question now is, I need to get the value from the field after clicking on the submit button. Here's my code: PHP Code:
Mainly, I just need to select the correct belt from the table, and output who owns it so far. I don't mean to be seeming like I'm asking how to do this whole thing, I've just been working on this for the whole day, and it's starting to get underneath my skin here. ** PS: I know it sounds like wrestling here, I'm helping a friend on a summer project ** |
Re: PHP, MySQL, and Dropdown lists
Quote:
NOTE: This news script cannot be used directly, there are still a few errors. If you look at the code under the if($action == "edit") section, you will see where a form is outputted. The following is a line of code from that, the name of the variable is modified for clarity: PHP Code:
|
Re: PHP, MySQL, and Dropdown lists
So you have a table of just people that own belts? Interesting. I'd have just made a new row in your wrestler table (I'm assuming you have one) named like belt_owned. Then you could have done something like SELECT DISTINCT wrestler_name,belt_owned FROM wrestlers WHERE belt_owned IS NOT NULL. But maybe I'm missing something. And I didn't even answer your question. Or was it already answered. I got so lost in that post that I don't even remember the problem :P I just got home from work.. so.. uhh *runs into wall and falls over*
|
Re: PHP, MySQL, and Dropdown lists
Quote:
|
Re: PHP, MySQL, and Dropdown lists
Ahh yes -- I knew there was a function, just couldn't find it in the 3-second attention span I allotted myself .. :)
|
Re: PHP, MySQL, and Dropdown lists
Quote:
max: Thanks also :) The problem w/ it though, is that when I choose the item...nothing happens period (which could be because I'm not good at using dropdown lists). |
Re: PHP, MySQL, and Dropdown lists
Ok, a new problem and I've been trying to fix it for the past 2 hours. What I'm trying to do is update the database by finding the belt in the table "belt_owner", and updating who owns it. I can connect, and get the current owners of it. My problem is trying to change the ownership of it.
There's a belt ("TV"), and the current holder in the database is "Trent Sinn". Whenever I try to change ownership of the belt (like, I enter my name as the new owner), nothing happens. It goes to the page it's supposed to, but doesn't update the table, or display a warning. PHP Code:
|
Re: PHP, MySQL, and Dropdown lists
Shouldn't you be doing something like UPDATE belt_owner SET $belt = '$new' WHERE wrestlername = 'Trent Sinn'. Or are these same people always going to have a belt? Could you maybe return the results of describe table; for the tables you're talking about? I'm not totally positive how you're doing this. I think I kinda see.. but it's a weird db design that I can't really grasp without seeing..
|
Re: PHP, MySQL, and Dropdown lists
Quote:
Table - Fields --------------- admin - username, password belt_owner -[list of belts] news - [news stuff] wrestler - [wrestler info] ------------------ The belt's values are who owns them. The reason for this is because a wrestler could hold more than 1 belt. I'm gonna keep it like this though (atleast for now). I get what you're saying though. But my field is set up to enter the belt to change, the current holder, and the new holder. So, I can't really do it the way you did by specifically (sp?) saying who holds the belt. Thanks though :) |
Re: PHP, MySQL, and Dropdown lists
Hrm. Okay.. so your belt_owner table has two columns.. one for the belt name and one for the owner of the belt? UPDATE belt_owner SET $belt = '$new' WHERE $belt = '$old' should be
Code:
UPDATE belt_owner SET wrestler_name = '$new' WHERE belt_name = '$belt'(and what I meant by describe table.. was actually running 'describe table' in mysql.. so you get stuff like this:) Code:
mysql> describe myposts; |
Re: PHP, MySQL, and Dropdown lists
Quote:
Quote:
+--------+------+---------+-------+--------+---------+----------+ |heavyweight|tv|cruiserweight|no_limits|tag_team1| tag_team2|team_name +--------+------+---------+-------+--------+---------+----------+ |Devon Matthews|Trent Sinn|Red Ninja| | | |CIA| +--------+------+---------+-------+--------+---------+----------+ The blank spots are vacant holdings. If I wanted to change Trent Sinn to say, raevin, the code wouldn't work (aka: the Cruiserweight title will still say Trent Sinn). |
Re: PHP, MySQL, and Dropdown lists
Huh.. okay.. that's an interesting way to do it. Well, then your SQL line should have been right. Try printing it out to make sure the values are what you expect them to be.
|
Re: PHP, MySQL, and Dropdown lists
Ok, 1 last question I think.
I got my other problems fixed so far, but now I'm having trouble showing the bio of the wrestler. I can get it to show everything but the weight. I've been working on this for about 1.5 days, and I can't understand why it's not working: PHP Code:
If anyone can help me w/ this, I will gladly appreciate it. |
Re: PHP, MySQL, and Dropdown lists
Just for kicks, try print_r($row); which will print the array. Make sure it's set and you have the column name correct. The code is fine, so I'd guess it's something small.
|
Re: PHP, MySQL, and Dropdown lists
Quote:
|
| All times are GMT -5. The time now is 00:29. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi