DanielHardy Posted March 24, 2009 Share Posted March 24, 2009 <?php $booked = "<b>Seat Booked</b>"; $sql = "SELECT id,username,admin,rowId,columnId FROM seats ORDER by id ASC"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while(list($id,$username,$admin,$columnId,$rowId,)=mysql_fetch_row($result)){ if($columnId == 'BOX' && $rowId == 1) { echo '<p></p>'."\n"; } if($admin==1){ echo '<div style="background-color:red;align:center;width:60px;text-align:center;float:right;height:40px;border:2px solid #FFFFFF;"><b><font color="black">'.$rowId.''.$columnId.'</div>'."\n"; } if($admin==0){ $checked = ($admin==1) ? 'checked="checked"' : ''; echo '<div style="background-color:green;align:center;width:60px;font-weight:bold;text-align:center;float:right;height:40px;border:2px solid #FFFFFF;"><b><font color="black">'.$rowId.''.$columnId.'<input type="checkbox" name="admin[]" value="'.$id.'" /></div>'."\n"; } } ?> Please notice the " if($columnId == 'BOX' && $rowId == 1) " part of my code. The rest of it is all running as I would like, and even with this bit of code in, it is still working too. However, as you will probably guess, I want the code to echo a new div ( serving the purpose of a gap on the page) if the column ID (from my database) is equal to BOX. However, nothing is happening. I have also tried the same technique using <P>. Any ideas why it's not working? Thanks in advance Dan Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/ Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Just before the while() bit add these two lines: $row=mysql_fetch_assoc($result); var_dump($row); Now right-click and view the browser source after trying it out as this will dump what your query is getting. Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792463 Share on other sites More sharing options...
DanielHardy Posted March 24, 2009 Author Share Posted March 24, 2009 ok im getting this now : array(5) { ["id"]=> string(1) "6" ["username"]=> string(0) "" ["admin"]=> string(1) "1" ["rowId"]=> string(1) "1" ["columnId"]=> string(3) "uCF" But why? Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792470 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 At least we've traced the problem back to your query. What in your table "seats" has the lowest id? Check and see what the fields contain. Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792472 Share on other sites More sharing options...
DanielHardy Posted March 24, 2009 Author Share Posted March 24, 2009 It is indeed the uCF 6 entry that it is picking up. Why is it picking this up though when I am clearly telling it to find BOX? Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792490 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 No you're not - you're requesting ORDER by id ASC which means when your query starts pulling data from the table it'll start with the lowest id then work its way up. You're then checking IF a field contains BOX. If you want to pull out the one with "BOX" you'll need to change your query... SELECT id,username,admin,rowId,columnId FROM seats WHERE columnId='BOX' Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792505 Share on other sites More sharing options...
DanielHardy Posted March 24, 2009 Author Share Posted March 24, 2009 If I do that I will only get the ones that contain box and I will ignore all the others Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792516 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Yes - in your IF you're checking for BOX against ID=1 which never will happen because BOX is associated with another ID. You need to change your IF to maybe this then: if($columnId == 'BOX') { echo '<p>Found BOX in ID '.$id.'</p>'."\n"; } (I've added some extra code in the echo to show you where BOX was found.) Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792521 Share on other sites More sharing options...
DanielHardy Posted March 24, 2009 Author Share Posted March 24, 2009 Im not calling it against ID=1. Im calling it against rowId=1 which is a different field in the table. ID is a totally seperate primary key field in the table. Sorry for any confusion Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792534 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Well if the two don't match you won't get a match of TRUE. Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792557 Share on other sites More sharing options...
DanielHardy Posted March 24, 2009 Author Share Posted March 24, 2009 just take $rowid as a separate bit of info in the table, such as firstname. it doesnt need to match anything Quote Link to comment https://forums.phpfreaks.com/topic/150852-help-with-an-if/#findComment-792571 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.