[SOLVED] getting the query to display in result page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

[SOLVED] getting the query to display in result page

Post by Wildwood »

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Im very new to PHP so please bear with me,
I am sampling a web site based on an estate agent. I am using it to work on forms and submitting quries (with no joy). I have done the database and have done an index that displays all results and have set up an admin page to delete, edit or remove the data, these all work fine.

I have created the "houses" database and have added a table called "sales" with the following fields (7)

Code: Select all

id
address
area
bedrooms
price
description
image
I have completed the search page and have attempted to create the "results.php" page with no joy. I give the user the option to select the number of bedrooms and the area where they are looking. Also two drop down menus one offering a minimum price selection and the other with the maximum house value. Below is the code for the "search.php" page

Can someone help me with the coding or give some advice, have been working on this for the last few weeks and have made no progress...............maybe im looking into it too deep

Code: Select all

<?php require_once('Connections/myConnection.php'); ?>
<?php
mysql_select_db($database_myConnection, $myConnection);
$query_area = "SELECT area, count(*) as count FROM sale GROUP BY area ORDER BY area ASC";
$area = mysql_query($query_area, $myConnection) or die(mysql_error());
$row_area = mysql_fetch_assoc($area);
$totalRows_area = mysql_num_rows($area);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images_1/logo.jpg" width="600" height="100"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<div align="center"> </div>
<form name="form1" method="post" action="results.php">
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td colspan="6"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please 
        enter your search criteria below.</font></td>
    </tr>
    <tr> 
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td colspan="5"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr> 
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Minimum 
        Price range</font></td>
      <td colspan="3"><select name="Minprice" id="price">
          <option value="20000">&pound;20'000</option>
          <option value="30000">&pound;30'000</option>
          <option value="40000">&pound;40'000</option>
          <option value="50000">&pound;50'000</option>
          <option value="55000">&pound;55'000</option>
          <option value="60000">&pound;60'000</option>
          <option value="65000">&pound;65'000</option>
          <option value="70000">&pound;70'000</option>
          <option value="75000">&pound;75'000</option>
          <option value="80000">&pound;80'000</option>
          <option value="85000">&pound;85'000</option>
          <option value="90000">&pound;90'000</option>
          <option value="95000">&pound;95'000</option>
          <option value="100000">&pound;100'000</option>
          <option value="105000">&pound;105'000</option>
          <option value="110000">&pound;110'000</option>
          <option value="115000">&pound;115'000</option>
          <option value="120000">&pound;120'000</option>
          <option value="125'000">&pound;125'000</option>
          <option value="130'000">&pound;130'000</option>
          <option value="135000">&pound;135'000</option>
          <option value="140000">&pound;140'000</option>
          <option value="140000">&pound;145'000</option>
          <option value="150000">&pound;150'000</option>
          <option value="155000">&pound;155'000</option>
          <option value="160000">&pound;160'000</option>
          <option value="165000">&pound;165'000</option>
          <option value="170000">&pound;170'000</option>
          <option value="175000">&pound;175'000</option>
          <option value="180000">&pound;180'000</option>
          <option value="185000">&pound;185'000</option>
          <option value="190000">&pound;190'000</option>
          <option value="195000">&pound;195'000</option>
          <option value="200000">&pound;200'000</option>
          <option value="250000">&pound;250'000</option>
          <option value="300000">&pound;300'000</option>
          <option value="350000">&pound;350'000</option>
          <option value="400000">&pound;400'000</option>
          <option value="450000">&pound;450'000</option>
          <option value="500000">&pound;500'000</option>
          <option value="550000">&pound;550'000</option>
          <option value="600000">&pound;600'000</option>
        </select> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td width="18%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Maximum 
        Price Range</font></td>
      <td width="38%"><select name="Maxprice" id="price">
          <option value="600000">&pound;600'000</option>
          <option value="550000">&pound;550'000</option>
          <option value="500000">&pound;500'000</option>
          <option value="450000">&pound;450'000</option>
          <option value="400000">&pound;400'000</option>
          <option value="350000">&pound;350'000</option>
          <option value="300000">&pound;300'000</option>
          <option value="250000">&pound;250'000</option>
          <option value="200000">&pound;200'000</option>
          <option value="180000">&pound;180'000</option>
          <option value="160000">&pound;160'000</option>
          <option value="140000">&pound;140'000</option>
          <option value="135000">&pound;135'000</option>
          <option value="130000">&pound;130'000</option>
          <option value="125000">&pound;125'000</option>
          <option value="120000">&pound;120'000</option>
          <option value="115000">&pound;115'000</option>
          <option value="110000">&pound;110'000</option>
          <option value="105000">&pound;105'000</option>
          <option value="100000">&pound;100'000</option>
          <option value="95000">&pound;95'000</option>
          <option value="90000">&pound;90'000</option>
          <option value="85000">&pound;85'000</option>
          <option value="80000">&pound;80'000</option>
          <option value="75000">&pound;75'000</option>
          <option value="70000">&pound;70'000</option>
          <option value="65000">&pound;65'000</option>
          <option value="60000">&pound;60'000</option>
          <option value="55000">&pound;55'000</option>
          <option value="50000">&pound;50'000</option>
          <option value="45000">&pound;45'000</option>
          <option value="40000">&pound;40'000</option>
          <option value="35000">&pound;35'000</option>
          <option value="30000">&pound;30'000</option>
        </select></td>
    </tr>
    <tr> 
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td colspan="5"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr> 
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Bedrooms</font></td>
      <td colspan="5"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
        <select name="bedrooms" id="bedrooms">
          <option value="any">Any</option>
          <option value="1>">1+</option>
          <option value="2>">2+</option>
          <option value="3>">3+</option>
          <option value="4>">4+</option>
          <option value="5>">5+</option>
        </select>
        </font></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="5">&nbsp;</td>
    </tr>
    <tr> 
      <td colspan="5">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td colspan="4"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">* 
        If No area's are selected below you will receive property information 
        for all area's.</font></td>
    </tr>
    <tr> 
      <td colspan="4">&nbsp;</td>
    </tr>
    <tr> 
      <?php $horizcount=0; do { 
      $areaname = $row_area['area'];
	  if (!$areaname) { $areaname = "No Area"; }
	  $count = $row_area['count'];
	  echo "<td><input type="checkbox" value="$areaname"> $areaname ($count)</td>";
	  $horizcount +=1;
	  if ($horizcount == 4) { echo "</tr><tr>"; $horizcount=0; }
       } while ($row_area = mysql_fetch_assoc($area)); ?>
    </tr>

    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($area);
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/size]

