SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select multiple columns in table

    I'm trying to select multiple columns to search through instead of one. I've posted the code that sends the query.

    PHP Code:
     mysql_select_db($database_MySQL_Connection$MySQL_Connection);
    $query_Recordset1 sprintf("SELECT * FROM `new` WHERE Bird LIKE '%%%s%%'"$colname_Recordset1);
    $Recordset1 mysql_query($query_Recordset1$MySQL_Connection) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1); 
    DoesItMatter
    - anyone seen my underwear?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    searching multiple columns would be something like this:
    Code:
    select * 
      from `new` 
     where Bird like '%s%'
        or Lemon like '%s%'
        or Ennui like '%s%'
        or Quark like '%s%'
    each percent sign wildcard stands for zero or more characters,
    so you only need one of them on either side of the search string
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i do that i get the following error:

    HTML Code:
      [b]Warning[/b]: sprintf() [[url="http://localhost/Birds/function.sprintf"][color=#800080]function.sprintf[/color][/url]]: Too few arguments in [b]c:\wamp\www\Birds\birds.php[/b] on line [b]8[/b]
    Query was empty
    Here is all of the code:

    PHP Code:
    <?php require_once('Connections/MySQL_Connection.php'); ?>
    <?php
    $colname_Recordset1 
    "1";
    if (isset(
    $_POST['search'])) {
      
    $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
    }
    mysql_select_db($database_MySQL_Connection$MySQL_Connection);
    $query_Recordset1 sprintf("select * from `new` where Bird like '%s%' or Location like '%s%'"$colname_Recordset1);
    $Recordset1 mysql_query($query_Recordset1$MySQL_Connection) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
    ?>
    </head>
    <style type="text/css">
    <!--
    .style8 {color: #FFFFFF}
    .style9 {font-family: Arial, Helvetica, sans-serif}
    .style12 {font-size: 10px}
    .style13 {font-family: Arial, Helvetica, sans-serif; font-size: 10px; }
    -->
    </style>
    <body>
    <?php include("search.php"); ?>
    <br>
    <table width="500" border="0" cellspacing="0" cellpadding="4" id=theTable>
      <tr bgcolor="#003366">
        <td><span class="style1 style8 style9 style12">Type</span></td>
        <td><span class="style1 style8 style9 style12">Bird</span></td>
        <td><span class="style1 style1 style8 style9 style12">Location</span></td>
        <td><span class="style1 style8 style9 style12">Date</span></td>
      </tr>
      <?php do { ?>
      <tr>
        <td><span class="style13"><?php echo $row_Recordset1['Type']; ?></span></td>
        <td><span class="style13"><?php echo $row_Recordset1['Bird']; ?></span></td>
        <td><span class="style13"><?php echo $row_Recordset1['Location']; ?></span></td>
        <td><span class="style13"><?php echo $row_Recordset1['Date']; ?></span></td>
      </tr>
      <?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <p>&nbsp;</p>
    </body>
    </html><?php
    mysql_free_result
    ($Recordset1);
    ?>
    DoesItMatter
    - anyone seen my underwear?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    well, i'm pretty confident your sql is okay

    looks like you have a php question, not a mysql question

    have you tried that forum?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not yet...will try
    DoesItMatter
    - anyone seen my underwear?


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
  •