Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 27th, 2004, 04:35 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default parsing concatenated strings?

Hi,

I am new to PHP and cant seem to find a way to parse a concatenated string and variable.

To explain:

I have a database to catalogue a composers works, one of the tables has a list of instruments which I then access to dynamically display on a wep page using checkboxes - if a particular instrument is used in the work then the checkbox is checked.

<?php
$resultInstrument = mysql_query("SELECT * FROM instrumentTbl ORDER BY sort_order");
 if ($myrowInstrument = mysql_fetch_array($resultInstrument)) {
do {
echo $myrowInstrument['instrument'];
echo ": ";
?>

 <input name="<?php echo $myrowInstrument['instrument']; ?>" type="checkbox" value="<?php echo $myrowInstrument['instrument']; ?>">

So far so good.

The problem I am having is when I want to insert the number of instruments used in the work.
<input name="<?php echo $myrowInstrument['instrument']; ?>number" type="text" size="3">

This snipet of code produces a dynamically created form where the user can enter the number of instruments.

Here is a part of the form created from the code above:
<input name="Flutenumber" type="text" size="3">

To process the information in this form I think I need to concatenate $instrument with the string 'number'. the only problem is that PHP reads this literally and the output is just $Flutenumber and not the number actually entered.

Here is the code I have at the moment

$resultInstrument_id = mysql_query("SELECT * FROM instrumentTbl ORDER BY sort_order");

    while ($myrowInstrument_id = mysql_fetch_array($resultInstrument_id))
    {
    $instrument = $myrowInstrument_id['instrument'];

if (strlen ($$instrument !='0'))
  {
//this works fine and gives a list of all the checked instruments
print $$instrument;

//this just outputs the literal interpretation
print "$${$instrument}number";

    }
}

Any help would be greatly appreciated.

Thanks,
Paul.

Reply With Quote
  #2 (permalink)  
Old October 27th, 2004, 07:52 AM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You may try using the . opperator instead. <?php print $$instrument. ' ' . number ?> you can remove the ' ' if you want. That's only there for an added space.

&lt;&gt;_&lt;&gt;
Reply With Quote
  #3 (permalink)  
Old October 27th, 2004, 06:34 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply!

actually I have tried several different variations of concat - using . using different quotes and different brackets, all with varied and interesting results, but nothing would actually parse the variable $instrumentnumber it would only print "$Flutenumber" (as an example) to the screen. It should actually print a number.

Very frustrating.

Reply With Quote
  #4 (permalink)  
Old October 28th, 2004, 12:10 AM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

print $$instrument . 'number'; doesn't work???


&lt;&gt;_&lt;&gt;
Reply With Quote
  #5 (permalink)  
Old October 28th, 2004, 02:40 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, but it's not the result I was after.

print $$instrument . 'number';
 will just print $Flutenumber (or whatever instrument is checked) I was hoping to get the actual variable .

If I manually tpye
print $Flutenumber;
I get the value that was entered in the form (the number 2 will be printed if 2 was entered on the form)

It's doing exactly what I tell it to do, just not interpreting the variable.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenated dynamic date KYbluebird BOOK: Access 2003 VBA Programmer's Reference 5 June 11th, 2007 10:13 AM
strings bschleusner C# 2005 3 February 27th, 2007 11:46 PM
strings Moharo Pro PHP 2 May 17th, 2004 06:15 AM
TCP/IP Data is Being Concatenated owain Pro VB 6 2 December 9th, 2003 08:12 PM
New line in concatenated field NK Oracle 1 July 15th, 2003 10:27 PM



All times are GMT -4. The time now is 12:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.