Jump to content

I'm so new to php that I'm not even sure how to effectively ask this question...


Recommended Posts

If anyone could provide me some help, it would be much appreciated.  I'd imagine this will require the most basic of answers, and even then it will undoubtedly be over my head.  Anyway...

I've put together a database table of schools.  My repeating table on the page currently displays the school_name, school_city, and school_state.  There is another column in my table, school_link, that contains a url to a page outside my site.  I'd like to have the school_name display, but have it serve as the link to that external page.  Since each link for each school is different, it's not as easy as just assigning an href to that particular spot where the school_name is set to appear.

This is what I've tried (for my Alabama schools page):

<a href="<?php echo $school_link; ?>"><?php echo $row_rsAlabama['school_name']; ?>

And this is my currently defined recordset:

$query_rsAlabama = "SELECT school_name, school_city, school_link, school_state FROM schools_tbl WHERE school_state = 'AL' AND school_active = '1' ORDER BY school_city ASC";

This obviously doesn't work, but I thought I'd let whoever was considering helping me know where I'm starting from in terms of help needed.  I would appreciate ANY guidance I could get in this matter.  Thanks for taking the time to read my super long and boring first post.
Link to comment
Share on other sites

A solution can be:

[code]
<?php

  // ORDER BY ... ASC =:> ASC is the mysql default so it's not needed to mention
  $query = <<<SQL
      SELECT school_name, school_link
      FROM schools_tbl
      WHERE school_state = 'AL'
        AND school_active = '1'
      ORDER BY school_city
SQL;
  $results = mysql_query($query);
  while($result = mysql_fetch_object($results) {
      $output .= "<a href='{$result->school_link}'>{$result->school_name}</a><br>";
  }

  echo $output;
?>
[/code]

This will output all school names as a link on a new line.

Hope this helps you out.
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.