DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   php code to search and show results on same page (http://www.daniweb.com/forums/thread166921.html)

almostbob Jan 9th, 2009 10:56 pm
Re: php code to search and show results on same page
 
more than you can ever read, compiled so you can find the part you need to read
http://www.php.net/docs.php

phpNewbie Jan 10th, 2009 3:40 am
Re: php code to search and show results on same page
 
enim213 - thank you very much for the links you supplied - i really do appreciate your time to give them and will definitely make an effort to get the understanding - be afraid lol - if i come up with anything i'll be right back here for you to debug :) (or get your pasted code - kidding - or not lol)
thank you almostbob for your link and code too
at least today i got my basic html page made and my database loaded so that's a start :)

phpNewbie Feb 5th, 2009 8:30 pm
Re: php code to search and show results on same page
 
Hi... i'm baaack
Ok.. i made some effort (got myself more confused in the process - seem to be so many ways to do the same thing??)

Anyway.. this is what i have now: Please help to add or change code to get this working. my sql statement works in phpmyadmin bringing back required results from the database but how do i get that happening on my webpage with the php and html.

Apologies for my messy code but like i explained before, i'm absolutely new to php and finding it very difficult to get my 'blonde' head around it.

Thanks again in advance for any help.

<html>
<head>
<title>Baby Names Database</title>
</head>
<body>
<h1>Baby Names</h1>
<h3>Please fill in the blanks below, and We'll return baby names for you to browse.</h3>

<form method = "post" action = "practiceBaby5.php">
<table border = "1">
<tr>
<th align = "left">Gender:</th>
<th>
<input type = "radio" name = "male" value = "yes">Boys Names<br />
<input type = "radio" name = "female" value = "yes">Girls Names<br />
</th>

<tr>
        <th align = "left">Meaning:</th>
        <th>
                <input type = "text" name = "meaning" value = "">
        </th>
</tr>

<tr>
        <th align = "left">Name Begins With:</th>
        <th>
                <input type = "text" name = "name" value = "">
        </th>
</tr>


<tr>
        <th align = "left">Origin</th>
        <th>
                <select name = "origin">
                <option value = "Muslim">Muslim</option>
                <option value = "anglo">Anglo</option>
                <option value = "african">African</option>
                <option value = "celtic">Celtic</option>
                </select>
        </th>
</tr>

<tr>
        <td colspan = 2> <br />
                <center>
                        <input type = "submit" value = "Show me Names">
                </center>
        </td>
</tr>
</table>
</form>
               
</body>
</html>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<?
// MySQL Connection Information
$server = "localhost";
$username = "sharlene";
$password = "";
$dbname = "baby_names";

// MySQL Connect String
$connection = mysql_connect($server,$username,$password);

// Select the database
mysql_select_db($dbname);

$gender = $_POST['gender'];
$meaning = $_POST['meaning'];
$name = $_POST['name'];
$origin = $_POST['origin'];

$gender = mysql_real_escape_string($gender);
$meaning = mysql_real_escape_string($meaning);
$name = mysql_real_escape_string($name);
$origin = mysql_real_escape_string($origin);

$sql = "SELECT * FROM names WHERE gender = '" . $gender . "' and name LIKE '" . $name . "%' and

meaning LIKE '%" . $meaning . "%' and origin = '" . $origin . "'";
//print($sql);

//execute SQL query and get result
$sql_result = mysql_query($sql, $connection)
        or die(mysql_error());
//print("after sql");

// Loop through the data set and extract each row into it's own variable set
while ($row = mysql_fetch_array($sql_result)) {
        extract($row);
}
// Loop through the data set and extract each row into it's own variable set
//while ($row = mysql_fetch_array($sql_result)) {
//        echo $row['gender']." ".$row['meaning']." ".$row['name']." ".$row['origin']."<br>";

?>


</BODY>
</HTML>


All times are GMT -4. The time now is 11:32 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC