Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Links in php code

Engaged ,
Mar 03, 2012 Mar 03, 2012

Copy link to clipboard

Copied

The following code lists countries and associated clubs:

<?php

$Current = $row_clubset['country_id']; // initialise variables

  echo '<p>' . $row_clubset['country_id'] . '<blockquote>'; // print the first country and set a block quote.

  do{

      // if it is not the same country, close the blockquote, print the Country  open a new blockquote and print the club name followed by a break

if ($Current<>$row_clubset['country_id']) echo  '</blockquote> <p>' . $row_clubset['country_id'] . '</P> <blockquote>'.'Visit the '.  $row_clubset['club_name'] . '<br>' ;

// else just print the club name followed by a break

else echo 'Visit the '.$row_clubset['club_name'] . '<br>' ;

// Set the current country to the value of the current country

$Current = $row_clubset['country_id'];

// now get the next record if there are any to get.

  } while ($row_clubset = mysql_fetch_assoc($clubset)); ?>

The output is as follows:

Germany

     Visit the Berlin Club

     Visit the Hanover Club

France

          Visit the Paris Club

I need to convert the "Visit" into a link..

The link should be like this:

<a href="viewclubs.php">visit the</a> without  a parameter.

And it produces this code, which does create the link and works fine but does not pass a parameter.to the next page.

if ($Current<>$row_clubset['country_id']) echo  '</blockquote> <p>' . $row_clubset['country_id'] . '</P> <blockquote>'.'<a href="viewclubs.php">visit the</a> '.  $row_clubset['club_name'] . '<br>' ;

The link should include a parameter and be like this:

<a href="viewclubs.php?pick=<?php echo $row_clubset['club_index']; ?>">Visit the </a>

When I wrap this link around the existing 'Visit the', I get the following line of code:

if ($Current<>$row_clubset['country_id']) echo  '</blockquote> <p>' . $row_clubset['country_id'] . '</P> <blockquote>'.'<a href="viewclubs.php?pick=<?php echo $row_clubset['club_index']; ?>">Visit the</a> '.  $row_clubset['club_name'] . '<br>' ;

This throws the following  error > Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'


I think that the probelm is caused by too many or the wrong sort of inverted commas of various sorts but I cannot work it out. Can anyone show me what is wrong?

TOPICS
Server side applications

Views

666
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 04, 2012 Mar 04, 2012

Copy link to clipboard

Copied

LATEST

I solved the problem in a way by using a different approach:

<table >

<?php do { ?>

  <tr>

    <td> </td>

    <td><?php if ($current<> $row_clubset['country_id']) echo $row_clubset['country_id']; ?></td>

    <td><?php echo $row_clubset['club_name']; ?></td>

    <td><a href="viewclubs.php?club_index=<?php echo $row_clubset['club_index']; ?>">View</a></td>

  </tr>

  <?php

    $current = $row_clubset['country_id'];

     } while ($row_clubset = mysql_fetch_assoc($clubset)); ?>

</table>

However, Dreamweaver attempts to interpret this as a repeat region server behaviour, which it basically is, as it uses similar code.

As a result, a red exclamation mark appears in the server behaviour panel.

I deleted the behaviour and then inserted my own code. Dreamweaver again recognised it as a behaviour.

The code validates and works fine, so I will just have to remember to ignore the exclamation mark if I ever need to edit the page.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines