michellephp Posted March 28, 2006 Share Posted March 28, 2006 Hello again!I am now having another little problem with the realestate script!I have a button (in the admin area) that says (well the heading says) "sold?". Then the button says either yes or no after clicking on it. However if it hasn't been clicked on yet, it comes up as a blank button. I want it to come up as 'no' (without having to click) - because if you've just listed a property, it's not likely to already be sold! So is it possible to do this? I think I can make it come up saying no, but then it must be click on twice to get to yes (as the first click still corresponds to 'no').<button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? echo $row_p['sold']; ?></button>And this is the code in the sold.php://update soldif($_REQUEST['id'] != "") { $sql = "select * from items where id = ". $_REQUEST['id']; $result = mysql_query($sql,$myconn) or die(mysql_error());if (mysql_num_rows($result) > 0) {// if found //fetch results in assoc array $row_item = mysql_fetch_assoc($result); if ($row_item['sold'] == "no") $sold = "Yes"; else $sold = "No";//build update sql string $update = "update items set sold = '".$sold."' where id = ".$_REQUEST['id']; $result = mysql_query($update,$myconn) or die(mysql_error());Thanks again everyone :) :)Michelle. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 Does this work?[code]<?php $YorN = $row_p['sold']=='no' ? 'No' : 'Yes';?><INPUT TYPE='BUTTON' name='sold' value='<?php echo $YorN ?>' onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'">[/code] Quote Link to comment Share on other sites More sharing options...
michellephp Posted March 28, 2006 Author Share Posted March 28, 2006 Thanks for the suggestion :) but it didn't seem to fix it. Now, the button automatically displays 'yes' (i want 'no') and when click it still says yes and doesn't update the db.i'm totally stumped! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 Try slightly different tack[code]<?php $YorN = $row_p['sold'] != 'Yes' ? 'No' : 'Yes';?><INPUT TYPE='BUTTON' name='sold' value='<?php echo $YorN ?>' onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'">[/code] Quote Link to comment Share on other sites More sharing options...
norman100 Posted March 28, 2006 Share Posted March 28, 2006 <button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? echo $row_p['sold']; ?></button>Michelle, i think that you will need a IF statement in here ,<button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? $status = $row_p['sold'];IF (!$status) {$status = 'No'ELSE //WE HAVE A VALUE $status=$row_p['sold']; } ?></button>[!--quoteo(post=359255:date=Mar 28 2006, 08:17 AM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 28 2006, 08:17 AM) [snapback]359255[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks for the suggestion :) but it didn't seem to fix it. Now, the button automatically displays 'yes' (i want 'no') and when click it still says yes and doesn't update the db.i'm totally stumped![/quote] Quote Link to comment Share on other sites More sharing options...
AV1611 Posted March 28, 2006 Share Posted March 28, 2006 Which is the long way of doing what Barand suggested...[!--quoteo(post=359261:date=Mar 28 2006, 08:47 AM:name=norman100)--][div class=\'quotetop\']QUOTE(norman100 @ Mar 28 2006, 08:47 AM) [snapback]359261[/snapback][/div][div class=\'quotemain\'][!--quotec--]<button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? echo $row_p['sold']; ?></button>Michelle, i think that you will need a IF statement in here ,<button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? $status = $row_p['sold'];IF (!$status) {$status = 'No'ELSE //WE HAVE A VALUE $status=$row_p['sold']; } ?></button>[/quote] Quote Link to comment Share on other sites More sharing options...
michellephp Posted March 28, 2006 Author Share Posted March 28, 2006 Hi everyone,thanks for your replies!I tried both options but sadly neither worked. The first made the button say 'no', but when clicked did not then say 'yes', nor was the db updated.The second gave me this error: Parse error: syntax error, unexpected T_ELSE I think (but really have no idea) that the problem may be that the propety hasn't got a sold status, until the button is clicked. Then if it is clicked once, the staus is then 'no'. Clicked again and the status is 'yes'. Clicked again, back to 'no', etc etc. My main problem with it is that it looks a bit dodgy having a button with no writing in it. Maybe, if I had raido buttons, one for yes, and one for no, it would look passable. But I've no idea how to make the script adapt to that. Or maybe just a single little radio button they could click once it has sold. So that would mean the property never has the status 'no' (ie not sold) just 'yes'. Unless the button is unclicked... then the status would be no. But that's pretty much the same as what I've got............ although I think the empty radio button would look better than the empty button. I'll try to make it into a radio button instead :) If anyone knows how to do it off the top of their head please feel free to show me :) :) Otherwise I'll play around till I get it.Thanks! Quote Link to comment Share on other sites More sharing options...
norman100 Posted March 28, 2006 Share Posted March 28, 2006 Michelle!Thats not even a problemadd me to msn nokia_buyer@hotmail.comor email me and we will discuss this nirmal[!--quoteo(post=359313:date=Mar 28 2006, 10:34 AM:name=michellephp)--][div class=\'quotetop\']QUOTE(michellephp @ Mar 28 2006, 10:34 AM) [snapback]359313[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi everyone,thanks for your replies!I tried both options but sadly neither worked. The first made the button say 'no', but when clicked did not then say 'yes', nor was the db updated.The second gave me this error: Parse error: syntax error, unexpected T_ELSE I think (but really have no idea) that the problem may be that the propety hasn't got a sold status, until the button is clicked. Then if it is clicked once, the staus is then 'no'. Clicked again and the status is 'yes'. Clicked again, back to 'no', etc etc. My main problem with it is that it looks a bit dodgy having a button with no writing in it. Maybe, if I had raido buttons, one for yes, and one for no, it would look passable. But I've no idea how to make the script adapt to that. Or maybe just a single little radio button they could click once it has sold. So that would mean the property never has the status 'no' (ie not sold) just 'yes'. Unless the button is unclicked... then the status would be no. But that's pretty much the same as what I've got............ although I think the empty radio button would look better than the empty button. I'll try to make it into a radio button instead :) If anyone knows how to do it off the top of their head please feel free to show me :) :) Otherwise I'll play around till I get it.Thanks![/quote] Quote Link to comment Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 Norman,Normally, we'd like to keep these discussions online so that other people searching through the forums can find answers as well. I obviously can't stop either of you from proceding, but I also think it should be the origional poster's position to ask about taking it offline. Quote Link to comment Share on other sites More sharing options...
norman100 Posted March 28, 2006 Share Posted March 28, 2006 Hi In the first instance try the following <button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'"><? IF (!$status) {$status = 'No'echo $status;}ELSE {//WE HAVE A VALUE $status=$row_p['sold']; echo $status;}?></button>Ober no you misunderstood me, I just wanted to discuss the problem in more detail perhaps even see the underlying mysql database, I felt that i couldnt get this same level of communication through the forum, But should that be your wish that it all stays online then thats fine. Quote Link to comment Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 No offense, but I don't think anyone on here is going to (or at least they shouldn't) just show you their MySQL database. That's a security risk. If you can't figure out the problem, then leave it for someone else to answer or ask the poster to provide more information that they're comfortable sharing. Quote Link to comment Share on other sites More sharing options...
michellephp Posted March 28, 2006 Author Share Posted March 28, 2006 Hi Norman,Thanks for the suggestion :) however this time I got the error: Parse error: syntax error, unexpected T_ECHOMaybe the radio buttons would be easier? Quote Link to comment Share on other sites More sharing options...
michellephp Posted March 31, 2006 Author Share Posted March 31, 2006 Hi everyone again!I have partially fixed this, by adding the 'if' as suggested. However I still have a problem. It comes up as 'no' is there has been no value assigned for it. It comes up as yes if it has 'yes' assigned to it. But still, the person has to click the 'no' button twice to get to use.I.e.First No = "no"second No = "yes"Code:if ($row_p['sold'] == "Yes") $sold = "Yes"; else $sold = "No"; ?><button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'" value="No"><? echo $sold; ?></button>And the sold.php:if($_REQUEST['id'] != "") { $sql = "select * from items where id = ". $_REQUEST['id']; $result = mysql_query($sql,$myconn) or die(mysql_error()); if (mysql_num_rows($result) > 0) {// if found //fetch results in assoc array $row_item = mysql_fetch_assoc($result); if ($row_item['sold'] == "No") $sold = "Yes"; else $sold = "No";//build update sql string $update = "update items set sold = '".$sold."' where id = ".$_REQUEST['id']; $result = mysql_query($update,$myconn) or die(mysql_error());Now logically, you would think that you would change the "no" to "yes" in the button link. And then the no in "if ($row_item['sold'] == "No")" to yes. BUt when I do that, when the button is clicked it doesn't change tp yes (even if clicked twice) and doesn't update the db.I thought maybe by adding an ORDER BY somewhere (because my only thought at the moment is that "no" is always the first option submitted as it comes first in the alphabet....). But if this might be the case, where do I stick the ORDER BY desc??Thanks again,Michelle Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 31, 2006 Share Posted March 31, 2006 Change the following:[code]<button onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'" value="No"><? echo $sold; ?></button>[/code]to this:[code]<input type="button" onclick="window.location='sold.php?id=<? echo $row_p['id']; ?>'" value="<?php echo $sold; ?>">[/code] Quote Link to comment Share on other sites More sharing options...
michellephp Posted March 31, 2006 Author Share Posted March 31, 2006 Hi,Thanks for your help. Unfortunately it still doesn't work; the button still needs to be clicked twice.It seems to me that the form is not passing on the value "no". Michelle :) Quote Link to comment Share on other sites More sharing options...
Barand Posted March 31, 2006 Share Posted March 31, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]It seems to me that the form is not passing on the value "no". [/quote]The button is passing the id of the property. The record with that id contains the "sold" value, Yes or No. So you should be able to determine whether property is sold or not. Quote Link to comment Share on other sites More sharing options...
play_ Posted March 31, 2006 Share Posted March 31, 2006 I got 1 hour of sleep last night so bare with me, im not sure i understand.Your page loads a listing of houses, and each of them has a button, that you would like to say 'no', but when you click, you want it to display 'yes'?If so, why not have a column in your database, let's say "sold", that can hold either "yes" or "no".Then, you could retrieve it and put it as the button value like<input type="submit" value="<?php echo $row['sold']; ?>">Is that it? sorry if im way off. Quote Link to comment Share on other sites More sharing options...
michellephp Posted April 1, 2006 Author Share Posted April 1, 2006 Hi,the buttons are in the backend, where the people can add their homes to be sold. There's a button in one of teh columns that they can click to say whether or not the property has sold. At the moment, the button initially comes up empty (which I think looks dodgy). Then if you click it once, it says 'no' and the database knows it is not sold (although if the button has never been pressed the database does not say the property has been sold either).If you click it again, the button says 'yes'.But really, if the person has just listed their property, it won't be sold yet. So the button should come up saying 'no' rather than blank. And then, the person should only have to click it once to say the property has been sold = "yes"At the moment, I have it so the button comes up saying "no" which looks better. But the person still has to click it twice to get to "yes"iecomes up saying (but with no real value) = "no"first click = "no"2nd click = "yes"so if the db could assume if not yes, = no, that would be good. But I can't get it to do that. Quote Link to comment Share on other sites More sharing options...
michellephp Posted April 1, 2006 Author Share Posted April 1, 2006 Hi Barand,I'm not sure I understand... what does that mean?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]So you should be able to determine whether property is sold or not.[/quote]It is working so far as it updates the db... it's just when the button is clicked it updates the db to 'no' first (i want 'yes' first).I thought maybe this was happening because of this line is sold.php $update = "update items set sold = '".$sold."' where id = ".$_REQUEST['id'];See i thought there should be another " at the end.... but I get this error when I add one:Parse error: syntax error, unexpected '"' in /home/homebuy/public_html/sold.php on line 23But when I take the " out (ie where id = .$_REQUEST)I get: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /public_html/sold.php on line 23Do you think this could have something to do with it? Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2006 Share Posted April 1, 2006 I've set a simple sample system similar to yours. Hope it helpsThe table[code]CREATE TABLE property ( propID int not null auto_increment primary key, descrip varchar(20), price int, sold varchar(3) );[/code]The data[code]INSERT INTO property (descrip, price) VALUES('a house', 220000),('big house', 354995),('huge house', 1295000),('bungalow', 295000),('studio apartment', 140000);[/code]The code[code]<?phpinclude 'db.php';// -- supporting functions ------------------------------------------------------------------function listProperties() { $sql = "SELECT propID, descrip, price, sold FROM property ORDER BY price "; $res = mysql_query($sql) or die (mysql_error()); echo "<TABLE width='500' cellspacing='0' cellpadding='5'>\n"; echo "<TR> <TH>ID</TH> <TH>Property</TH> <TH>Price</TH> <TH>Sold</TH> </TR>\n"; while (list($id, $desc, $price, $sold) = mysql_fetch_row($res)) { $btnval = ($sold=='Yes') ? 'Yes' : 'No'; $script = $_SERVER['PHP_SELF']; $btn = "<INPUT type='button' value='$btnval' onClick='location.href=\"$script?sellid=$id\"'>"; echo "<TR> <TD>$id</TD> <TD>$desc</TD> <TD style='text-align:right'>" . number_format($price,0) . "</TD> <TD style='text-align:center'>$btn</TD> </TR>\n"; } echo "</TABLE>\n";}function sellProperty($id) { $sql = "SELECT sold FROM property WHERE propID = '$id'"; $res = mysql_query($sql) or die (mysql_error()); $sold = mysql_result($res, 0); $sellval = ($sold=='Yes' ? 'No' : 'Yes'); mysql_query ("UPDATE property SET sold = '$sellval' WHERE propID = '$id'");}// -- end functions ------------------------------------------------------------------if (isset($_GET['sellid'])) { sellProperty($_GET['sellid']);}?><HTML><HEAD><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)"><title>Sample property page</title><meta Name="author" content="Barand"></HEAD><BODY><?php listProperties();?></BODY></HTML>[/code] Quote Link to comment Share on other sites More sharing options...
norman100 Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360661:date=Apr 1 2006, 01:41 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 01:41 PM) [snapback]360661[/snapback][/div][div class=\'quotemain\'][!--quotec--]I've set a simple sample system similar to yours. Hope it helpsThe table[code]CREATE TABLE property ( propID int not null auto_increment primary key, descrip varchar(20), price int, sold varchar(3) );[/code]The data[code]INSERT INTO property (descrip, price) VALUES('a house', 220000),('big house', 354995),('huge house', 1295000),('bungalow', 295000),('studio apartment', 140000);[/code]The code[code]<?phpinclude 'db.php';// -- supporting functions ------------------------------------------------------------------function listProperties() { $sql = "SELECT propID, descrip, price, sold FROM property ORDER BY price "; $res = mysql_query($sql) or die (mysql_error()); echo "<TABLE width='500' cellspacing='0' cellpadding='5'>\n"; echo "<TR> <TH>ID</TH> <TH>Property</TH> <TH>Price</TH> <TH>Sold</TH> </TR>\n"; while (list($id, $desc, $price, $sold) = mysql_fetch_row($res)) { $btnval = ($sold=='Yes') ? 'Yes' : 'No'; $script = $_SERVER['PHP_SELF']; $btn = "<INPUT type='button' value='$btnval' onClick='location.href=\"$script?sellid=$id\"'>"; echo "<TR> <TD>$id</TD> <TD>$desc</TD> <TD style='text-align:right'>" . number_format($price,0) . "</TD> <TD style='text-align:center'>$btn</TD> </TR>\n"; } echo "</TABLE>\n";}function sellProperty($id) { $sql = "SELECT sold FROM property WHERE propID = '$id'"; $res = mysql_query($sql) or die (mysql_error()); $sold = mysql_result($res, 0); $sellval = ($sold=='Yes' ? 'No' : 'Yes'); mysql_query ("UPDATE property SET sold = '$sellval' WHERE propID = '$id'");}// -- end functions ------------------------------------------------------------------if (isset($_GET['sellid'])) { sellProperty($_GET['sellid']);}?><HTML><HEAD><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)"><title>Sample property page</title><meta Name="author" content="Barand"></HEAD><BODY><?php listProperties();?></BODY></HTML>[/code][/quote]Michelle did you not use that function which i gave you in the end All you had to do was include the file and call the function where ever you wonted to place the button,buttom($id);that is it, u could have placed this in a table cell tooif you wonted to print everything it would be something like this$queries ="select * from properties";$result = mysql_query($queries);While ($row=mysql_fetch_array($result)) {$id=$row['id];##PRINT THE TABLE AND CONTENTS <TD style='text-align:center'>buttom($id);</TD>}AND THATS IT! U MIGHT GET A PARSE ERROR OR 2 BECAUSE I HAVENT RAN AND TESTED ANYTHING, I HAVE THE FUNCTION OF COURSE!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.