Jump to content


Photo

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


  • Please log in to reply
1 reply to this topic

#1 weaksauce

weaksauce
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 July 2006 - 02:10 AM

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.

#2 CheesierAngel

CheesierAngel
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationBelgium

Posted 06 July 2006 - 02:14 PM

A solution can be:

<?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;
?>

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

Hope this helps you out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users