what's the actual problem? You don't know how to create the results page? That's somewhat straight forward. You first validate all the posted data. This should be done anytime data is coming in from the user, really. You will be looking through the $_POST superglobal array to find this data.

Next, you figure out what to do for the database query.. This can be adding in the values to match against the prices selected, or any combination of options your search page allows.

Then it's down to printing it all out. I'd suggest playing around with the queries you'll need to use for the results based on varying inputs from your search form. (In phpMyAdmin)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

just to add

Post by phpScott »

you will have to dynamically create you query based on what the use inputs.
This can be a little troublesome for the more search criteria that you allow the more you will have to work.
Suggestion is just to keep it simple firtst by allowing only to search by area then when that is working to follow it up buy adding the price range.

After having a closer look at what your code is doing buy allowing to search for multiple areas at once(using the check boxes) you are biting alot off for your first use defined search.

Ignore first paragraph and do the price search first as it should be easier to implement between the two.

Try posting the search code you already have to see if any one else can point you in the right direction.
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

Forms and Query

Post by Wildwood »

The problem being is that I have constructed most of the site in Dreamweaver and in one tutorial book it shows partially how to create the form in Dreamweaver, I thought it would be possible to create the form in Dreamweaver.....................is it ???

I probably need some guidance on how to create the form in Dreamweaver and setting up the query.......................any guidance again would be greatly appreciated...............(before my life falls completely apart).


Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=25870 is probably a good starting off point for doing the query, at the least.
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

Will crack on..........

Post by Wildwood »

Thanks Feyd and phpscott..............I will have another attempt over the weekend and see what comes out.
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

Database query and forms

Post by Wildwood »

Still no nearer my problem regarding above,

I think the best thing for me to do is start from fresh...........Is there any good tutorials or links that follow step by step...........setting up a form and also applying the query ?
Because I have concentrated this in Dreamweaver is there any info anywhere on creating the form and also the query in dreamweaver??

Any.............and I mean ANY help will be appreciated.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe the concensus from the bulk of us is lose Dreamweaver. :)

As for creating a form, it's simple html. BareBones Guide to HTML can help you there. As for creating the query, using a tool like phpMyAdmin to show your the queries it's running may help you a lot. Reading the mysql manual can help a lot with the added syntaxes and things that you can do which phpMyAdmin normally doesn't do on it's own.
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

forms

Post by Wildwood »

Hi Feyd,

The problem being that I have done most of the database layout and design in Dreamweaver (I believed that most php scripting could have been done in Dreamweaver, but now I understand that even within dreamweaver there has to be a bit of handballing of code to fit the dreamweaver requirements). Maybe im trying to sing off two different songsheets, php and dreamweaver. I have actually done a few sql queries within myadmin and they seem to work okay. The problem being setting out the code into the results page for it to show the desired result.

Would it be beneficial to tender out the code on the php developers page on here and just pay someone to do the code for me ?? If so what is the stipulation and how would I pay for the service ect. (Whsat happens if the code is not what I wanted).

Would like to sort this out been on it too long...............although I have learnt some stuff on php last two weeks and will be getting into this in a big way..........but at a slower pace i think.
Wildwood
Forum Newbie
Posts: 8
Joined: Fri Oct 01, 2004 3:34 am

Forms

Post by Wildwood »

Thanks guys..............ended up putting the work out to someone else...................will look over the script and will have a better understanding on how it works.

Is there no need to mark these threads as closed ?

Thanks for the advice anyway.
Post Reply