chmpdog Posted December 3, 2008 Share Posted December 3, 2008 Hola, In my script I have a variable, and I need to echo it. But here is the tricky part. I need to echo it in a certain place in a paragraph, which is taken from MySql. So, does anyone know how to do this? Thankyou Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/ Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 I am a little confused. Let me try to clarify. You have a paragraph (i will use a sentence for example sake): "Hello my name is Name!" and you want to put some one's name in there? Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704619 Share on other sites More sharing options...
haku Posted December 3, 2008 Share Posted December 3, 2008 Elaborating on that: $name = 'John'; $paragraph = 'My name is NAME'; $formatted_paragraph = str_replace('NAME', $name, $paragraph); Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704622 Share on other sites More sharing options...
chmpdog Posted December 3, 2008 Author Share Posted December 3, 2008 Im pretty sure that will work... Thanks Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704636 Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 I am sure this will do the same try it mate....... <?php $sql="select SUBSTRING(field_name,-4) from table_name"; $res=mysql_query($sql)or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704653 Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 I am sure this will do the same try it mate....... <?php $sql="select SUBSTRING(field_name,-4) from table_name"; $res=mysql_query($sql)or die(mysql_error()); ?> that is assuming my example was what he actually needed. Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704655 Share on other sites More sharing options...
corbin Posted December 3, 2008 Share Posted December 3, 2008 Uhm.... What?! Edit: That was at redarrow. Also, it wouldn't work alone because he would have to concatenate the name (or whatever) to the end. Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704657 Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 say in the database you had "my name is john" why wouldnt it just echo john from the field name from the database........ <?php $sql="select SUBSTRING(name,-4) from text where id='$session_id'"; $res=mysql_query($sql)or die(mysql_error()); while($rec=mysql_fetch_assoc($rec)){ echo " ".$rec["name"]." "; } ?> Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704675 Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 yeah but if the name is changing frequently, then it woulnt work. Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704677 Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 u can use REGEXP in the select statement, to show the word afther the 3rd space in the database field and that word can be any size......... Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704684 Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 Well still, you are basing your code off of my example. The OP stated that there is a paragraph and he needed to change something within the paragraph. The easiest solution is str_replace() Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704722 Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 Agree sorry......... Link to comment https://forums.phpfreaks.com/topic/135281-variable-in-a-mysql-table/#findComment-704733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.