SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need PHP Help - Simple Query

    Hi,

    Simple php question. I keep playing around and getting errors, so I thought I should ask the pros to save me some time and headaches...

    In the script below, how would I get the results to only show names with $price greater than or equal to 99? It seems simple enough, but I keep screwing it up.

    Thanks a lot,

    Doug

    ---------- script ----------------

    <?
    mysql_connect("localhost","xxxxxxxx","xxxxxxx");
    mysql_select_db("thedatabase");

    $query = "SELECT * FROM my_domains ORDER BY name";
    $result = mysql_query($query);

    echo "<html><body bgcolor=\"#FFFFFF\"><table border=\"0\" align=\"center\" width=\"600\" cellspacing=\"0\" cellpadding=\"2\"><tr><td><b>Domain</b></td><td><b>Price</b></td></tr>";
    while($row = mysql_fetch_array($result))
    {
    $price = $row['priceb'];
    $domain = $row['name'];

    echo "<tr><td>$domain</td><td>$price</td><td><a href=\"mailto:$domain@mywebsite.com?subject=$domain\">Contact Us</a></td></tr>";
    }

    echo "</table></body></html>";

    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    PHP Code:
    $query "SELECT * FROM my_domains WHERE price =< 99 ORDER BY name"
    $result mysql_query($query); 
    That should work. Price should of cource be the column name with the price in it, I assumed you just called it price.

  3. #3
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got this error...

    Warning: Supplied argument is not a valid MySQL result resource in .../ on line 30

    Line 30...
    while($row = mysql_fetch_array($result))

  4. #4
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work...

    I just changed

    "WHERE price =< 99 ORDER BY name"

    to

    "WHERE price >= 99 ORDER BY name"

    and it worked!

    Thanks Mark for your help!

    Doug

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, did I make a stupid mistake there !

    The price had to be bigger, and in stead I placed the greater then symbol at the wrong side of the =. I was already staring at your code what could be wrong, and couldn't find a thing.

    Thanks for telling me this , and good luck with the website !

  6. #6
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mark! I would have never gotten it to work without your help!

    Doug

  7. #7
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi All...

    In the code above... Is there a way to make it so when you view the
    source code it separates the table rows in nice organized html?

    ie...

    <tr><td>name1.com</td><td>$25.00</td><td><a href="mailto:name1.com@mywebsite.com?subject=name1.com">Contact Us</a></td></tr>

    <tr><td>name2.com</td><td>$25.00</td><td><a href="mailto:name2.com@mywebsite.com?subject=name2.com">Contact Us</a></td></tr>

    <tr><td>name3.com</td><td>$25.00</td><td><a href="mailto:name3.com@mywebsite.com?subject=name3.com">Contact Us</a></td></tr>

    instead of...

    <tr><td>name1.com</td><td>$25.00</td><td><a href="mailto:name1.com@mywebsite.com?subject=name1.com">Contact Us</a></td></tr><tr><td>name2.com</td><td>$25.00</td><td><a href="mailto:name2.com@mywebsite.com?subject=name2.com">Contact Us</a></td></tr><tr><td>name3.com</td><td>$25.00</td><td><a href="mailto:name3.com@mywebsite.com?subject=name3.com">Contact Us</a></td></tr>


    Thanks as always,

    Doug

  8. #8
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where you're echo()ing out the HTML in the while() loop, just add a "\n" after the </tr>. that'll put a newline in the HTML source.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  9. #9
    I LOVE THIS SITE ! ! ! DougD's Avatar
    Join Date
    May 2000
    Location
    San Diego, CA
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    It worked perfectly... Much appreciated!

    I just ordered Kevin's book about 5 minutes ago... I can't wait to get it. Hopefully, I will get much better at this PHP stuff!

    Thanks again,

    Doug


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
  •