suttercain Posted February 26, 2007 Share Posted February 26, 2007 I did a search on google and seem to be getting conflicting answers. If it is possible can someone point me to a tutorial that is valid for PHP 5? Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/ Share on other sites More sharing options...
Orio Posted February 26, 2007 Share Posted February 26, 2007 What do you mean? Do you mean start running a script from a certain line? Orio. Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-194620 Share on other sites More sharing options...
suttercain Posted February 26, 2007 Author Share Posted February 26, 2007 Lets say I have a list of anchor links, in HTML Turtle, Elephant, Duck, etc. And I have a php echoed table way way further down in the page with one title Turtle. How can I make it so if someone clicks the "Turtle" link at the top of the page it takes them way further down the page to the Turtle table. I know how to do this using HTML but not PHP. Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-194652 Share on other sites More sharing options...
JBS103 Posted February 26, 2007 Share Posted February 26, 2007 I'm unsure you can do this explicitly, but you could of course use a variety of If statements and functions to scroll down the page until a stopping point where it continues to parse code. Interested to see if there is, but I'm doubting it. Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-194659 Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 there is no difference. Just use the html code, and if you have to, substitute value into the code. With php you are just echo'ing out html code anyways. What makes php different, is you can loop though and echo out ALOT of html code. Ray Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-194668 Share on other sites More sharing options...
ShogunWarrior Posted February 26, 2007 Share Posted February 26, 2007 In your output, to place an anchor which you should be able to jump to you would write: <a name="nameofanchor"></a> And to make a link to that anchor: <a href="#nameofanchor">Link to anchor</a> Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-194737 Share on other sites More sharing options...
suttercain Posted April 6, 2007 Author Share Posted April 6, 2007 So I hadn't touched the idea since I asked this a couple months back. Tonight I was watching Lost on my TIVO and I thought of this. Works pretty good. It generates a table from MySQL and assigns the anchor property of <a name='$variable'></a> to the table header. I then echoed the list of all possible table header names and used <a href='#" . $makes[$current] . "'>$makes[$current]</a> to get it working. Here is the entire code for newbies like myself that may want to try it: <?php //Connect to the Database via the Include File! require ('get_connected.php'); // Perform a statndard SQL query: $res = mysql_query("SELECT UPPER(vehicle) AS vehicle FROM cars ORDER BY vehicle ASC") or die (mysql_error()); // GENERIC CODE FOR THE ANCHORS $makes = array('ACR'=>'ACURA', 'TOY'=>'TOYOTA', 'SAT'=>'SATURN'); print $makes[$row['vehicle']]; //CSS for the Alternating Color Rows $current = ''; while($row = mysql_fetch_array($res)) { if($current != $row['vehicle']) { $current = $row['vehicle']; echo "<a href='#" . $makes[$current] . "'>$makes[$current]</a>\n"; } } //Convert Vehicle Column to out put from the MySQL instead of HTML $sql = mysql_query("SELECT UPPER(vehicle) AS vehicle, sub_class, disp, fuel FROM cars ORDER BY vehicle ASC") or die (mysql_error()); $current = ''; while($row = mysql_fetch_array($sql)) { if($current != $row['vehicle']) { $current = $row['vehicle']; echo "<table width='100%' border='0' bgcolor=#CCCCCC cellpadding='1' cellspacing='1'> <tr> <td width='70'><b>$makes[$current]</b><a name='$makes[$current]'></a></td> <td width='55'><b>FUEL</b></td> <td width='110'><b>DISPLACEMENT</b></td> </tr><br>"; } //Continuation of CSS for the Alternating Color Rows $class = $class == 'even' ? 'odd' : 'even'; //Populate the Tables from the Database echo "<tr class=\"$class\">\n"; echo "<td>$row[sub_class]</td>\n"; echo "<td>$row[disp] L</td>\n"; echo "<td>$row[fuel]</td>\n"; echo "</tr>\n"; } ?> I am not sure if the is the best way to do it, but it works. Link to comment https://forums.phpfreaks.com/topic/40218-out-of-curiosity-can-you-make-anchors-in-php-like-in-html/#findComment-222724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.