• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Search engine for my web page

Joined
Dec 2, 2009
Messages
3,351 (0.64/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
Hi guys!
I created a simple search engine, but i am a beginner so don't know what is the problem with it.
I created the search, but the problem is, whatever i write on it.... it shows everything.
I know the LIKE action, but i dunno how to use it, can anyone help on here?
The code i have written is this:
Code:
$result = mysql_query("SELECT * FROM student LIKE '%id%'");

Also, if i delete the like function everything i type doesn't matter, it shows everything on the database
 
Last edited:
Joined
Aug 10, 2007
Messages
4,267 (0.70/day)
Location
Sanford, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
Code:
$result = mysql_query("SELECT * FROM studenti [B]WHERE [I]column[/I][/B] LIKE '%[I]something[/I]%'");

Could do something like this for a single box name search:
Code:
SELECT * FROM studenti WHERE CONCAT(firstname, ' ', surname) LIKE '%[I]partialname[/I]%'

From your example, seems like you'd like to search every field? This is of course possible. What information do you have in the students table?
 
Joined
Dec 2, 2009
Messages
3,351 (0.64/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
In the student table i have:
id, name, surname, school, age, city, address, e-mail, password
What is the meaning of CONCAT?????
 
Last edited:
Joined
Aug 10, 2007
Messages
4,267 (0.70/day)
Location
Sanford, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

Concat is short for concatenation, or gluing strings together.

In my example I did a LIKE against the full name (name + surname). This is similar to:

Code:
SELECT * FROM studenti WHERE name LIKE '%string%' OR surname LIKE '%string%'

The difference is that the first example could return results from searches like "jill s" or "hobar d" where as the second one would need to be a partial of either the name or surname.

Searches can be designed dozens of different ways. Could simply concat all the fields you want and search against it:

Code:
SELECT * FROM studenti WHERE CONCAT_WS(' ', name, surname, school, CAST(age AS CHAR), city, address, e-mail) LIKE '%string%'
# I assumed that age may be an integer type

Lacks the versatility of a Google or Yahoo search, but it's a start. From one input box a user could search for "tirana" or "18" or "joe" or anything else and possibly get results. What they couldn't do is search for all of them at the same time. Not without more coding.
 
Joined
Jul 20, 2008
Messages
4,016 (0.70/day)
Location
Ohio
System Name Desktop|| Virtual Host 0
Processor Intel Core i5 2500-K @ 4.3ghz || 2x Xeon L5630 (total 8 cores, 16 threads)
Motherboard ASUS P8Z68-V || Dell PowerEdge R710 (Intel 5520 chipset)
Cooling Corsair Hydro H100 || Stock hotplug fans and passive heatsinks
Memory 4x4gb Corsair Vengeance DDR3 1600 || 12x4gb Hynix DDR3 1066 FB-DIMMs
Video Card(s) MSI GTX 760 Gaming Twin Frozr 4GB OC || Don't know, don't care
Storage Hitachi 7K3000 2TB || 6x300gb 15k rpm SAS internal hotswap, 12x3tb Seagate NAS drives in enclosure
Display(s) ViewSonic VA2349S || remote iDRAC KVM console
Case Antec P280 || Dell PowerEdge R710
Audio Device(s) HRT MusicStreamer II+ and Focusrite Scarlett 18i8 || Don't know, don't care
Power Supply SeaSonic X650 Gold || 2x870w hot-swappable
Mouse Logitech G500 || remote iDRAC KVM console
Keyboard Logitech G510 || remote iDRAC KVM console
Software Win7 Ultimate x64 || VMware vSphere 6.0 with vCenter Server 6.0
Benchmark Scores Over 9000 on the scouter
Lacks the versatility of a Google or Yahoo search, but it's a start. From one input box a user could search for "tirana" or "18" or "joe" or anything else and possibly get results. What they couldn't do is search for all of them at the same time. Not without more coding.
I'm not a coder (only took a simple "programming logic and problem-solving" class), but wouldn't it be possible to set up some sort of "if" or "case" statement to allow for various types of searches based on input (like if it's in quotes or has boolean operators such as AND, OR, etc.). Or maybe there is a built-in or just simpler way of handling boolean operators in queries? Or another way would be to have it perform different types of searches based on some checkboxes and/or radio buttons. Just some ideas.
 
Joined
Dec 2, 2009
Messages
3,351 (0.64/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
@Jizzler
Is it possible to search for Aleks and it shows my name?
Or the person must put in ALL the name to find it?
 
Joined
Aug 10, 2007
Messages
4,267 (0.70/day)
Location
Sanford, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
I'm not a coder (only took a simple "programming logic and problem-solving" class), but wouldn't it be possible to set up some sort of "if" or "case" statement to allow for various types of searches based on input (like if it's in quotes or has boolean operators such as AND, OR, etc.). Or maybe there is a built-in or just simpler way of handling boolean operators in queries? Or another way would be to have it perform different types of searches based on some checkboxes and/or radio buttons. Just some ideas.

Yup. Things like city and school could be drop-down boxes to narrow down results. And with a little work to recognize keywords, quotes, etc, the script could build a query that more accurately returns results.

By coincidence I'm coding up a search page for the company I'm contracting at right now. It's one dirty $%&*$%* database and at this time it can't be redesigned. I'm already up to 250 lines just to build the queries and it's only about half-way done! Also have several mapping files so users can choose one value and the search will include all variations and make use of regex patterns where needed. Much of it could be avoided if the db was well-normalized.


@Jizzler
Is it possible to search for Aleks and it shows my name?
Or the person must put in ALL the name to find it?

Yes. Because of the "%", it would also work with "le", "ek", "al", "ale", "lek" and any single letter in your name.

Depending on how you want your search to operate, you could certainly have multiple fields.
 
Joined
Dec 2, 2009
Messages
3,351 (0.64/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
Ok. The big problem i always have is the "PARSE ERROR"
Parse error: syntax error, unexpected T_STRING in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\regjistrohu.php on line 2
So this is ALL the code:
Code:
<?php
$connection mysql_connect("localhost","root","");
if(!$connection)
	{
	die('Connection could not be done: ' . mysql_error());
	}

mysql_select_db("geoinformatic", $connection);

mysql_query($connection);
$id = $_POST['id'];
$emri = $_POST['name'];
$mbiemri = $_POST['surname'];
$sql="INSERT INTO student (id, name, surname)
VALUES
(´$_POST[id]´,´$_POST[name]´,´$_POST[surname]´)";

if (!mysql_query($sql, $connection))
  {
  die('Error: ' . mysql_error());
  }
echo "New registration added";

$result = mysql_query("SELECT * FROM student");

while($row = mysql_fetch_assoc($result))
  {
  echo $row['id'] . ' ' . $row['name'] . ' ' . $row['surname'];
  }

mysql_close($connection);
?>
Where the HELL is the problem here?
 
Last edited:

Zyon

New Member
Joined
Mar 18, 2011
Messages
264 (0.06/day)
Location
Australia
System Name Computernamehere/Computernamehere2/Computernamehere3
Processor i5-2500/Athlon 6000+/C2D Q6700
Motherboard P67A-UD3R/M2N-SLI Deluxe/P5K-Deluxe
Cooling Stock/Hyper212+/Unknown Coolermaster
Memory Patriot PC3-10666 2x2/A-Data PC2-6400 4x1/OCZ PC2-8500 4x1
Video Card(s) MSI GTX580 Lightning/2x Gigabyte GTS450 OC 1GB/2x HIS HD4870 512MB
Storage Seagate 1TB/Samsung 500GB/Seagate 1TB
Display(s) Samsung BX2440
Case V4 Black/Mystique 631 Silver/Soprano VX
Audio Device(s) WTF is a sound card?
Power Supply Corsair HX650/Antec Earthwatts 650W Green/None
Software Windows 7 Home/Professional/Professional
Benchmark Scores TBA
Line 2

$connection = mysql_connect("localhost","root","");

mysql_connect function should be returning a connection which is then assigned to $connection, just need the = sign.
 
Joined
Dec 2, 2009
Messages
3,351 (0.64/day)
System Name Dark Stealth
Processor Ryzen 5 5600x
Motherboard Gigabyte B450M Gaming rev 1.0
Cooling Snowman, arctic p12 x2 fans
Memory 16x2 DDR4 Corsair Dominator Pro
Video Card(s) 3080 10gb
Storage 2TB NVME PCIE 4.0 Crucial P3 Plus, 1TB Crucial MX500 SSD, 4TB WD RED HDD
Display(s) HP Omen 34c (34" monitor 3440x1440 165Hz VA panel)
Case Zalman S2
Power Supply Corsair 750TX
Mouse Logitech pro superlight, mx mouse s3, Razer Basiliskx with battery
Keyboard Custom mechanical keyboard tm680
Software Windows 11
Benchmark Scores 70-80 fps 3440x1440 on cyberpunk 2077 max settings
There was an error with my local server.
Anyway, i fixed all the errors
 
Top