2
$query = "SELECT * FROM seats WHERE SeatStatus = 1";
$display = @mysql_query($query);


if ($display){
$disable = "disable";
}


    <input name="ch1" type="checkbox" id="A1" value="" <?php echo $disable ?>/>;

how do i add "disable" inside the code...ive tried many time..but still didnt work.. Im new with php btw...Thanks..~

5 Answers 5

1

The main problem is that you are not checking if the query returned any results or an empty set. You are just checking whether the query is successful. mysql_query() would return false only when the query is wrong. In your case the query is correct, so $display = mysql_query(); will always evaluate to a non-false value.

To solve this, you should check how many rows mysql_query() returns using mysql_num_rows(). So let's rewrite your code.

$query = "SELECT * FROM seats WHERE SeatStatus = 1";
$result = @mysql_query($query);
$display = (mysql_num_rows($result) == 1);

$disable = $display?'':'disabled="disabled"';

   <input name="ch1" type="checkbox" id="A1" value="" <?php echo $disable; ?>/>;

Hope that helps...

Peace...

Sign up to request clarification or add additional context in comments.

5 Comments

I forgot to put the "d" at the end of the code...the thing is i wan to make my checkbox to be disabled if seatStatus is true, else nothing happen..do you know the codes?
Seat_ID 1 | 2 | 3 || SeatStatus 0 | 0 | 0....So if i click checkBox and hit reserve...it should be automatically change the SeatStatus to 1[worked] and the checkbox to be disable[still not working]...
edit your question and give more details and codes about your problem for a better solution.
@ahmedtabrez This method WORKS ! Thank BRO ! Ive been solving this for weeks... THANK YOU VERY MUCH...YOU MAKE ME CRY T_T..~ LOL
Its my email name btw since saiful was taken..and its my first time here...never explore anything yet...~ btw thank you so much !
1

The attribute value is disabled not disable, just add a d.

2 Comments

oh ya thx btw...its worked..but the thing is i wan to make its if the SeatStatus value is 1 it will disabled the checkbox else nothing happen... this code wrong?
Forms only submit successful controls. A checkbox is only a successful control if it is checked and is not disabled.
0

What you actually want is not clear for me. I think you want to find all seats where its status equals to 1. if seats are available(status = 1) disable checkbox.

$query = "SELECT * FROM seats WHERE SeatStatus = 1";
$result = @mysql_query($query);

$num_rows = @mysql_num_rows($result);

$disable = '';
if (!$num_rows){
$disable = 'disabled="disabled"';
}

<input name="ch1" type="checkbox" id="A1" value="" <?php echo $disable ?>/>;

6 Comments

i have tried it and still failed. am i missing something? $query = "SELECT count(*) FROM seats WHERE SeatStatus = 1"; $display = @mysql_query($query) $disable = ''; if (!$display){ $disable = 'disabled="disabled"'; } <input name="ch1" type="checkbox" id="A1" value="" <?php echo $disable ?>/>;
at the input end did you put the name you want to display? <input name="ch1" type="checkbox" id="A1" value="" <?php echo $disable ?>/> Display
i did not put display...if i use the top method...it will disabled the checkbox straight away...that the problem..
when the page is load your checking there are seats where status=1( there can be many seats rite). if there are seats ($display>0) available then you want to disable the checkbox. if not which means ($display=0) you want to enable checkbox. am I rite? the code should work if this is the requirement you want. try a echo the $display value and see the SQL query is working correctly.
yeah this is exactly what i want...i echo the $display...it display Resources #4...what is that mean?
|
0

Replacedisable with disabled

Comments

0
<input type="checkbox" <?php echo ($condition) ? ' disabled="disabled"' : '';/>

2 Comments

how do i use this...is it <input type="checkbox" <?php echo ($display) ?> 'disabled' : '';/>
@Ahmad : No that's a ternary if

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.