database driven webpage
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: February 18, 2006 03:45AM

hi guys! wondering if somone can help me here!

basically I've a dreamhome database which has details on the properties on rent. I've a webpage that connects to the database and it has a combo box. The box has all the property nos that are being retrieved from the database. now the combo box should allow the user to select the property no and display its details on the webpage such as 'no of rooms' 'owner' etc. I can't figure out how to do it? can someone help me

this is the code I'm using which connects to the database, does a query and retrieves data into the combo box:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

// connect to mySql
$session = mysql_connect("localhost", "root", ""winking smiley;
// select the database
mysql_select_db("dreamhome"winking smiley;

$query = "select * from property_for_rent";

$result = mysql_query($query);
if ( !$result )
{
echo ( "<P>Error doing a select: " . mysql_error() . "</P>" );
}
else
{
// succesful read - how many records ?
print (" Number of rows read " . mysql_num_rows($result)."</br>"winking smiley;

$rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr

}

// close the connection
mysql_close($session);

?>

//puts the property nos into the combo box
<form name="form1" method="post" action="">
<select name="getPropNo" id="getPropNo">
<?php
for ($i=0; $i<$rr; $i++) {
$nextresult = mysql_fetch_array($result);
$property_no = $nextresult['property_no'];
echo "<option>$property_no</option>";
}
?>
</select>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>


thank you so much

Options: ReplyQuote
Re: database driven webpage
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 18, 2006 06:29AM

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

// connect to mySql
if (!$session = @mysql_connect("localhost", "root", ""winking smiley) {
print ('Error: Could not connect to database server.<br>');
break;
}

// select the database
if (!@mysql_select_db("dreamhome"winking smiley) {
print ('Error: Could not secect database.<br>');
break;
}

$query = "select * from property_for_rent";

if (!$result = @mysql_query($query)) {
( "<P>Error doing a select: " . mysql_error() . "</P>" );
break;
} else {
print (" Number of rows read " . mysql_num_rows($result)."</br>"winking smiley;
$rr = mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr
}

// close the connection
mysql_close($session);

?>

//puts the property nos into the combo box
<form name="form1" method="post" action="">
<select name="getPropNo" id="getPropNo">
<?php

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
print ("<option>" . $row['property_no'] . "</option>\n"winking smiley;
}

?>
</select>
</form>
<p> </p>
<p> </p>
</body>
</html>

Options: ReplyQuote
Re: database driven webpage
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: February 18, 2006 01:33PM

hi thank you for replying.

the for loop that i was using was also bringing in the property nos from the database to the combo box and so is your code. but what i want is that when the user selects the property no from the combo box for e.g. p94 it should bring in the property details like 'no of rooms' etc into webpage. so basically on user selection of an option from the combo box should allow us to display that particular property details.

on the html page there will be

the combo box at the top for property no.... then

type________rooms_______ owner no_____________________

Rent___________________ Person/business name _____________

Address_________________ Address___________________________

Tel no_____________________________

Type of business____________________

Contact name_______________________

Managed by staff____________ Registered at branch _________________


all these details are in the database but on user selection of combo box it should display on the webpage.

I'm thinking it invovles post and get method? thank you so much

Options: ReplyQuote
Re: database driven webpage
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 18, 2006 06:26PM

test if the form has been submitted, and it it has then display the results you just said, otherwise, if not, display your form.

Options: ReplyQuote
Re: database driven webpage
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: February 19, 2006 03:02AM

hi sorry I'm not really a programmer. I've never used php and sql so i'm a bit confused now. basically the above form is not a form to recieve input so the user won't be submitting anything but just to display the property details onto the webpage. so if the user selects p94 (property no) from the combo box how would that display for e.g. the no of rooms in that property on the webpage. I'm not using any fields but just labels to display details. could you help me with the code here. what do i need to add to my code?

thank you so much. i don't have a clue and can't seem to work it out at all. getting very stressed cause the deadline is near and i've wasted like two weeks to work it out.

Options: ReplyQuote
Re: database driven webpage
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 19, 2006 06:49AM

post your question here, this is the best php support forum in the world. Your questions will always be answered, and it is a regular handout for some of the brightest php developers.

[www.devnetwork.net]

Another good one is:
[forums.devshed.com]

Post your question at one of these forums

Options: ReplyQuote
Re: database driven webpage
Posted by: kirti (---.cable.ubr03.newm.blueyonder.co.uk)
Date: February 19, 2006 11:42AM

thank you so much.

Options: ReplyQuote
Re: database driven webpage
Posted by: war (---.man.east.verizon.net)
Date: February 19, 2006 05:04PM

not sure i am entirely clear what you are trying to accomplish but i think i see a problem. but let me ask , are you giving the user a form to choose the property no. and then the results should be diplayed based on the prop no. they choose. if so i think you would send your db query after they choose.
$propno = "select * from property_for_rent where property_no = $formvar"
then you could use extract to grab each variable based on it row name.
i think it is like extract($propno).
then you would have the variables automatically named based on database row name and can use them as you like to display on your page.

Options: ReplyQuote


Sorry, only registered users may post in this forum.