Re: Combining Fields
| From: | Grae Wolfe - PHP | Date: | Wed, 31 May 2006 20:01:42 +0000 |
| Subject: | Re: Combining Fields | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41963@lists.php.net to get a copy of this message | ||
Again, my many thanks - I didn't know about the 'explode' function - that
may be a huge help.
Hopefully, I am on the right track now... thanks!
"Brad Bonkoski" <bbonkoski@mediaguide.com> wrote in message
news:447DF496.30301@mediaguide.com...
>
>
> Grae Wolfe - PHP wrote:
>
>>Thank you Brad - That is what I was looking for, but now that I see how it
>>behaves, I am thinking that it isn't going to work the way I wanted. I
>>need to then be able to pass the "ID" back to MySQL so that it will
>>retrieve just the one record for editing.
>>
>>I guess I need to go back to making the DB create an auto-incrementing ID
>>number. Hmmm...
>>
>>Thanks!!
>>
>>
> Well, the unique ID would probably be the *best* way to go, but you could
> also get the record with the below solution, of course this requires every
> combination of first and last name is unique...
> if you do:
> $id = "Smith,Adam"
> Then:
> list($fname, $lname) = explode(",",$id);
> select * from table where first_name = '$fname' and last_name='$lname'
> would do the trick...
> Of course this has many "what-ifs" asociated with it...all of which would
> be taken care of with an auto-incrementing/primary key ID field for wach
> record ;-)
>
> -Brad
>
>>"Brad Bonkoski" <bbonkoski@mediaguide.com> wrote in message
>>news:447DF244.1070705@mediaguide.com...
>>
>>>Grae Wolfe - PHP wrote:
>>>
>>>
>>>>Good Day!
>>>> I am trying to use my limited knowledge to create a VERY simple process
>>>> to display some of the information in my table, allow a particular
>>>> record to be selected, then opened on a page with text boxes to edit
>>>> the information, after which the UPDATE command will be used to update
>>>> the database.
>>>> That being said, I have a way that I think this will work, but I don't
>>>> have a unique record number in my table for each of the entries. I
>>>> have tried getting PHPMyAdmin to set this up, but I cannot seem to make
>>>> it work. SO - I need to try to create that ID on the fly. I figured I
>>>> could just combine the first and last names to make this ID, but I am
>>>> not sure what the syntax should be. Here is the code I have dealing
>>>> with defining the variables...
>>>>
>>>>Any help or thoughts would be splendid!
>>>>
>>>>while ($row = mysql_fetch_array($result)) {
>>>>$id = $row['last_name'],$row['first_name'];
>>>>$fname = $row['first_name'];
>>>>$lname = $row['last_name'];
>>>>
>>>>$option_block .= "<option value=\"$id\">$lname,
>>>>$fname</option>";
>>>>
>>>>
>>>>
>>>>
>>>Use the dot (.) for appending variables...
>>>so it would be:
>>>$id = $row['last_name'].$row['first_name'];
>>>...or course if you want that would look like this: 'SmithAdam'
>>>if you want 'Smith,Adam' as your id then:
>>>$id = $row['last_name'].",".$row['first_name'];
>>>-Brad
>>
>>