SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using the SELECT * Command

    Hello,

    I have the following code listed below, but it is only displaying one entry. Hoping you can help!

    <?php

    // Select WSR Database
    mysql_select_db("wsrskitites");

    // Retrieve all the data from the skisites table
    $result = mysql_query("SELECT * FROM skisites")
    or die(mysql_error());

    echo "<table border='1' width='650' cellpadding='0' cellspacing='0'>

    <tr bgcolor='#333333'>
    <th valign='top'><p align='center' class='title'><b>State</b></p></th>
    <th valign='top'><p align='center' class='title'><b>City</b></p></th>
    <th valign='top'><p align='center' class='title'><b>Ski Site</b></th>
    <th valign='top'><p align='center' class='title'><b>Website Address</b></p></th>
    <th valign='top'><p align='center' class='title'><b>Contact Info</b></p></th>
    </tr>";

    // store the record of the skisites table into $row
    $row = mysql_fetch_array( $result );
    // Print out the contents of the entry

    {
    echo "<tr>";
    echo "<td>".$row['State'] ."</td>";
    echo "<td>".$row['City'] ."</td>";
    echo "<td>".$row['Site_Name'] ."</td>";
    echo "<td>".$row['Website'] ."</td>";
    echo "<td>".$row['Contact'] ."</td>";
    echo "</tr>";
    }

    echo "<br>";

    echo "</table>";

    ?>

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,028
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    You need to loop through until there are no more matches left using a while loop:

    PHP Code:
    while ($row mysql_fetch_array$result )) {
    <
    code to display results>

    It will keep looping through until mysql_fetch_array() returns false, meaning that there are no results left to display.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much for answering my question! I don't know how many more you are interested in but I will post a couple of other challenges:

    1. I want to take my list and divide them out by state but I want it to have a format like this:

    5 Columns and the title of the column put in when a new set of listings starts for a state by state basis. Someone told me that I could type one line of code and it's possible but I'm not sure. If not, I do know how to break it out with WHERE state=""

    2. I have a column for email addresses and one for website addresses, and instead of displaying someonesname@somedomain.com , I want to put "EMAIL" or something in it's place. I'll do the same for a website listing and link them up but not all entries have a website or email address so I don't want a link created if there is no address behind them.

    Thanks again for your time! It's greatly appreciated.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,028
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by djl631981 View Post
    Thanks so much for answering my question! I don't know how many more you are interested in but I will post a couple of other challenges:

    1. I want to take my list and divide them out by state but I want it to have a format like this:

    5 Columns and the title of the column put in when a new set of listings starts for a state by state basis. Someone told me that I could type one line of code and it's possible but I'm not sure. If not, I do know how to break it out with WHERE state=""

    2. I have a column for email addresses and one for website addresses, and instead of displaying someonesname@somedomain.com , I want to put "EMAIL" or something in it's place. I'll do the same for a website listing and link them up but not all entries have a website or email address so I don't want a link created if there is no address behind them.

    Thanks again for your time! It's greatly appreciated.

    1. You would need to use an 'ORDER BY' clause to group the records in order of the state. I'm not sure if you can add the column headings after each group of records for a state, with the 'ORDER BY' clause, you might well need to loop through an array of states (in the order that you want them in), where each time the column names are printed and the records for that state are then printed with the state name that the loop as reached from the array being passed to the query for the 'WHERE' clause.
    2. For the email address, i think your looking at in the loop that displays the records, where it comes to the display of the email address something like:
      PHP Code:
      if ($email == null) {
          echo 
      'No E-mail Address';
      } else {
          echo 
      "<a href='$mail'>e-mail</a>";


    Hope that helps.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again for your feedback. I have been busy and haven't had a chance to try this yet, but I will and let you know what worked. Thanks!

  6. #6
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help and and I want to post the code, but this forum won't let me post a link and that is included in my code


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •