Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Search Anchor Not Working

Status
Not open for further replies.

dessie1981

Programmer
May 9, 2006
116
GB
Hi Everyone,

I'm Displaying a list of results in a table from a search in the online store i am writing.

I list the various manufacturers at the top of the table. When the user clicks on the link i would like the page to do a text search on the results listed in the table below , however this does not seen to be working.

while ($manu_row = mysql_fetch_array($manu_result))
{
echo '<a href="#' . $manu_row[0] . '"> ' . $manu_row[0] . ',</a>';
}
The abouve code does not work, can anyone see anything wrong??





Regards
Dessie
 
Dessie said:
however this does not seen to be working
is a bit vague... Can you tell us what is it not working? Let's begin with the obvious... Do you have correct anchors in the actual table?
 
i don't know what this is trying to do
Code:
 '<a href="#' . $manu_row[0]

assuming element[0] is a unique id would this not look something like
Code:
<a href="#123456">123456</a>

and i think this would cause a browser to look for an anchor somewhere in your document called 123456

if you want this to be a php call (i.e. a return to the server) then your link should be formatted like this:
Code:
<a href="pagename.php?uniqueid=123456">123456</a>
where pagename.php could equally be any valid uri

if you want the link to function as an internal anchor then the link is correctly formatted but you need to tell the browser where to find the anchor that it points to by putting this in the relevant place in the text:
Code:
<a name="123456"></a>
 
Hi again, Sorry for not being more clear.

I am returning a list of products with various different columns in the table, e.g. partnumber, manufacturer, model.

Code:
echo '<a href="#' . $manu_row[0] . '"> ' .    $manu_row[0] . ',</a>';

Prints at the top of the table which lists all the manufacturers that are in the results table.

I would like the link to function as an internal anchor so that the user can locate the list of products of their choosen manufacturer quickly from the list of all results.

With the code i have at the moment (i.e. the above code), when the user click on the link, nothing happens, the text search does not happen, the page does not move.



Regards
Dessie
 
In response to vragabond, yes the correct anchors are in the table as i am using the same variable to return them.

Regards
Dessie
 
can you post the source code generated by this page. the error is undoubtedly in your html.
 
Here you go


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>shop</title>
<link href="frame-style.css" rel="stylesheet" type="text/css" />
</head>

<body onLoad="parent.topFrame.location.reload();">


