leest Posted February 1, 2008 Share Posted February 1, 2008 Ok, I have simplified my if else/ else if statement, however when i add an elseif block the code stops working. No errors are produced just the page stops displaying any contents at the point where the if else file is called from another page. Any guidance would be appreciated: Thanks if ($num1 > 0) { echo "test 1";} elseif ($num2 <1) { echo "test 2";} else {echo "Database is empty" Quote Link to comment Share on other sites More sharing options...
GameYin Posted February 1, 2008 Share Posted February 1, 2008 Hmm try something like...this. if ($num1 > 0) { echo "test 1"; } else { if { ($num2 <1) echo "test 2"; } else {echo "Database is empty" } Ok...I think that should work, if it doesn't let me know. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted February 1, 2008 Share Posted February 1, 2008 Try <?php if ( $num > 0 ) { echo 'Number is above 0'; } else if ( $num == 1 ) { echo 'Number is equal to 1'; } else { echo 'We do not currently know the status of the number.'; } ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 Ok, I have simplified my if else/ else if statement, however when i add an elseif block the code stops working. No errors are produced just the page stops displaying any contents at the point where the if else file is called from another page. Any guidance would be appreciated: Thanks if ($num1 > 0) { echo "test 1";} elseif ($num2 <1) { echo "test 2";} else {echo "Database is empty" It's almost perfect, you just need to use a } instead of a ) at the very end. Also, if no error was displayed, then you have error reporting off. Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 Thanks I changed that closing bracket and it worked perfectly, lee Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 OK, that was a bit short lived, what i have just discovered is that whilst it works fine for the if and else if parts, if both num 1 & num 2 return a value = 0 then i get the same effects as before. As for the error reporting i think it is on as i had an error earlier telling me when i had made a mistake with my database connection script, how can i check this? thanks Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 If your code is: <?php if ($num1 > 0) { echo "test 1"; } elseif ($num2 < 1) { echo "test 2"; } else { echo "Database is empty"; } ?> Then something will ALWAYS be echoed. Since this is just a snippet, the problem may be else where. What is the rest of the code for the page? Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 thanks for the reply, The whole page is pasted below, the two include pages refer to the database queries that generate num1 and num 2 and they are the parts that are working fine, well i think they are if num 1 = 1 then it displays test1 if num2 = 1 it displays test 2, the problem seems to be when num 2 = 0, though the v2 page that is included is just a page that runs one query to get a value from a database and then uses that value to run a second query and generate the result for num 2. include 'connections/db1.php'; include 'v1.php'; include 'v2.php'; session_start(); $username = $_SESSION['username']; $num1 = $_SESSION['num1']; $num2 = $_SESSION['num2']; if ($num1 > 0) { echo "test 1";} elseif ($num2 <1) { echo "test 2";} else {echo "Database is empty" Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 You have a ) instead of a } again. Also, make session_start() the very first thing, before the includes even. Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 ok i'll give it a go, sorry the closing bracket was where i copied and paste the original code, Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 OK, i moved the start() to the begining of the script made sure that the closing bracket was a }, and it's still doing the same thing, so i will look at the second include file just to make sure it isn't that. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 Adjust your script like so: <?php //Turn on error reporting ini_set('display_errors', '1'); error_reportIng(E_ALL); //Start Session session_start(); //Inlcudes include 'connections/db1.php'; include 'v1.php'; include 'v2.php'; $username = $_SESSION['username']; .... Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 OK, thanks for that, now i get the following message: "Notice: A session had already been started - ignoring session_start() in /home/sites/sbg.com/public_html/search/database_check.php on line 7" the only place i can see a session is on the page that calls for the if else wihich is contained in it's own page, if that makes sense, Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 Try this out and see what happens: <?php //Turn on error reporting ini_set('display_errors', '1'); error_reportIng(E_ALL); //Start Session session_start(); //Inlcudes echo "includeing db1.php...'; require_once('connections/db1.php'); echo "done<br>includeing v1.php..."; require_once('v1.php'); echo "done<br>includeing v2.php..."; require_once('v2.php'); echo 'done<br>'; $username = $_SESSION['username']; echo "username: {$username}<br>"; $num1 = $_SESSION['num1']; echo "num1: {$num1}<br>"; $num2 = $_SESSION['num2']; echo "num2: {$num2}<br>"; if ($num1 > 0) { echo "test 1"; } elseif ($num2 <1) { echo "test 2"; } else { echo "Database is empty"; } ?> Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 ok, I think must be something to do with the sessions, first of i got the following message: "Notice: A session had already been started - ignoring session_start() in /home/sites/harrier-recruitment.com/public_html/search/database_check.php on line 7 done includeing v1.php... " Then i removed the start session on line seven and this is all that was returned: done includeing v1.php... I think i will have to go back to the drawing board and start again as i may have made it to difficult as the current structure is as: Page 1 - calls the Include (if else ) the if else page then calls (v1.php + v2.php) and some where along the lines i think there must be a problem with the sessions as they are all registered on page one and then passed through each page, if that makes sense Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 If the script is stopping after including v1.php, the something in v1.php is halting the script. What is the code in v1.php? Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 ok, the problem only occurs when num 1 and num 2 = 0, as long as num 1 or either num 2 = 1 then the script works perfectly, below are the returns for num 1 - 1 done includeing v1.php... done includeing v2.php... done username: leest num1: 1 num2: 1 test 1 when i choose an option to lead me to num2 = 0 but num 1 = 1 i get the following done includeing v1.php... done includeing v2.php... done username: leest num1: 1 num2: 1 test 1 so the problem is my way of thinking, as it only fails when num 1 and num 2 both = 0, so i need to add more options i think done includeing v1.php... done includeing v2.php... done username: leest num1: 1 num2: 1 test 1 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 again. what is the code from v1.php and v2.php? clearly those scripts don't like it when the $num#s are set to 0 Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 This is the script from v1, it queries the candidates database to see if they are already in the database with that company, then gets their id if they are and then sees if they have applied for the job to which they are applying, if they have num 1 = will equal 1: include 'connections/db1.php'; //***** Gets Candidate ID from candidate table *************// $username = $_SESSION['username']; $SID = $_SESSION['SID']; $query = "SELECT * FROM candidate WHERE username ='$username' AND site_id ='$SID'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); $candidate_id = $row['candidate_id']; $_SESSION['candidate_id']="$candidate_id"; $JOID = $_SESSION['JOID']; $candidate_id = $_SESSION['candidate_id']; $query = "SELECT * FROM candidate_joborder WHERE candidate_id ='$candidate_id' AND joborder_id ='$JOID'"; $result = mysql_query($query)or die(mysql_error()); $num1 = mysql_num_rows($result); $_SESSION['num1']="$num1"; Quote Link to comment Share on other sites More sharing options...
leest Posted February 1, 2008 Author Share Posted February 1, 2008 The code for v2 is below, having worked out that they haven't applied it then tries to establish if they have already registered with the company advertising the job. include 'connections/db1.php'; //***** Gets Candidate ID from candidate table *************// $username = $_SESSION['username']; $SID = $_SESSION['SID']; $query = "SELECT * FROM candidate WHERE username ='$username' AND site_id ='$SID'"; $result = mysql_query($query) or die(mysql_error()); $num2 = mysql_num_rows($result); $_SESSION['num2']="$num2"; 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.