Jump to content

Simple search


seephp

Recommended Posts

I have created a simple way to add email address to a MySQL DB. I am trying to make a way to search alphabetically.

 

Here is my current code:

 

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<link rel="stylesheet" type="text/css"
href="./style.css" />
<head>
<title>Creat A sticky note</title>
</head>
<body>
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
require ('enavbar1.php');
require ('footer.php');
if ($dbc = mysql_connect
('localhost', 'root', 'vertrigo'))
{		

		if (!mysql_select_db ('emaildb'))
		{	
			die ('<p>Could not select the database because: <b>' .
			mysql_error() . '</b></p>');
		}

} else {
	die ('<p>Could not select the database because: <b>' .
			mysql_error() . '</b></p>');

}

$query = 'SELECT * FROM email_entries ORDER BY date_entered DESC';

if ($r = mysql_query ($query)) {

		while ($row = mysql_fetch_array ($r)) {
			print "<p><h4>{$row['name']}</h4>
			{$row['address']}<br />
			<a href=\"edit_entry.php?id={$row['blog_id']}\">Edit</a>
			<a href=\"delete_entry.php?id={$row['blog_id']}\">Delete</a>
			</p><hr />\n";
		}

				} else {
			print "<p>Could not retrieve the data because: <b>" .
			mysql_error() . "</b>The query was $query.</p>";

		}

		mysql_close();


?>
</body>
</html>

 

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<link rel="stylesheet" type="text/css"
href="style.css" />
<head>
<title>Creat A sticky note</title>
</head>
<body>
<?php
require ('enavbar.php');
require('footer.php');
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset ($_POST['submit'])) {
if ($dbc = mysql_connect
('localhost', 'root', 'vertrigo'))
{		

		if (!@mysql_select_db ('mysticky'))
		{	
			die ('<p>Could not select the database because: <b>' .
			mysql_error() . '</b></p>');
		}

} else {
	die ('<p>Could not select the database because: <b>' .
			mysql_error() . '</b></p>');

}

$query = "INSERT INTO blog_entries
(blog_id, title, entry, date_entered)
VALUES (0, '{$_POST['title']}',
'{$_POST['entry']}', NOW())";

		if (mysql_query ($query)) {
			print '<p>Your StickyWeb Sticky has been stuck.</p>';

		} else {
			print "<p>Could not select the database because: <b>" .
			mysql_error() . "</b>The query was $query.</p>";

		}

		mysql_close();
}
?>
<form action="addNote.php" method="post">
<p>Create your Websticky Sticky note!</p>
<p>Enter your title:<input type="text" name="title" size="40" maxsize="100" /></p>
<p>Enter your note:<textarea name="entry" columns="40" rows="5"></textarea></p>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>

 

can someone tell me how I would add the ability to search alphabetically?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/38922-simple-search/
Share on other sites

well you would add like the links that are like: www.yoursite.com/list.php?viewby=J

 

then you query would become:

 

if(isset($_GET['viewby'])){
$query = 'SELECT * FROM email_entries WHERE LEFT(`email_entries`,1)='{$_GET['viewby']}' ORDER BY date_entered DESC';
}else{
$query = 'SELECT * FROM email_entries ORDER BY date_entered DESC';
}

 

and hopefully that will do trick.

Link to comment
https://forums.phpfreaks.com/topic/38922-simple-search/#findComment-187598
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.