1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Show only results that start with "A"

Discussion in 'PHP' started by Al Capone, Aug 19, 2005.

  1. #1
    Here's what I am trying to do, I am trying to display the $query but I only want to display the $query's that begin with the letter "A"

    Can someone tell me if this is possible and if so how can I do this? Thank you very much in advance.
     
    Al Capone, Aug 19, 2005 IP
  2. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #2
    Change the SQL to
    
    SELECT * FROM `searchtable` [B]WHERE query like 'a%'[/B] ORDER BY `query` ASC
    
    Code (markup):
     
    dct, Aug 19, 2005 IP
  3. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #3
    SWEEEEEEEEEEEEEEET Thank so much man, I love this forum, i think you guys are the best, (shouldn't mean much but o'well) but still thanks so much man :) can't tell you how greatful I am :) thanks again WOW ! :)
     
    Al Capone, Aug 19, 2005 IP
  4. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #4
    Yooooouuuuuuuur welcome
     
    dct, Aug 19, 2005 IP
  5. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Sorry, one more question, what if I wanted to do, lets say... XYZ like 3 letters instead of one, thanks in advance :)
     
    Al Capone, Aug 19, 2005 IP
  6. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #6
    Change the SQL to

    Change the SQL to
    
    SELECT * FROM `searchtable` 
    [B]WHERE query like 'x%' OR query like 'y%' OR query like 'z%'[/B] 
    ORDER BY `query` ASC
    
    Code (markup):
     
    dct, Aug 19, 2005 IP
  7. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #7
    Thanks so much, I am still having a problem, theres to many results per page, is there anyway to split them into like 100 per page, I am kind of new to php.
     
    Al Capone, Aug 19, 2005 IP
  8. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #8
    You will need to use the limit clause
    e.g.
    
    SELECT * FROM `searchtable` 
    WHERE query like 'x%' OR query like 'y%' OR query like 'z%' 
    ORDER BY `query` ASC
    [B]LIMIT 10, 5[/B]
    
    Code (markup):
    This would return 5 rows starting from position 10.
     
    dct, Aug 19, 2005 IP
  9. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #9
    Ok thanks so much, what I was trying to do was like this site here: h**p://www.edcomp.com/sitemap.aspx did but I am guessing that's more complicated then I think since there like different pages and stuff, thanks for all your help.
     
    Al Capone, Aug 19, 2005 IP
  10. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #10
    You can do that with what I've posted, it's fairly simple to do you will just need to pass the letter and page number on the URL and then build the SQL from those parameters. If you experiment a bit I'm sure you'll get there and if yet get stuck feel free to post more questions here.
     
    dct, Aug 19, 2005 IP
  11. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #11
    Ok, I did this right now:

    <?php

    $dbase['host'] = 'localhost';
    $dbase['user'] = 'pgn_SEARCH';
    $dbase['pass'] = '***';
    $dbase['name'] = 'pgn_SEARCH';

    $dblink = mysql_connect($dbase['host'], $dbase['user'],$dbase['pass']);
    mysql_select_db($dbase['name'], $dblink);

    //Now for the displaying stuff
    $getit = mysql_query("SELECT * FROM `searchtable` ORDER BY `time` desc LIMIT 2, 10") or die(mysql_error());
    while($get = mysql_fetch_array($getit))
    {
    $query = $get['query'];
    $query = str_replace(" ", "-", $query);
    $query = str_replace("?", "-", $query);
    $query = str_replace("#", "-", $query);
    $query = str_replace("}", "-", $query);
    $query = str_replace("{", "-", $query);
    $query = str_replace("%", "-", $query);
    $query2 = $get['query'];
    $time = $get['time'];
    $ftime = $get['ftime'];
    echo("<p><font size=-1><A href='/e-$query.htm'>$query2</a></font></P>");
    }
    ?>

    now what do I do, whats pass the letter and page number on the url then build the sql to those perameters means, I really want to do this I hope you'll help me :) I know I am dumb I am just 16 and starting but I am really learning quick (Thanks to you and other helpful members here :))
     
    Al Capone, Aug 19, 2005 IP
  12. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #12
    On the URL you need to pass the letter and page no, so the URL would look like
    
    links.php?letter=a&page=4
    
    Code (markup):
    Which would mean you want to look at page 4 of the letter As. Then in the code do something like
    
    $Letter = $_GET['letter'];
    $Page = $_GET['page'];
    
    $ListingsPerPage = 5;
    
    $lStartRow = ($Page - 1) * $ListingsPerPage;
    
    $lSQL = "SELECT * FROM `searchtable` 
    WHERE query like '$Letter%'
    ORDER BY `query` ASC
    LIMIT $lStartRow, $ListingsPerPage";
    
    PHP:
    I've not tested this but it should give you the general idea.
     
    dct, Aug 19, 2005 IP
  13. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #13
    I did this:

    <?php

    $dbase['host'] = 'localhost';
    $dbase['user'] = 'pgn_SEARCH';
    $dbase['pass'] = '***';
    $dbase['name'] = 'pgn_SEARCH';

    $dblink = mysql_connect($dbase['host'], $dbase['user'],$dbase['pass']);
    mysql_select_db($dbase['name'], $dblink);

    //Now for the displaying stuff
    $Letter = $_GET['letter'];
    $Page = $_GET['page'];

    $ListingsPerPage = 5;

    $lStartRow = ($Page - 1) * $ListingsPerPage;

    $lSQL = "SELECT * FROM `searchtable`
    WHERE query like '$Letter%'
    ORDER BY `query` ASC
    LIMIT $lStartRow, $ListingsPerPage";

    {
    $query = $get['query'];
    $query = str_replace(" ", "-", $query);
    $query = str_replace("?", "-", $query);
    $query = str_replace("#", "-", $query);
    $query = str_replace("}", "-", $query);
    $query = str_replace("{", "-", $query);
    $query = str_replace("%", "-", $query);
    $query2 = $get['query'];
    $time = $get['time'];
    $ftime = $get['ftime'];
    echo("<font size=-1><A href='/e-$query.htm'>$query2</a></font> ");
    }


    ?>

    But I am not getting any results when I use links.php?letter=a&page=1 just a white page, I should be getting apple and a couple other words with a as results, did I do something wrong? By the way, thanks so much for taking the time to help me, I really do appreciate it.
     
    Al Capone, Aug 19, 2005 IP
  14. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #14
    echo out the SQL that is generated and post it here.
     
    dct, Aug 19, 2005 IP
  15. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #15
    It's 5:15 AM my mom just woke up and is yelling at me I got to go I will be back tomarrow morning, thanks so much for all your help, I really do appreciate it, if you find out whats wrong please tell me I would be extremely greatful.

    Thank you again.
     
    Al Capone, Aug 19, 2005 IP
  16. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #16
    not sure what echo out means
     
    Al Capone, Aug 19, 2005 IP
  17. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #17
    hmmm, you already use it in your code. Just do
    
    echo $lSQL;
    
    PHP:
     
    dct, Aug 19, 2005 IP
  18. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #18
    Man I am such a dumbass and I feel like I am frustrating you, I still don't know what your asking, I'm sorry if I am a dumbass :( I know how frustrating it must be for you



    I typed

    <?php

    $dbase['host'] = 'localhost';
    $dbase['user'] = 'pgn_SEARCH';
    $dbase['pass'] = '***;
    $dbase['name'] = 'pgn_SEARCH';

    $dblink = mysql_connect($dbase['host'], $dbase['user'],$dbase['pass']);
    mysql_select_db($dbase['name'], $dblink);

    echo $lSQL;


    ?>

    in there is that what u were asking, i just see blank page
     
    Al Capone, Aug 19, 2005 IP
  19. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #19
    You missed the
    
    $lSQL = "SELECT * FROM `searchtable`
    WHERE query like '$Letter%'
    ORDER BY `query` ASC
    LIMIT $lStartRow, $ListingsPerPage"; 
    
    PHP:
    Do

    
    <?php
    
    $dbase['host'] = 'localhost';
    $dbase['user'] = 'pgn_SEARCH';
    $dbase['pass'] = '***';
    $dbase['name'] = 'pgn_SEARCH';
    
    $dblink = mysql_connect($dbase['host'], $dbase['user'],$dbase['pass']);
    mysql_select_db($dbase['name'], $dblink);
    
    //Now for the displaying stuff
    $Letter = $_GET['letter'];
    $Page = $_GET['page'];
    
    $ListingsPerPage = 5;
    
    $lStartRow = ($Page - 1) * $ListingsPerPage;
    
    $lSQL = "SELECT * FROM `searchtable`
    WHERE query like '$Letter%'
    ORDER BY `query` ASC
    LIMIT $lStartRow, $ListingsPerPage"; 
    
    echo $lSQL;
    
    PHP:
     
    dct, Aug 19, 2005 IP
  20. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #20
    thats all i see on the page

    Full code as of now:

     
    Al Capone, Aug 19, 2005 IP