Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2004, 04:35 AM
Registered User
 
Join Date: Oct 2004
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.

 
Old October 27th, 2004, 07:52 AM
Authorized User
 
Join Date: Oct 2004
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;
 
Old October 27th, 2004, 06:34 PM
Registered User
 
Join Date: Oct 2004
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.

 
Old October 28th, 2004, 12:10 AM
Authorized User
 
Join Date: Oct 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


&lt;&gt;_&lt;&gt;
 
Old October 28th, 2004, 02:40 AM
Registered User
 
Join Date: Oct 2004
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.







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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.