<div class="header2">Go straight to product:<a href="#NAVMAN"> NAVMAN,</a><a href="#VODAFONE"> VODAFONE,</a><br><br><table width="95%" border="0" align="center" cellpadding="5" cellspacing="5" summary="">
	      <tr><table width="95%" border="0" align="center" cellpadding="5" cellspacing="5" summary="">
		<tr><td colspan="6" class="product-header">Searching on "aerials"</td></tr>
    <tr>
      <td class="column-header">Part No.</td>
      <td class="column-header">Description</td>
      <td class="column-header">Manufacturer</td>
      <td width="80" class="column-header"><div align="right">Price (&#8364;)</div></td>
      <td width="80" class="column-header"><div align="right">Stock Qty</div></td>
      <td width="90" class="column-header"><div align="right">Add To Cart</div></td>
    </tr><tr>
      <td class="cell-content">AA005120</td>
      <td class="cell-content">iCN 320 Mmcx External Antenna..........<A HREF="details.php?details=129210" TARGET = "mainFrame">More Details / Buy</A>.</td>
      <td class="cell-content">NAVMAN <<font SIZE=1> <A HREF="advanced_classification.php?advanced_class=Navman G.P.S."><br>Navman G.P.S.<a></font></td>
      <td class="cell-content"><div align="right">36.95</div></td>
      <td class="cell-content"><div align="right">38</div></td>
      <td class="cell-content"> 
        <div align="right">	  <form name="myform" action = "/Copy of onlinestore/manufacturer_test.php?id&quantity">
          <input name="quantity" type="text" class="form-input" size="5" maxlength="5" />
	  <input type="hidden" name="id" value="129210">
          <input name="Submit" type="submit" class="form-button" value="Add"/>
	  </form>
          </div>
            </td>
    </tr>
    <tr>
      <td class="cell-content">AA005088</td>
      <td class="cell-content">mMCX External Antenna..........<A HREF="details.php?details=129827" TARGET = "mainFrame">More Details / Buy</A>.</td>
      <td class="cell-content">NAVMAN <<font SIZE=1> <A HREF="advanced_classification.php?advanced_class=|Navman G.P.S."><br>|Navman G.P.S.<a></font></td>
      <td class="cell-content"><div align="right">37.22</div></td>
      <td class="cell-content"><div align="right">170</div></td>
      <td class="cell-content"> 
        <div align="right">	  <form name="myform" action = "/Copy of onlinestore/manufacturer_test.php?id&quantity">
          <input name="quantity" type="text" class="form-input" size="5" maxlength="5" />
	  <input type="hidden" name="id" value="129827">
          <input name="Submit" type="submit" class="form-button" value="Add"/>
	  </form>
          </div>
            </td>
    </tr>
    <tr>
      <td class="cell-content">AA004035</td>
      <td class="cell-content">External MCX Car Antenna for ICN630 & GPS3450 Only..........<A HREF="details.php?details=125744" TARGET = "mainFrame">More Details / Buy</A>.</td>
      <td class="cell-content">NAVMAN <<font SIZE=1> <A HREF="advanced_classification.php?advanced_class=Navman G.P.S."><br>Navman G.P.S.<a></font></td>
      <td class="cell-content"><div align="right">49.26</div></td>
      <td class="cell-content"><div align="right">20</div></td>
      <td class="cell-content"> 
        <div align="right">	  <form name="myform" action = "/Copy of onlinestore/manufacturer_test.php?id&quantity">
          <input name="quantity" type="text" class="form-input" size="5" maxlength="5" />
	  <input type="hidden" name="id" value="125744">
          <input name="Submit" type="submit" class="form-button" value="Add"/>
	  </form>
          </div>
            </td>
    </tr>
    <tr>
      <td class="cell-content">T3GANT</td>
      <td class="cell-content">Telsa 3G Datacard Antenna..........<A HREF="details.php?details=117883" TARGET = "mainFrame">More Details / Buy</A>.</td>
      <td class="cell-content">VODAFONE <<font SIZE=1> <A HREF="advanced_classification.php?advanced_class=VodaFone 3G Data Card"><br>VodaFone 3G Data Card<a></font></td>
      <td class="cell-content"><div align="right">15.73</div></td>
      <td class="cell-content"><div align="right">0</div></td>
      <td class="cell-content"> 
        <div align="right">	  <form name="myform" action = "/Copy of onlinestore/manufacturer_test.php?id&quantity">
          <input name="quantity" type="text" class="form-input" size="5" maxlength="5" />
	  <input type="hidden" name="id" value="117883">
          <input name="Submit" type="submit" class="form-button" value="Add"/>
	  </form>
          </div>
            </td>
    </tr>
    </div>
</body>
</html>

Regards
Dessie
 
sorry but i cannot see any anchors in your code.

remember the anchor must look like this
Code:
<a href="NAVMAN"></a>
 
so are you saying that i do not need the '#' character?

Code:
Go straight to product:<a href="#NAVMAN"> NAVMAN,</a><a href="#VODAFONE"> VODAFONE,</a>

Regards
Dessie
 
no no no !

an anchor is a point in your code that you want to "bookmark". you create the anchor by doing this
Code:
<a name="i_am_an_anchor"></a>

you can LINK to an anchor like this
Code:
<a href="#i_am_an_anchor">CLICK ME</a>

and you can even link to foreign anchors like that
Code:
<a href="somepage.php#i_am_an_anchor">CLICK ME</a>
 
Nope. A link to the anchor needs to look like this:
Code:
<a href="#name_of_anchor">Go to Name of Anchor</a>
However, this will not look for the words 'name_of_anchor' in your page but rather one of the following:
1. An anchor element with a name of 'name_of_anchor' like this: [tt] <a name="name_of_anchor"></a> or
2. An element with an id of 'name_of_anchor' like this: [tt]<td class="cell-content" id="name_of_anchor">Does not need to be exact text as in a link</td>

There is neither in your code. If you add anchors, you will notice that it will start working. I suggest example 2.
 
Hey guys,

I understand now that you have to create the anchor, Working great now, thanks for your time.

Regards
Dessie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top