SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32

Thread: Searching!!!

  1. #26
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Koncise remember when I told you to print the query to the screen and then copy and paste into the command line mysql or phpMyAdmin. this is where this can come in handy to see if your query is returning any rows. Alternately you can put in a little checking to see if any rows were returned

    PHP Code:
    $result mysql_query("SELECT group_name, category, city, region from Groups 
    WHERE group_name like '%
    $group_name%' 
    AND category like '%
    $category%' 
    AND city like '%
    $city%' 
    AND region like '%
    $region%' order by group_name") OR die (mysql_error()); 

    //Start results formatting 
    echo "<TABLE BORDER=3>"

    echo 
    "<tr><th>group_name</th><th>category</th><th>city</th><th>region</th></tr>"

    if(
    mysql_num_rows($result) > 0) {
    while (
    $row mysql_fetch_array($result) ) { 


    $group_name $row["group_name"]; 
    $category $row["category"]; 
    $city $row["city"]; 
    $region $row["region"]; 

    echo 
    "<tr><td>$group_name</td><td>$category</td><td>$city</td><td>$region</td></tr>"


    }
    else {
    print 
    "No records found";

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  2. #27
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much Freddy.

    I tried the code and no results were returned, however the "No records found" message which was meant to be printed did not appear either....

    I've just about had it with this, I'm very very tired with all of it.

    I have been considering the whole concept of a search facility for my database. I came to the conclusion that it would'nt be detremental if my site did not contain a search facility.
    Instead I could have a whole series of views which visitors to my site can use to view particular aspects of my database in particular orders. For example I could have two drop down lists which contain the variopus regions and categories of groups within my database. I could present a series of views depending upon what combination of category and region was selected, e.g. 'London' and 'Jazz' or 'Scotland' and 'Chior'.

    I already have a number of views in place which visitors can view the groups within my database already. These existing views (plus some additional ones) could eliminate the need for a database search facility.

    I really appreciate all the help that I have recieved and I don't want to become a pain to all who have helped me.

    The immense frustration I have experienced over this function has finally got to me; I have spent way too much time on this and my deadline for the project is creeping up on me!

    Thanx again,

    (A very humbled) Koncise.

  3. #28
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by FatPiper
    I think the reason it returned missing mysql resource is because you're missing a semicolon at the end of your SQL.
    No - PHP doesn't want a semicolon at the end of the statement.

  4. #29
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    really??? hmm ... It's never given me an error when I put one, and for some odd reason it doesn't work when I don't. Perhaps its just the thingy I've got on my computer or something, but all of my sql's have ;'s in them, and they work fine. That's interesting ... is it the same in php3? or do all php versions have no semi-colon?

    ... what's the world coming to?

  5. #30
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I have ever experienced, I only need a semicolon on the end of an sql statement when running it from the mysql command line, I have never put it in my actual php code when making queires. In fact I just tried putting one in and got a parse error.

    Thats is strange that it works for you.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #31
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FatPiper - that is freaky. The PHP manual http://www.php.net/manual/en/function.mysql-query.php has this to say:

    Note: The query string should not end with a semicolon.

  7. #32
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How odd. I just checked my CMS to be sure, and yes, I have a semi-colon at the end of every single SQL statement. I then checked to see if it was working (its still in development .. ), and yes it works perfectly, and I can login, view, add and delete articles, signup, add comments, vote on polls, etc.. And EVERY SINGLE ONE of my SQL statements has semi-colon on it!! I usually build them like this
    PHP Code:
    $server "localhost";
    $user"dbuser";
    $pass="dbpass";
    $database "database";
    $dblink mysql_connect($server,$user,$pass);
    mysql_select_db($database);
    $query="SELECT * FROM $tblname ";
    $query.= "WHERE blah='blabla'";
    $query.= ";";
    $result mysql_query($query); 
    And it works fine (I swear!! )
    Last edited by FatPiper; Mar 21, 2001 at 11:29.

    ... what's the world coming to?


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
  •