47 users online (1 members and 46 guests)  


Page 1 of 2 1 2 Last
  Results 1 to 15 of 25

Related

  1. Replies: 1
  2. need help displaying results with links    Forum: PHP Forum
    Replies: 0
  3. Replies: 4
  4. Displaying Paged Results In A Table    Forum: Javascript Forum
    Replies: 4
  5. google search results    Forum: HTML Forum
    Replies: 1
  1. #1
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    PHP displaying search results

    I am using a drop down menu to select my search criteria from a mysql database. I can display only the first result. Need to display all that fit the search criteria.

    This is the code:

    <?
    // Connect database
    mysql_connect("localhost","user","pass");
    mysql_select_db("members");

    // If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
    if(isset($select)&&$select!=""){
    $select=$_GET['select'];
    }
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <form ID="form1" Category Listing"form1" method="get" action="<? echo $PHP_SELF; ?> ">
    Selections :
    <select name="select">
    <option value="">--- Select ---</option>
    <?
    // Get records from database (table "member_list").
    $list=mysql_query("select * from member_list order by id asc");

    // Show records by while loop.
    while($row_list=mysql_fetch_assoc($list)){
    ?>
    <option value="<? echo $row_list['ID']; ?>" <? if($row_list['ID']==$select){ echo "selected"; } ?>><? echo $row_list['Category Listing']; ?></option>
    <?
    // End while loop.
    }
    ?>
    </select>
    <input type="submit" name="Submit" value="Select" />
    </form>
    <hr>
    <p>
    <?
    // If you have selected from list box.
    if(isset($select)&&$select!=""){

    // Get records from database (table "member_list").
    $result=mysql_query("select * from member_list where ID='$select'");
    $row=mysql_fetch_assoc($result);


    ?>




    Information about <strong><? echo $row['Customer']; ?></strong> company...</p>



    <?
    // End if statement.
    }



    // Close database connection.
    mysql_close();
    ?>
    </p>
    </body>
    </html>

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    From what i can see of this code... there is nothing wrong with it.

    are any results showing? because if not you may have a typo in you sql statment (maybe like the table name is different).

    Other than that it looks fine.

    as for a php tip... a quick trick to the <??> tags is...

    <?="hello";?> will do the same as: <? echo "hello";?> just a quick trick some times it can save alot of time.

  3. #3
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    It only shows one result. Need to show all that match search criteria.

  4. #4
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    if you dont have phpmyadmin installed... install it...

    then go into it and try running this sql:

    select * from member_list order by id asc

    how many does it return?

  5. #5
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    It returns all matches.

  6. #6
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    well i dont know what to say, because i don't see anything wrong with it. Did you check the raw html to see if it does what it says it does.

    if i would try anything else try changing:

    while($row_list=mysql_fetch_assoc($list)){

    to:

    while($row_list=mysql_fetch_array($list, MYSQL_ASSOC)){

    but i doubt that will change anything

  7. #7
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: displaying search results

    Quote Originally Posted by rdub
    Code:
    // If you have selected from list box. 
    if(isset($select)&&$select!=""){ 
    
    // Get records from database (table "member_list"). 
    $result=mysql_query("select * from member_list where ID='$select'"); 
    $row=mysql_fetch_assoc($result); 
    
    ?> 
    
    Information about <strong><? echo $row['Customer']; ?></strong> company...</p> 
    
    <? 
    // End if statement. 
    } 
    
    // Close database connection. 
    mysql_close(); 
    ?>
    Shouldn't that be
    Code:
    // If you have selected from list box. 
    if(isset($select)&&$select!=""){ 
    
    // Get records from database (table "member_list"). 
    $result=mysql_query("select * from member_list where ID='$select'"); 
    while($row=mysql_fetch_assoc($result)) {
    
    ?> 
    
    Information about <strong><? echo $row['Customer']; ?></strong> company...</p> 
    
    <? 
    // End While statement
    }
    // End if statement. 
    } 
    
    // Close database connection. 
    mysql_close(); 
    ?>
    to show multiple records?

  8. #8
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    Quote Originally Posted by DeadMeatGF
    Shouldn't that be
    Code:
    // If you have selected from list box. 
    if(isset($select)&&$select!=""){ 
    
    // Get records from database (table "member_list"). 
    $result=mysql_query("select * from member_list where ID='$select'"); 
    while($row=mysql_fetch_assoc($result)) {
    
    ?> 
    
    Information about <strong><? echo $row['Customer']; ?></strong> company...</p> 
    
    <? 
    // End While statement
    }
    // End if statement. 
    } 
    
    // Close database connection. 
    mysql_close(); 
    ?>
    to show multiple records?
    I thought the same thing at first... however usually when somone does "WHERE ID = something" usually they are looking for only 1 item.

  9. #9
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    Displays only one record.

    The query is good. I'm missing something with the display.

  10. #10
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    If I change this line
    $result=mysql_query("select * from member_list where ID='$select'");
    To this
    $result=mysql_query("select * from member_list");
    It displays all results. The problem is I need it to display all of the results of $select from a drop down menu.

  11. #11
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    ok... now i am lost... unless your database is configured different than normal... the "ID" field 99% of the time is unique...

    so from the sounds of it.. $select should be an array, but there is no indication of an array because <option does not send arrays.

    is there a place that we can view the page to see exacly the problem?

  12. #12
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    This is the page generated by the basic script.

    http://host557.ipowerweb.com/~idyllwil/test_back_members_b.php

  13. #13
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    ok try this:

    PHP Code:
    <? 
    // Connect database 
    mysql_connect("localhost","user","pass"); 
    mysql_select_db("members"); 

    // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. 
    if(isset($select)&&$select!=""){ 
    $select=$_GET['select']; 

    ?> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    </head> 
    <body> 
    <form ID="form1" Category Listing"form1" method="get" action="<? echo $PHP_SELF?> "> 
    Selections : 
    <select name="select"> 
    <option value="">--- Select ---</option> 
    <? 
    // Get records from database (table "member_list"). 
    $list=mysql_query("select * from member_list order by id asc"); 

    // Show records by while loop. 
    while($row_list=mysql_fetch_assoc($list)){ 
    ?> 
    <option value="<? echo $row_list['ID']; ?><? if($row_list['ID']==$select){ echo "selected"; } ?>><? echo $row_list['Category Listing']; ?></option> 
    <? 
    // End while loop. 

    ?> 
    </select> 
    <input type="submit" name="Submit" value="Select" /> 
    </form> 
    <hr> 
    <p> 
    <? 
    // If you have selected from list box. 
    if(isset($select)&&$select!=""){ 

    // Get records from database (table "member_list"). 
    $result=mysql_query("select * from member_list where ID='$select'"); 
    while(
    $row=mysql_fetch_assoc($result)){


    ?> 




    Information about <strong><? echo $row['Customer']; ?></strong> company...</p> 



    <? 
    }
    // End if statement. 




    // Close database connection. 
    mysql_close(); 
    ?> 
    </p> 
    </body> 
    </html>

  14. #14
    rdub's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    15

    Re: displaying search results

    You can see the results here
    http://host557.ipowerweb.com/~idyllwil/test_back_members_c.php

    It still displays only one record.

  15. #15
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: displaying search results

    ok then lets see the sql database...



Page 1 of 2 1 2 Last

Tags for this Thread