speedovic — 2012-11-10T17:51:59-05:00 — #1
I need some help to put this simple code into MVC any help would be appreciated. It is a simple form which retrieves data from an SQL DB.. it works fine as one file but I have problems to put it in MVC, especially with submit part.:(
I know for many people this is an easy thing to do in MVC... but i am in a learning process. Plz help
=================== HTML ========
<h3>Search Contacts Details</h3>
<p>You may search either by first or last name</p>
<form method="post" action="search_start.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
================== PHP ============
if(preg_match("/[A-Z | a-z]+/", $_POST['name']))
//-query the database table
$sql="SELECT * FROM Contacts WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";
//-run the query against the mysql query function
//-create while loop and loop through result set
//-display the result of the array
echo "<li>" . "<a href=\"search_start.php?id=$FirstName\">" .$FirstName . " " . $LastName . "</a></li>\
echo "<p>Please enter a search query</p>";
ronalds — 2012-11-10T19:29:01-05:00 — #2
My suggestion is to read about what MVC is. It's not just pushing a "button convert to MVC", most of the times it's preferred to use some MVC framework and for each the code and approach will slightly differ.
jeff_mott — 2012-11-10T19:34:55-05:00 — #3
I suggest reading From Flat PHP to Symfony2. It takes you step-by-step from the kind of PHP you're writing now to a more organized structure.
ftassi — 2012-12-08T21:59:19-05:00 — #4
And maybe you should post the result of your refactoring so someone can use it as an example and learn from it (or we can even improve what you've done).
oddz — 2012-12-09T11:51:46-05:00 — #5
So is this part of a larger site or what? The reason I ask is that wrapping a whole bunch of abstraction around something so simple might not be answer.
kylewolfe — 2012-12-10T14:15:52-05:00 — #6
@ronalds ;, you mean you haven't found PHP's convert-mvc feature yet?
kylewolfe — 2012-12-10T15:48:10-05:00 — #7
belekevicius — 2012-12-12T15:14:35-05:00 — #8
I suggest you to use CodeIgniter framework. Really easy, light and clear
kylewolfe — 2012-12-12T16:51:17-05:00 — #9
Vote for Zend Framework 1.x here
jeff_mott — 2012-12-12T17:56:41-05:00 — #10
Are we voting now?
+1 for Symfony2