Thread: Please Help Gyz

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Exclamation Please Help Gyz


    suppose i have 10 products in my database
    Example:
    iphone 2 - iphone 3g - laptop i3 - laptop i7 - nokia n96 etc

    when i enter iphone in my search i see all records stored in database thats my prob!

    what i want ?
    suppose if i enter laptop i7 or laptop then i get result for laptop i7 or laptop

    here is my code..

    <?php
    // Connects to your Database
    mysql_connect("host.com", "userr", "pass") or die(mysql_error());
    mysql_select_db("products") or die(mysql_error());

    $data = mysql_query("SELECT * FROM Products")
    or die(mysql_error());
    Print "<table border cellpadding=3>";
    while($info = mysql_fetch_array( $data ))
    {
    Print "<tr>";
    Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
    Print "<th>new:</th> <td>".$info['new_price'] . "</td> ";
    Print "<th>old:</th> <td>".$info['old_proce'] . "</td> ";
    Print "<th>faulty:</th> <td>".$info['Faulty_price'] . " </td></tr>";
    }
    Print "</table>";
    ?>

    if any one have better code then please give me tankxx
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Well yeah it shows everything: you don't have any kind of searching functionality in there. You have to write that.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    Well yeah it shows everything: you don't have any kind of searching functionality in there. You have to write that.
    im new in php
    if u gve me a code thts will b gr8
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Nope, not gonna happen. If you'd like to try writing it yourself then we can certainly help you but we won't do it for you.

    Unless you're willing to pay us.

    So assuming you feel up to the task, how much PHP and SQL do you know?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,971
    Rep Power
    375
    here is a clue:

    $data = mysql_query("
    SELECT * FROM Products
    ")

    change this: SELECT * FROM Products and add a where clause to NARROW down your search results..

    it is like me saying get me all the names of people on the planet... or i could say:
    get me all the names of people on the planet who are 18-20 years etc...
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    can any bdy help me .....
  12. #7
  13. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    Have you read Paul's post?
    ys and alrdy try it but got error like this Table 'home/uks/.name' doesn't exist
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    wll u cn ty 2 ma-b rite englsh
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,971
    Rep Power
    375
    Originally Posted by ManiacDan
    wll u cn ty 2 ma-b rite englsh
    nd while @ it.. lrn 2 use google...

    Comments on this post

    • ManiacDan agrees
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    And a note to ur last post... If ur string worked fine before, but now offers you that error, you changed the wrong part of the line... The WHERE clause gets added to the end of your SELECT line.

    GENERAL format of SELECT.
    SELECT `column1`, `column2` FROM `table` WHERE `column`='value';

    EDIT: Also take note the difference of `column` and 'value'. Database items, such as table and column names, use backticks, while string items use an apostrophe.



    (Thanks for the edit, Mod, I debated how to write such. :-D)
    Last edited by Triple_Nothing; March 8th, 2013 at 12:16 PM.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Lightbulb


    let me simple evry thing ...

    database (Products):
    id
    name
    new_price
    old_price
    faulty_price


    This is my Search code:
    <form method="get" action="db1.php">
    <label><font size="5">Search For: </label>
    <input type="text" name="query" />
    <input type="submit" name="submit" value="Lookup" />
    <input type="reset" value="Reset" </form>

    And Here Is My db1.php code:
    <?php // Connects to your Database
    mysql_connect("host.com", "userr", "pass") or die(mysql_error());
    mysql_select_db("products") or die(mysql_error());
    $data = mysql_query("SELECT * FROM Products")
    or die(mysql_error());
    Print "<table border cellpadding=3>";
    while($info = mysql_fetch_array( $data ))
    {
    Print "<tr>";
    Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
    Print "<th>new:</th> <td>".$info['new_price'] . "</td> ";
    Print "<th>old:</th> <td>".$info['old_price'] . "</td> ";
    Print "<th>faulty:</th> <td>".$info['Faulty_price'] . " </td></tr>";
    }
    Print "</table>";
    ?>

    My Prob??
    when i enter iphone or other product name i see all stored records in database.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    That's because when you submit your search, no matter what you type in, you are running the exact same query every time:
    Code:
    SELECT * FROM `Products`;
    You want to add the WHERE clause. Something so it ends up a search like:
    Code:
    SELECT * FROM `Products` WHERE `name`='George';
    Your first goal is inserting the search string into your MySQL query to be ran, so it doesn't always select all rows.
    Then, figure out which would work better for you as far as HOW you wish to search. Do a little research on the LIKE or the MATCH AGAINST items with MySQL searches.
    Last edited by Triple_Nothing; March 8th, 2013 at 12:23 PM.
  26. #14
  27. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    Right, we know. You do not actually have a WHERE clause. We will not write one for you. You put a textbox on a form and expected it to magically limit an unrelated SQL query? That's not how computers work. Parse the input, escape it, and include it in your SQL query.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0

    Lightbulb


    ha gyz im tide if there is any expert or any member who have a code plz give .. tnkxx
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo