The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-General - Please Help Gyz
Discuss Please Help Gyz in the PHP Development forum on Dev Shed. Please Help Gyz PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 8th, 2013, 02:42 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
PHP-General - 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
|

March 8th, 2013, 02:54 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Well yeah it shows everything: you don't have any kind of searching functionality in there. You have to write that.
|

March 8th, 2013, 03:49 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
Quote: | 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
|

March 8th, 2013, 04:13 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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?
|

March 8th, 2013, 04:28 AM
|
|
|
|
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...
|

March 8th, 2013, 05:21 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
|
can any bdy help me .....
|

March 8th, 2013, 05:41 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Have you read Paul's post?
|

March 8th, 2013, 05:51 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
Quote: | 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
|

March 8th, 2013, 07:57 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

March 8th, 2013, 08:12 AM
|
|
|
Quote: | Originally Posted by ManiacDan wll u cn ty 2 ma-b rite englsh |
nd while @ it.. lrn 2 use google...
|

March 8th, 2013, 08:44 AM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 294
  
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
|
|
|
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.
|

March 8th, 2013, 11:57 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
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.
|

March 8th, 2013, 12:13 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 294
  
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
|
|
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.
|

March 8th, 2013, 12:22 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

March 8th, 2013, 12:48 PM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 9
Time spent in forums: 1 h 31 m 27 sec
Reputation Power: 0
|
|
ha gyz im tide if there is any expert or any member who have a code plz give .. tnkxx
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|