mrt003003 Posted September 29, 2011 Share Posted September 29, 2011 Hi there im trying to add a "\n" to some text and select results but its not creating a new line and is just presented across the screen, i want the data in rows. Like this: Credit Output: 50 Construction Yard Level: 1 Not like this: Credit Output: 50 Construction Yard Level: 1 $alderaancredits = "Credit Output: "; $alderaancyard = "Construction Yard Level:"; $alderaanalt = $alderaancredits."" .$row_Alderaan['Credits']." \n".$alderaancyard." ".$row_Alderaan['CYardLevel1']; The variable $alderaanalt is being used as alt in a hyperlink. Can you help please??? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/ Share on other sites More sharing options...
AltarofScience Posted September 29, 2011 Share Posted September 29, 2011 you mean like a line break? what is \n? <br /> Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273780 Share on other sites More sharing options...
jcbones Posted September 29, 2011 Share Posted September 29, 2011 \n is a newline character. It will only create a new line in a text editor, or the page source code. Browsers ignore them, that is why you must use the break rule <br />. Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273782 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Thanks for the reply, if i use <br/>, It simply outputs </br> and doesnt put the break in at all???? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273940 Share on other sites More sharing options...
freelance84 Posted September 29, 2011 Share Posted September 29, 2011 eh? so this in the html source: Credit Output:50<br/>Construction Yard Level: 1 gets displayed in your browser like: Credit Output:50<br/>Construction Yard Level: 1 and not Credit Output:50 Construction Yard Level: 1 ?? Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273943 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Yes exactly... The break is added after the data of the Credits so: $alderaanalt = $alderaancredits."" .$row_Alderaan['Credits']." </br>".$alderaancyard." ".$row_Alderaan['CYardLevel1']; Credits 50 Construction Yard 1 but instead it just outputs the </br> Credits 50 </br> Construction Yard 1 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273946 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 So, if you did this $alderaanalt = $alderaancredits."" .$row_Alderaan['Credits']."<br/>\n".$alderaancyard." ".$row_Alderaan['CYardLevel1']; Your resulting output will be displaying <br/> tags on the page? Are you using htmlentities on the string before you output it? Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273949 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 No im not... How does that work? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273951 Share on other sites More sharing options...
freelance84 Posted September 29, 2011 Share Posted September 29, 2011 You're definitely sure that in the source (when you right click and view source) it reads: Credit Output:50<br/>Construction Yard Level: 1 Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273952 Share on other sites More sharing options...
dragon_sa Posted September 29, 2011 Share Posted September 29, 2011 I see in your post when you added break rule you did this </br> That is incorrect the forward slash must be after the br like this <br/> check your code to make sure you have written this the correct way Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273965 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Hi there i see what you mean and have tried it both ways </br> or <br/> and both are just outputted.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273971 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Can you post the outputted source code and perhaps the part of the script where this is echoed? Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273972 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Heres where i assign text to two variables: $alderaancredits = "Credit Output: "; $alderaancyard = "Construction Yard Level:"; Then I assign my 3rd variable with the text from the other variables and the data from my database: $alderaanalt = $alderaancredits."" .$row_Alderaan['Credits']." <br/>".$alderaancyard." ".$row_Alderaan['CYardLevel1']; And finally i had the variable with all the text and data from the database to the alt or title of my hyperlink: echo '<a href="http://localhost/swb/planet.php?recordID='.$row_Planet['PlanetID'].'" title ="' .$alderaanalt. '"> This is then outputted as: Credits 50 <br/> Construction Yard 1 I want it to look like: Credits 50 Construction Yard 1 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273975 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Riiiiight.. You are trying to add a line break into a title tag.. That kind of information would have helped from the start Try this $alderaanalt = $alderaancredits . $row_Alderaan['Credits'] . '\n' . $alderaancyard . ' ' . $row_Alderaan['CYardLevel1']; Edit: Ignore that (that is how you do it in JavaScript).. Line breaks in title tags is only supported in some browsers.. Try using JavaScript tooltips or something.. Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273980 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Hi there, that doesnt work either?? Its outputted as: Credits 50 /n Construction Yard 1 and doesnt put the break in?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273982 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Im using mozilla firefox browser, is there no way it will work using php here? Thanks :| Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273985 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Unfortunately, no. Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273986 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Ok so whats the best way to overcome this problem please?? Is this javascript tooltip like an addon that is installed onto firefox or is it javascript source code i use on my page?? Im not sure where to start. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273988 Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 There are many options, I prefer jQuery implementation because there is less of a chance of having browser issues.. Heres a nice little list of options for you http://www.1stwebdesigner.com/css/stylish-jquery-tooltip-plugins-webdesign/ Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1273990 Share on other sites More sharing options...
mrt003003 Posted September 29, 2011 Author Share Posted September 29, 2011 Thank you, very much! Ive had a look and have it all working! Thanks for you help Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1274013 Share on other sites More sharing options...
freelance84 Posted September 29, 2011 Share Posted September 29, 2011 CSS tooltips will do the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/248071-n-within-variable/#findComment-1274027 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.