seblondres Posted September 8, 2014 Share Posted September 8, 2014 (edited) Hi, I've been working with the indeed jobs API and I have a line break after the title that Id'like to get rid off. Jobs Results: Graduate Scheme - 2015 Crossrail Ltd (2 days ago) London - Crossrail vacancies Graduate Scheme - 2015 Graduate Scheme - 2015 Job title Graduate Scheme - 2015... visit our designated Graduate Scheme page for more... Here is the code: foreach($xml->results->result as $result) {echo "<h3><a href=".$result->url.">".$result->jobtitle."</a></h3>";echo "<p><b>".$result->company."</b> (".$result->formattedRelativeTime.") <b>".$result->city."</b> - ".$result->snippet."</p>";} ?> I can't find out why there is a line break between the two echo, any idea? Many Thanks, Edited September 8, 2014 by seb_london Link to comment Share on other sites More sharing options...
dsonesuk Posted September 8, 2014 Share Posted September 8, 2014 because H3 and p tags are block elements meaning each will force a new line, you will have to apply display: inline; OR float: left; to both. possible option add class the first element <h3 class="InlineMeAndNext"><a href=".$result->url.">".$result->jobtitle."</a></h3> css .InlineMeAndNext, .InlineMeAndNext + * { display:inline;} will target h3 and first any sibling element following it. Link to comment Share on other sites More sharing options...
seblondres Posted September 8, 2014 Author Share Posted September 8, 2014 Hi, Thanks for your help. I have added the class + the css but I got the following error - see: http://gradsjobs.co.uk/ Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/emploica/gradsjobs/indeed.php on line 35 - See more at: http://gradsjobs.co.uk/#sthash.tmliP1UT.dpuf foreach($xml->results->result as $result) { echo "<h3 class="InlineMeAndNext"><a href=".$result->url.">".$result->jobtitle."</a></h3>"; echo "<p><b>".$result->company."</b> (".$result->formattedRelativeTime.") <b>".$result->city."</b> - ".$result->snippet."</p>";} ?> Link to comment Share on other sites More sharing options...
dsonesuk Posted September 8, 2014 Share Posted September 8, 2014 It because of quotes for class name echo "<h3 class="InlineMeAndNext"><a href=".$result->url.">".$result->jobtitle."</a></h3>"; you will have to escape them so they not treated as ending text to insert php coding text php original code echo "<h3><a href=".$result->url.">".$result->jobtitle."</a></h3>"; new code echo "<h3 class="InlineMeAndNext"><a href=".$result->url.">".$result->jobtitle."</a></h3>"; //see how it thinks class name is php code should be echo "<h3 class="InlineMeAndNext"><a href=".$result->url.">".$result->jobtitle."</a></h3>"; //now it ignore quotes i prefer to do it this way echo '<h3 class="InlineMeAndNext"><a href="'.$result->url.'">"'.$result->jobtitle.'"</a></h3>'; by using single quotes you don't need to escape, when you insert php you use single quotes '.$result->url.' '.$result->jobtitle.' within double, the html shown is as you would normally see it without escaping the quotes all the time, which can be difficult to spot sometimes. Link to comment Share on other sites More sharing options...
seblondres Posted September 8, 2014 Author Share Posted September 8, 2014 (edited) ok thanks a lot, the space is gone now. But the description is now next to the title instead of being just below and if I add a <br> at the end, I end up with the space again Currently: Purchasing Graduate Development Programme - UKRolls-Royce (7 days ago) - Rolls-Royce Purchasing Graduate Development Programme... possible value from that spend. Our Purchasing Graduate Development Programme is designed to give you an... But I'd like the description just below with no space between the title and the description. Purchasing Graduate Development Programme - UK Rolls-Royce (7 days ago) - Rolls-Royce Purchasing Graduate Development Programme... possible value from that spend. Our Purchasing Graduate Development Programme is designed to give you an... Edited September 8, 2014 by seb_london Link to comment Share on other sites More sharing options...
dsonesuk Posted September 8, 2014 Share Posted September 8, 2014 That's not a line break problem then, that's just a margin problem with <h3> an following paragraph option 1 .InlineMeAndNext { margin-bottom: 8px;}/* adjust to requirements */.InlineMeAndNext + * { margin-top: 8px}/* adjust to requirements */ option2 .InlineMeAndNext + * { margin-top: -16px}/* adjust to requirements */ Link to comment Share on other sites More sharing options...
seblondres Posted September 8, 2014 Author Share Posted September 8, 2014 All good, thanks a lot for your time and your patience! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now