SkyRanger Posted May 8, 2007 Share Posted May 8, 2007 Not sure why this isn't working, It will bring up the info if there is a bid=whatever but when it doesn't have a bid it doesn't show anything. here is what I have and you will see what I am trying todo: $origdate = $postbdate->format('M d, Y H:i'); $bid = $row['bid']; $resulta = mysql_query( "SELECT * from board_post where bid='$bid'" ) or die( "Unable to select database"); $wordnum = mysql_num_rows( $resulta ); while( $rowb = mysql_fetch_array( $resulta ) ) { if ($rowb['bpid']) { echo $rowb['blfpost']; echo "<br>"; echo $rowb['bpdate']; } else { #This section is not showing when bpid is empty or does not have a bid=$bid echo "-------"; echo "<br>"; echo $origdate; } } $origdate echos with no problem. Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/ Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 With this section: if ($rowb['bpid']) { Is that suppose to be $rowb['bid']? Or do you have a column in your MySQL table named bpid? Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247791 Share on other sites More sharing options...
warewolfe Posted May 8, 2007 Share Posted May 8, 2007 use isset() to check the variable without the script failing. Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247794 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 is bpid same bid Run this script and post o/p while( $rowb = mysql_fetch_array( $resulta ) ) { echo "<pre>"; print_r($rowb ); if ($rowb['bpid']) { echo $rowb['blfpost']; echo "<br>"; ............ ............ Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247795 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 No, that part is correct. I have a bid and bpid but as I mentioned I can get the show part if it exists but can't get it to show the not exists part which is the ----- and $origpost; data Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247796 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 2 tables Table 1 just has bid table 2 has bid and bpid T1 bid = T2 bid bid = Board ID bpid = Board Post ID If bid=$bid in T2 is not there then I want it to echo ---- and $orig... Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247797 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 is bpid same bid Run this script and post o/p while( $rowb = mysql_fetch_array( $resulta ) ) { echo "<pre>"; print_r($rowb ); if ($rowb['bpid']) { echo $rowb['blfpost']; echo "<br>"; ............ ............ Table is empty so it will display nothing. Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247799 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 if (isset($rowb['bpid']) and is_numeric($rowb['bpid'])) { echo $rowb['blfpost']; echo "<br>"; ........ ....... Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247800 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 If table is empty then it will not go in to while loop....... Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247802 Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 Dumb question but I'll ask anyway... Are there any 'bpid' rows in your database that are empty... NULL? Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247805 Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 if (!isset($rowb['bpid'])) { echo "OrigDate: " . $origdate; } Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247809 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 My table is empty, so Not sure what the problem is. In my board table there is a bid in my board_post table there is nothing. When there is nothing in the board_post table it should read $origpost Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-247997 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 if(mysql_num_rows($resulta)){ while( $rowb = mysql_fetch_array( $resulta ) ) { if ($rowb['bpid']) { echo $rowb['blfpost']; echo "<br>"; echo $rowb['bpdate']; } else { #This section is not showing when bpid is empty or does not have a bid=$bid echo "-------"; echo "<br>"; echo $origdate; } } }else{ #This section is not showing when bpid is empty or does not have a bid=$bid echo "-------"; echo "<br>"; echo $origdate; } Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248005 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 Grrrr..... if(mysql_num_rows($resulta)){ while( $rowb = mysql_fetch_array( $resulta ) ) { if ($rowb['bpid']) { echo $rowb['blfpost']; echo " "; echo $rowb['bpdate']; } else { #This section is not showing when bpid is empty or does not have a bid=$bid # echo "-------"; # echo " "; echo $origdate; } }} This isn't working either. I am not sure what the heck is going on. Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248028 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248105 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 Ok, not sure if I explained it properly to what I am trying to do: Table 1 (board) bid btitle bmsg bdate etc.... Table 2 (board_post) bpid bid blpost bpdate What I am trying to do is: $origdate = $postbdate->format('M d, Y H:i') $bid = $row['bid']; $resulta = mysql_query( "SELECT * from board_post where bid='$bid'" ) or die( "Unable to select database"); $wordnum = mysql_num_rows( $resulta ); while( $rowb = mysql_fetch_array( $resulta ) ) { if ($rowb['bpid']) { echo $rowb['blfpost']; echo "<br>"; echo $rowb['bpdate']; } else { echo "-------"; echo "<br>"; echo $origdate; } } This will display if the bid = $bid and bpid is there echo $rowb['blfpost']; echo "<br>"; echo $rowb['bpdate']; But if there is no $bid it will not display the echo "-------"; echo "<br>"; echo $origdate; Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248144 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248218 Share on other sites More sharing options...
MadTechie Posted May 8, 2007 Share Posted May 8, 2007 whats the problem/error/question!! Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248229 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 Weird things is I am not getting any errors, The problem is that if bid is not existing in board_post then the } else { code } is not displaying. Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248233 Share on other sites More sharing options...
SkyRanger Posted May 8, 2007 Author Share Posted May 8, 2007 taith if you see this post, thanks, I just found my fix in another thread that was replied to by you. Anybody else that is looking for help, best thing to do is keep searching the forum while you are still waiting for help, because you may end of finding the answer: $origdate = $postbdate->format('M d, Y H:i'); $bid = $row['bid']; $sql = mysql_query("SELECT * FROM board_post where bid='$bid'"); if(mysql_num_rows($sql)==0){ echo "-----"; echo "<br>"; echo $origdate; }else{ while($rowb = mysql_fetch_array($sql)) { echo $rowb['blfpost']; echo "<br>"; echo $rowb['bpdate']; } } Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248245 Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 YAY! I WIN! *pats himself on the head* what do i win? Quote Link to comment https://forums.phpfreaks.com/topic/50439-solved-problem/#findComment-248256 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.