rocky48 Posted August 15, 2013 Share Posted August 15, 2013 Hi I am trying to use goto in my script to jump around some code that causes the header to be displayed when there is on data to fill the table. The code uses MySQL to query a database and present the data in a table. Prceddining the main code is some code to check whether any lines of data are found and if none it shows a message on the screen. It then still runs the code that produces the table and consquently only shows the table header. I have tried using the test for data with a goto label at the end of the code, but I get a parse error: Parse error: syntax error, unexpected T_STRING in /homepages/43/d344817611/htdocs/Test/index.php on line 119 Here is the code I am running: <?php include("RelHol_connect.php"); doDB(); //verify the Event exists $verify_Event_sql = "SELECT Events.ID, Events.Event_Date, Events.Event_Description, Religion.ID, Religion.Religion FROM Events LEFT JOIN Religion ON Events.Faith_ID = Religion.ID WHERE DAY(Events.Event_Date)= Day(Now()) And MONTH(Events.Event_Date)=Month(Now()) And YEAR(Events.Event_Date)=YEAR(Now()) ORDER BY Events.Event_Date ASC"; $verify_Event_res = mysqli_query($mysqli, $verify_Event_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($verify_Event_res) < 1) { //this Event does not exist $display_block = "<p><em>No Religious festivals or holidays today.</em></p>"; } if (mysqli_num_rows($verify_Event_res) < 1) goto End //gather the Events $get_Event_sql = "SELECT Events.ID, Events.Event_Date, Events.Event_Description, Events.Faith_ID, Religion.ID, Religion.Religion FROM Events LEFT JOIN Religion ON Events.Faith_ID = Religion.ID WHERE DAY(Events.Event_Date)= Day(Now()) And MONTH(Events.Event_Date)=Month(Now()) And YEAR(Events.Event_Date)=YEAR(Now()) ORDER BY Events.Event_Date ASC"; $get_Event_res = mysqli_query($mysqli, $get_Event_sql) or die(mysqli_error($mysqli)); //create the display string $display_block .= " <table width=\"100%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"#87CEEB\" > <tr> <th>RELIGION</th> <th>EVENT</th> </tr>"; while ($Event_today = mysqli_fetch_array($get_Event_res)) { $Rel_Date = $Event_today['Event_Date']; $Rel_Event = $Event_today['Religion']; $Event_text = $Event_today['Event_Description']; //add to display $display_block .= " <tr> <td width=\"8%\" valign=\"top\">".$Rel_Event."<br/></td> <td width=\"25%\" valign=\"top\">" .$Event_text."<br/></td>"; } //free results mysqli_free_result($get_Event_res); //close connection to MySQL mysqli_close($mysqli); //close up the table $display_block .="</table>"; echo $display_block; End: ?> Can anyone help please! Quote Link to comment Share on other sites More sharing options...
Solution AbraCadaver Posted August 15, 2013 Solution Share Posted August 15, 2013 (edited) If you're using goto you're doing it wrong. There are many other ways to do what you want. 1. Change your IF to do that stuff if there ARE rows 2. Instead of goto End you could just exit; Edited August 15, 2013 by AbraCadaver 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.