Jump to content

is there ay easy way to do this in php?


shadiadiph

Recommended Posts

I know it can be done with anchor tags in html but it looks messy

 

I have some links A-Z clicking 'A' should only display the paragraphs that are started with A like APPLE ANT etc and clicking B BALL BAT etc

 

<td class="two"><a href="<?=???>">A</a></td>
<td class="two"><a href="<?=???>">A</a></td>
<td class="two"><a href="<?=???>">A</a></td>


<p>APPLE</p>
<p>ANT</p>
<p>BAT</p>
<p>BALL</p>

 

 

Does anyone have any idea how to make this work i can'y think of the work around?? :(

 

Link to comment
Share on other sites

It depends on what you mean by "only display".  If you're looking to do that in real time, you'd need to use Javascript.  If you're willing to let a page load happen in between, then use a GET var. 

 

Is there any PHP code outputting the paragraphs?  Where does that paragraph information get pulled from?

Link to comment
Share on other sites

Yes, PHP can reload a page without javascript. And it doesn't have to be with a submit button. It can just be a text link, too.

 

There's several ways to code it. One way is like so:

<form method="GET" action="{$_SERVER['PHP_SELF']}">
<a href="{$_SERVER['PHP_SELF']}?variable=A">A</a>
<a href="{$_SERVER['PHP_SELF']}?variable=B">B</a>
</form>

Link to comment
Share on other sites

you can do this in php or javascript

 

php:

 

<?php
  function removeAllOther($var,$key,$let) {
    $letter = $var{0};
    if (strtolower($letter) == strtolower($let)) return true;
    return false;
  }
  $array = array("Apple","Ant","Bat","Ball");
  $ord = $_GET['ord'];
  if (strlen($ord) == 1) {
    // sorry I like to use strlen for variable checks :S sue me
    array_filter($array,"removeAllOther",$ord);
    print_r($array);
  }
?>

^^ for the above make all links look like: http://whatever.com/whatever.php?ord=a or b or c etc

javascript code:

 

<script type="text/javascript">
  var list;
  function sortIt(ord) {
    e = document.getElementById("results");
    if (!list.length) {
      list = e.getElementsByTagName("p");
      for (a in list) {
        list[a] = list[a].innerHTML;
      }
    }
    e.innerHTML = "";
    for (i in list) {
      if (list[i].toUpperCase().substr(0,1) == ord.toUpperCase()) {
        p = document.createElement("p");
        p.appendChild(document.createTextNode(list[i]));
        e.appendChild(p);
      }
    }
  }
</script>
<div id="results">
  <p>Apple</p>
  <p>Ant</p>
  <p>Bat</p>
  <p>Ball</p>
</div>
<a href="javascript:sortIt('A');">A</a>
<a href="javascript:sortIt('B');">b</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.