fingirl Posted August 23, 2007 Share Posted August 23, 2007 Hi there, I'm successfully dispaying some database content in a table with this code: an echo statement here... <td valign = 'top'> <a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) <a href = '".$row[characterdemo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Character Demo </a>(mp3) <a href = '".$row[animation]."' onclick=\"window.open(this.href, 'popupwindow', 'width=800, height=600, left=150, top=100, scrollbars, resizable'); return false;\">Listen to Animation Demo </a>(mp3) </td> Now I want to add a condition that the <a href ... is only displayed if the field it calls is not empty. I'm getting very confused about adding in the php to the rather lengthy snippet above. My code opens <?php right at the beginning and closes ?>right at the end. Here's where I've got to so far - but I am getting a php syntax error. Missing a comma or semi colon somewhere. an echo statement here... <td valign = 'top'>" if(!empty($row[demo])) {echo "<a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) "}; echo "<a href = '".$row[characterdemo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Character Demo </a>(mp3) <a href = '".$row[animation]."' onclick=\"window.open(this.href, 'popupwindow', 'width=800, height=600, left=150, top=100, scrollbars, resizable'); return false;\">Listen to Animation Demo </a>(mp3) </td> Any assistance greatly appreciated. Fin Quote Link to comment Share on other sites More sharing options...
Tandem Posted August 23, 2007 Share Posted August 23, 2007 You'll need to post the full code. Also it'd be helpful if you could put [code.][./code] (remove the dots) around your code so the syntax will be highlighted. Thanks Quote Link to comment Share on other sites More sharing options...
fingirl Posted August 23, 2007 Author Share Posted August 23, 2007 OK. Thanks. I've commented in code where my problem is, like so <!-- NEED TO FIX HERE --> <?php $showalltalent=$_POST['showalltalent']; $showallfemaletalent=$_POST['showallfemaletalent']; $showallmaletalent=$_POST['showallmaletalent']; //when working locally @ $db = mysql_pconnect('localhost', 'troy', 'troy1'); //when working on bluehost //@ $db = mysql_pconnect('localhost', 'finfacto_troy', 'troy1'); if(!$db) { echo 'Sorry, could not connect to database. Please try later or contact database administrator.'; exit; } //when working locally mysql_select_db('jermyntalent'); //when working on bluehost //mysql_select_db('finfacto_jermyntalent'); /* SHOW ALL RECORDS -----------------------------------------------------------------------------*/ // variables for a search to show all records $querytoshowall = "select id, firstname, lastname, shortbiog, image, demo, characterdemo, animation from talent order by firstname"; $showallresult = mysql_query($querytoshowall); $number = mysql_num_rows($showallresult); // script triggered by clicking the Show All button if(isset($showalltalent)) { echo "<h3>You requested to view all records</h3>"; while($row = mysql_fetch_array($showallresult)) { echo "<table width = '90%' border = '0' cellpadding='3'> <tr> <td valign = 'top' rowspan='4' width='56'><img src='".$row[image]."' width='110' alt='image of ".$row[firstname]. " ". stripslashes($row[lastname]). "' /></td> <td valign = 'top'><h3>".$row[firstname] . " " . stripslashes($row[lastname]). "</h3></td> </tr>"; echo "<tr> <td valign = 'top' >".stripslashes($row[shortbiog])."</td> </tr> <tr><!-- NEED TO FIX HERE --><td valign = 'top'>" if(!empty($row[demo])) {echo "<a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) "}; echo "<a href = '".$row[characterdemo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Character Demo </a>(mp3) <a href = '".$row[animation]."' onclick=\"window.open(this.href, 'popupwindow', 'width=800, height=600, left=150, top=100, scrollbars, resizable'); return false;\">Listen to Animation Demo </a>(mp3)</td> </tr> <tr> <td valign = 'top'><a href='details.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=550, height=500, left=250, top=150, scrollbars, resizable'); return false;\">More details</a> <a href = 'emailenquiry.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=650, height=500, left=200, top=150, scrollbars, resizable'); return false;\"'>Email Enquiry</a></td> </tr> </table>"; echo "<hr />"; } if($number < 1) { echo "<h3>There were no results for your search</h3>"; } mysql_free_result($showallresult); } /* SHOW ALL FEMALE RECORDS -----------------------------------------------------------------------*/ //variables for a search to find females $queryallfemales = "select id, firstname, lastname, shortbiog, image, demo, characterdemo, animation from talent where gender='female' order by firstname"; $showallfemalesresult = mysql_query($queryallfemales); $numberfemales = mysql_num_rows($showallfemalesresult); // script triggered by clicking the Show All Females button if(isset($showallfemaletalent)) { echo "<h3>You requested to view all records of females</h3>"; while($row = mysql_fetch_array($showallfemalesresult)) { echo "<table width = '90%' border = '0' cellpadding='3'> <tr> <td valign = 'top' rowspan='4' width='56'><img src='".$row[image]."' width='110' alt='image of ".$row[firstname]. " ". stripslashes($row[lastname]). "' /></td> <td valign = 'top'><h3>".$row[firstname] . " " . stripslashes($row[lastname]). "</h3></td> </tr>"; echo "<tr> <td valign = 'top' >".stripslashes($row[shortbiog])."</td> </tr> <tr> <td valign = 'top'><a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) <a href = '".$row[characterdemo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Character Demo </a>(mp3) <a href = '".$row[animation]."' onclick=\"window.open(this.href, 'popupwindow', 'width=800, height=600, left=150, top=100, scrollbars, resizable'); return false;\">Listen to Animation Demo </a>(mp3)</td> </tr> <tr> <td valign = 'top'><a href='details.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=550, height=500, left=250, top=150, scrollbars, resizable'); return false;\">More details</a> <a href = 'emailenquiry.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=650, height=500, left=200, top=150, scrollbars, resizable'); return false;\"'>Email Enquiry</a></td> </tr> </table>"; echo "<hr />"; } if($numberfemales < 1) { echo "<h3>There were no results for your search</h3>"; } mysql_free_result($showallfemalesresult); } /* SHOW ALL MALE RECORDS -------------------------------------------------------------------------*/ //variables for a search to find males $queryallmales = "select id, firstname, lastname, shortbiog, image, demo, characterdemo, animation from talent where gender='male' order by firstname"; $showallmalesresult = mysql_query($queryallmales); $numbermales = mysql_num_rows($showallmalesresult); // script triggered by clicking the Show All Males button if(isset($showallmaletalent)) { echo "<h3>You requested to view all records of males</h3>"; while($row = mysql_fetch_array($showallmalesresult)) { echo "<table width = '90%' border = '0' cellpadding='3'> <tr> <td valign = 'top' rowspan='4' width='56'><img src='".$row[image]."' width='110' alt='image of ".$row[firstname]. " ". stripslashes($row[lastname]). "' /></td> <td valign = 'top'><h3>".$row[firstname] . " " . stripslashes($row[lastname]). "</h3></td> </tr>"; echo "<tr> <td valign = 'top' >".stripslashes($row[shortbiog])."</td> </tr> <tr> <td valign = 'top'><a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) <a href = '".$row[characterdemo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Character Demo </a>(mp3) <a href = '".$row[animation]."' onclick=\"window.open(this.href, 'popupwindow', 'width=800, height=600, left=150, top=100, scrollbars, resizable'); return false;\">Listen to Animation Demo </a>(mp3)</td> </tr> <tr> <td valign = 'top'><a href='details.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=550, height=500, left=250, top=150, scrollbars, resizable'); return false;\">More details</a> <a href = 'emailenquiry.php?id=$row[id]' onclick=\"window.open(this.href, 'popupwindow', 'width=650, height=500, left=200, top=150, scrollbars, resizable'); return false;\"'>Email Enquiry</a></td> </tr> </table>"; echo "<hr />"; } if($numbermales < 1) { echo "<h3>There were no results for your search</h3>"; } mysql_free_result($showallmalesresult); } ?> Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Share Posted August 23, 2007 <tr><!-- NEED TO FIX HERE --><td valign = 'top'>" if(!empty($row[demo])) {echo "<a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3) "}; That should be <tr><!-- NEED TO FIX HERE --><td valign = 'top'>" if(!empty($row[demo])) {echo "<a href = '".$row[demo]."' onclick=\"window.open(this.href, 'popupwindow', 'width=200, height=100, left=250, top=150, scrollbars, resizable'); return false;\">Listen to Demo </a>(mp3)  ";} Semi colon after " and before }, you've put it inside the " by accident, look closely. No semi colon is required after }. Quote Link to comment Share on other sites More sharing options...
fingirl Posted August 23, 2007 Author Share Posted August 23, 2007 Thanks Matthew, your solution looked good to me, but still throws a parse error. I have looked at this for too long. Will have a breather. Fin Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Share Posted August 23, 2007 Ah! echo "<tr> <td valign = 'top' >".stripslashes($row[shortbiog])."</td> </tr> <tr><!-- NEED TO FIX HERE --><td valign = 'top'>" if(!empty( needs to be echo "<tr> <td valign = 'top' >".stripslashes($row[shortbiog])."</td> </tr> <tr><!-- NEED TO FIX HERE --><td valign = 'top'>"; if(!empty( You didn't end the echo statement before you started the if. Quote Link to comment Share on other sites More sharing options...
fingirl Posted August 23, 2007 Author Share Posted August 23, 2007 You beauty! That's great. Those syntax errors are always so obvious in the end. Appreciate the help. Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Share Posted August 23, 2007 Any time. Don't forget to mark this as solved 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.