Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: While Help!

  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    While Help!

    I have some code:

    PHP Code:
              <?php
    $connect  
    = @mysql_connect("localhost","root","root") or die("Could not connect to database");
    $db          = @mysql_select_db("restfind");
    $query =  "SELECT *  
    FROM places  
    WHERE `name` LIKE '%{$_GET['q']}' 
    OR `description` LIKE '%{$_GET['q']}' 
    "
    ;  
    $mksql     =@mysql_query($query);
    $fetch     =@mysql_fetch_array($mksql);
    @
    mysql_free_result($mksql);
    @
    mysql_close($connect);
    ?>


          <table width="700" height="65" border="0" cellpadding="0" cellspacing="0" class="result">
            <tr>
              <td width="178" align="center" valign="middle"><div align="center"><?php echo $fetch['name']; ?> </div></td>
              <td width="121" align="center" valign="middle"><div align="center"><?php echo $fetch['phone']; ?> </div></td>
              <td width="163" align="center" valign="middle"><div align="center"><?php echo $fetch['description']; ?> </div></td>
              <td width="103" align="center" valign="middle"><div align="center"><?php echo $fetch['address']; ?><br />
                    <?php echo $fetch['town']; ?><br />
                <?php echo $fetch['city']; ?></div></td>
              <td width="135" align="center" valign="middle"><div align="center"><a href="http://<?php echo $fetch['website']; ?>" class="search">Website</a></div></td>
            </tr>
          </table>
          </div></td>
        </tr>
      </table>
    rite i need to do a while on the the table so it displays all the results not just one! Please help i have searched but cant find anything!!!

  • #2
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    C'Mon Please

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    while($fetch = mysql_fetch_array($mksql)) {
    
    //loop
    
    }
    I suggest using pear functions with your database to help further your knowledge and keep things simple .

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Unless you need the field numbers use mysql_fetch_assoc(), and you have to move your mysql_free_result() & mysql_close() after your while.

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Quote Originally Posted by iLLin View Post
    Code:
    while($fetch = mysql_fetch_array($mksql)) {
    
    //loop
    
    }
    I suggest using pear functions with your database to help further your knowledge and keep things simple .
    I'd only use PEAR if you really need it. In this case I don't think he would benefit at all from it.

  • #6
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    hi my code is now:

    PHP Code:
              <?php
    $connect  
    = @mysql_connect("localhost","root","root") or die("Could not connect to database");
    $db          = @mysql_select_db("restfind");
    $query =  "SELECT *  
    FROM places  
    WHERE `name` LIKE '%{$_GET['q']}' 
    OR `description` LIKE '%{$_GET['q']}' 
    "
    ;  
    $mksql     =@mysql_query($query);


    ?>
              <br />
              <div class="line"></div>
              <table width="700" border="0" cellspacing="0" cellpadding="0" class="result">
      <tr>
        <td width="178"><div align="center">Resturaunt Name:</div></td>
        <td width="121"><div align="center">Phone:</div></td>
        <td width="163"><div align="center">Description:</div></td>
        <td width="103"><div align="center">Address:</div></td>
        <td width="135"><div align="center">Website:</div></td>
      </tr>
    </table>
     
      
          <br />
          
          <div class="line"></div>
    <?php

    $website 
    $fetch["website"];
    $address $fetch["address"];
    $town $fetch["town"];
    $city $fetch["city"];
    $name $fetch["name"];
    $phone $fetch["phone"];
    $description $fetch["description"];



    while(
    $fetch mysql_fetch_array($mksql)) {

    //Result Loop
         
    echo '<table width="700" height="65" border="0" cellpadding="0" cellspacing="0" class="result">
            <tr>
              <td width="178" align="center" valign="middle"><div align="center">'
    .$name.' </div></td>
              <td width="121" align="center" valign="middle"><div align="center">'
    .$phone.' </div></td>
              <td width="163" align="center" valign="middle"><div align="center">'
    .$description.' </div></td>
              <td width="103" align="center" valign="middle"><div align="center">'
    .$address.'<br />
                    '
    .$town.'<br />
               '
    .$city.'</div></td>
              <td width="135" align="center" valign="middle"><div align="center"><a href="http://'
    .$website.'" class="search">Website</a></div></td>
            </tr>
          </table>'
    ;
          
    }


              
    ?>          

    <?php
    @mysql_free_result($mksql);
    @
    mysql_close($connect);
    ?>

    and it only displays blank tables and doesent put the info in them how can i make it so it puts the info in it!

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Delete this
    PHP Code:
    $website $fetch["website"];
    $address $fetch["address"];
    $town $fetch["town"];
    $city $fetch["city"];
    $name $fetch["name"];
    $phone $fetch["phone"];
    $description $fetch["description"]; 
    Then use extract() as you're doing it that way
    PHP Code:
    while($fetch mysql_fetch_array($mksql)) {
    extract($fetch);
    //Result Loop
         
    echo '<table width="700" height="65" border="0" cellpadding="0" cellspacing="0" class="result">
            <tr>
              <td width="178" align="center" valign="middle"><div align="center">'
    .$name.' </div></td>
              <td width="121" align="center" valign="middle"><div align="center">'
    .$phone.' </div></td>
              <td width="163" align="center" valign="middle"><div align="center">'
    .$description.' </div></td>
              <td width="103" align="center" valign="middle"><div align="center">'
    .$address.'<br />
                    '
    .$town.'<br />
               '
    .$city.'</div></td>
              <td width="135" align="center" valign="middle"><div align="center"><a href="http://'
    .$website.'" class="search">Website</a></div></td>
            </tr>
          </table>'
    ;
          


  • #8
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    that is amazingly-brilliantly-fantasticly-great(TM) THANKS!!!!!!

  • #9
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Now i have another problem! Sorry To Keep Bothering You's!

    i have a record in my db where the name field is:
    Figaro's Pizza Kettering

    if you search Figaro you get nothing the only way you can get that resut to show is if you type Kettering

    why is the and how can i fix it!

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $query =  "SELECT *  
    FROM places  
    WHERE `name` LIKE '%{$_GET['q']}' 
    OR `description` LIKE '%{$_GET['q']}' 
    "

    Is searching for words/letters before the word you're looking for. As you need to check for words/letters after the searchword too, add another % after
    PHP Code:
    $query =  "SELECT *  
    FROM places  
    WHERE `name` LIKE '%{$_GET['q']}%' 
    OR `description` LIKE '%{$_GET['q']}%' 
    "


  • #11
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    thanks thats great!

    How do i remove sertan words form the search like:

    and
    in
    or
    with
    ...

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    preg_replace(), ereg_replace(), or str_replace()

  • #13
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    cheers!!!!


    btw i needed your help b cuz i am making a local resturaunt search! It has been requested to me a few times so thankyou for making it possible!


  •  

    Posting Permissions

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