renegade44 Posted December 19, 2008 Share Posted December 19, 2008 Parse error: syntax error, unexpected '<', and I also get one with a ',' or ';'. here is my code:if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo <div class='title_class'>.$row['title'].</div>; '.$row['sd'].'<br /> Posted by : <b>'.$row['author'].'</b><br /> '.$row['post'].'<br /> <a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>'; } } else { echo 'There are no news posts to display'; } ?> </body> </html> the line with the error is: echo <div class='title_class'>.$row['title'].</div>; If I take out the div class, it works normal, so Ive gotten as far as to dtermine that I am not properly doing the div class correctly. I am basically trying to add CSS to the news posts in the news management system I have in place, I cant seem to get around this no mater what I try so I would be extremely thankful if someone here manages to help me fix this. Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/ Share on other sites More sharing options...
n3ightjay Posted December 19, 2008 Share Posted December 19, 2008 try: echo "<div class='title_class'>.$row['title'].</div>"; Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719839 Share on other sites More sharing options...
renegade44 Posted December 19, 2008 Author Share Posted December 19, 2008 ok, tried it and got this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719845 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 echo "<div class='title_class'>" . $row['title'] . "</div>"; He forgot quotes around $row['title'] Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719849 Share on other sites More sharing options...
renegade44 Posted December 19, 2008 Author Share Posted December 19, 2008 im getting this error: arse error: syntax error, unexpected T_STRING in the next line down now. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719910 Share on other sites More sharing options...
flyhoney Posted December 19, 2008 Share Posted December 19, 2008 <?php if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <div class="title_class"> <?php echo $row['title'] ?> </div> <?php echo $row['sd'] ?> <br /> Posted by : <strong><?php echo $row['author'] ?></strong> <br /> <?php echo $row['post'] ?> <br /> <a href="javascript:openComments('comments.php?id=<?php echo $row['id'] ?>')">Add new comment or view posted comments</a> <?php } } else { echo 'There are no news posts to display'; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719913 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 Look up PHP Proper Syntax please. These are really basic errors you should be able to solve yourself. <?php if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo "<div class='title_class'>" . $row['title'] . "</div> " . $row['sd'] . "<br /> Posted by : <b>" . $row['author'] . "</b><br /> " . $row['post'] . "<br /> <a href=\"javascript:openComments('" . $url . "')\">Add new comment or view posted comments</a></p>"; } } else { echo 'There are no news posts to display'; } ?> </body> </html> How you were going in and out the echo statement and mixing and matching all different types of " and ' was causing the error. Above should be formatted properly Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719914 Share on other sites More sharing options...
flyhoney Posted December 19, 2008 Share Posted December 19, 2008 Just fyi, in alternate syntax (which is better for displaying html): <?php if ($result): ?> <?php while ($row = mysql_fetch_assoc($result)): ?> <div class="title_class"><?php echo $row['title'] ?></div> <?php echo $row['sd'] ?><br /> Posted by : <strong><?php echo $row['author'] ?></strong><br /> <?php echo $row['post'] ?><br /> <a href="javascript:openComments('comments.php?id=<?php echo $row['id'] ?>')">Add new comment or view posted comments</a> <?php endwhile; ?> <?php else: ?> There are no news posts to display <?php endif; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719917 Share on other sites More sharing options...
renegade44 Posted December 19, 2008 Author Share Posted December 19, 2008 ok, I got it to work, thanks for your help guys, I will look up proper syntaxs, im like a week into PHP so I need to read alot of material at this point., im going to try and add div class to the other $rows, hopefully I dont ruin the internet lol. Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719920 Share on other sites More sharing options...
renegade44 Posted December 19, 2008 Author Share Posted December 19, 2008 ok, I added the divs to each element and I have it where I get no errors. here is my code if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $url = 'comments.php?id='.$row['id']; echo "<div class='title_class'>" . $row['title'] . "</div> "; "<div class='date_class'>" . $row['sd'] . "</div> "; "<div class='post_class'>" . $row['post'] . "</div> "; " <a href=\"javascript:openComments('" . $url . "')\">Add new comment or view posted comments</a></p>"; } } else { echo 'There are no news posts to display'; } ?> </body> </html> the weird thing is that just the "title" field is showing up on the website, the other fields are not there. im sorry for coming off like a noob lol, i guess I am, I basically replicated what you did for the first tag, and did the same for the other tags, hopefully its something minor I can fix. Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719950 Share on other sites More sharing options...
flyhoney Posted December 19, 2008 Share Posted December 19, 2008 This code is invalid: <php echo "<div class='title_class'>" . $row['title'] . "</div> "; "<div class='date_class'>" . $row['sd'] . "</div> "; ?> You need to either echo each line, or concatenate them with the '.' operator, like so: <?php echo "<div class='title_class'>" . $row['title'] . "</div> "; echo "<div class='date_class'>" . $row['sd'] . "</div> "; ?> or <?php echo "<div class='title_class'>" . $row['title'] . "</div> " . "<div class='date_class'>" . $row['sd'] . "</div> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-719956 Share on other sites More sharing options...
renegade44 Posted December 23, 2008 Author Share Posted December 23, 2008 hey guys, I was able to get everything working except one thing, I would like to be able to edit the "post comments" font, I am ssuming the issue I have is the ahref:javascript,etc thats in the middle, do you guys have any idea how to set it up so I can apply CSS to the last line? Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-722761 Share on other sites More sharing options...
flyhoney Posted December 24, 2008 Share Posted December 24, 2008 <?php echo "<a style=\"font-size: 12px; font-weight: bold; color: #000;\" href=\"javascript:openComments('$url)\">Add new comment or view posted comments</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137711-keep-getting-errors-when-tryng-to-apply-css/#findComment-723134 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.