0

I think my structure may be wrong on this page but I've gone too far to change it and now trying to make the best of a bad situation.

I have a large list of items in drop down.

an example is :

 <li><a href="conversion.php?conversionType=accelerationAngular">Acceleration - Angular</a></li>

What I'd like to use is something like :

<h4><?php

        if ($conversionType == null){
            echo "Please select a category";
        }else{
            echo "Current Category : " . $conversionType;
        }
        ?>
    </h4>

to display what the current selected category is. The above works but it doesn't display "Acceleration - Angular", it displays accelerationAngular which of course is how I've named the values to be passed onto another page.

Is there a way I can extract the name of the li element ?

1
  • Why don't you use a hashed array to store the values and names to display? Commented Sep 5, 2013 at 20:57

3 Answers 3

2

For me, I would have a PHP array with all the LI values and labels:

$list = array(
    'accelerationAngular' => 'Acceleration - Angular',
    'someOtherValue' => 'Some Other Label',
    // And more...
);

Then output the list:

<?php foreach($list as $k => $v): ?>
<li><a href="conversion.php?conversionType=<?php echo $k ?>"><?php echo $v ?></a></li>
<?php endforeach ?>

Then for your header:

<h4><?php echo isset($list[$conversionType]) ? $list[$conversionType] : 'Please select a category' ?></h4>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I used the array and the header part but havent used the for each li as my structure has various different levels etc. Works fine though, thank you!
0

So, not sure if you are hand-coding your HTML, but if you are, you could rewrite your code as follows

<li><a href="conversion.php?conversionType=Acceleration%20-%20Angular">Acceleration - Angular</a></li>

so that the same string that appears as the text of the link gets passed to the server as the conversionType parameter.

1 Comment

I can;t do this as it means changing too many things. thanks for the suggestion though
0
<li><a href="conversion.php?conversationType=<?=urlencode($title='Acceleration - Angular')?>"><?=$title?></a></li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.