Edit Script Output with Stylesheet - php

How are you?
I have a problem with the output of an internal webpage I use to print a query. It is ultimately just a formatting problem with the output.
The actual script (get_data.php) should do nothing more than to create an output for a certain topic or for a certain category (for example, records with the value "DVD" or books of an author).
That's exactly what it's supposed to do.
Now I have the problem that when I create the output this is not displayed correctly.
The actual text block sits one line below the bullet point. This is not earth-shattering but it does not look quite so pretty, so I would like to fix it. ;)
The website uses some stylesheets to give it their formatting, but the bullets or the list are generated by script. But I'm standing in front of the mountain and can not continue with this "formatting problem".
Can you help me?
Many thanks in advance
Dennis
PS: I hope my english isn't to bad.

Related

PHP snippet always shows in the top of page in wordpress

I'm currently using a database search in wordpress wherein I show the results in the result page via snippets.
The problem is the results always get displayed in the top of page. I do understand php executes first before html, but is there a way to get the results displayed where I want?
Code:
Wordpress: [xyz-ips snippet="industry"]
Php:
$com=$_GET['company'];
$sql2 = "SELECT count(1) i from data where sector= (SELECT sector from data where company like '$com%')";
$rows2 = $wpdb->get_results($sql2 );
echo ' '.$rows2[0]->i.' ';
Long story short, you need to find where in WordPress the string of HTML is being output.
Then, you move it to where you want the HTML to be output.
The general idea, as you said, is that PHP executes (echo $html) before your browser reads the HTML sent by PHP. Your PHP script will run in order, top to bottom, so by moving sections of PHP that output HTML (or anything) to a different part of your script, you change its location on the page.
It's hard to give further input without understanding your situation in detail. I would highly recommend browsing the documentation for your "WordPress search" to see if there is a best practice for accomplishing what you want.
Thanks to the intelligent community here, they are more curious to downvote than to help fellow mate.!
I discovered after much search that the php version caused this. I downgraded (from the current 5.6) to 5.5 and that solved the issue.
This might help someone who is searching for a similar answer.

ModX revo 2.2x: How to use a TV value to set tpl?

I'm trying to figure out a way to render a resource with a specific tpl based on a template variable(tv) value. here is my use case:
I have setup a modx installation for a basic site with a homepage and a blog (I used the articles add-on). I want to display blog posts on the home page, outside of the articles container. From my experience the easiest way to do this is with getResource. However for this specific project I would like to change the tpl of the getResources results based on whatever the tv value is for each result.
The template variable can be looked at as a "post type". if you choose "text" it would have tplA, if you choose "multimedia" it would have tplB etc...
now based on my research you would use the properties 'tplCondition' and 'conditionalTpls' to achieve this in your getResources call, something like this:
[[getResources?
&tplCondition=`tv.blogPostType`
&conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
&tpl=`defaultTpl`
]]
The problem is, this does not seem to work with template variables :( it even says it only uses resource fields in the documentation.....which is a REAL bummer, as i have no idea to pull this off otherwise. Based on my limited knowledge, you can maybe create a snippet or something that does this, But i have no clue.
Does anyone have an elegant solution to this problem?
to sum up what im trying to do, again:
-assign a "post type" to blog posts in my articles container via template variable.
-use the template variable value to set a specific tpl based on that value.
any help is highly appreciated. thanks
EDIT: okay I got a reply on the forums and have come across a"solution" to this.
you can accomplish this with css. in the tpl, you do something like:
<article class="[[+tv.post-type]]">....</article>
this will output the post type selected in the tv as the actual element class used, and you can then use css to give the output different looks based on the tv. its actually so simple im a little embarrased i didnt see it before. In my situation it 100% solves my problem, however if you needed to chasnge html im guessing javascript would need to be involved or another method with php. just leaving this here in case someone needs it!
If you need to do major changes to the html you could still probably solve it with css if you have a nice markup. However if thats not enough i would solve it by using one tpl for the getresources call, and letting that tpl handle the switching. If you could have your TV output the value symbolize the name of the tpl that should be used in each case, your tpl would only need this:
[[$[[+tv.yourtv]]]]
Your tv will be evaluated first, and then it will be processed as a chunk. That way you dont need a nasty switch or if-clause.
This is assumin you want toally different tpls, and not just need to change some small part of the standard tpl, in that case you could still use this tecnique though!
Conditional templates seem to work fine with pdoResources (part of pdoTools). (I have to put "tv." in front of the TV in the tplCondition but not in the other TVs)
James is correct.
[[pdoResources?
&includeTVs=`blogPostType`
&tplCondition=`tv.blogPostType`
&conditionalTpls=`{"1":"tplA","2":"tplB","3":"tplC"}`
&tpl=`defaultTpl`
]]

How to display text in the same format as added in mysql text field using php echo

I want to display a large amount of text using a php echo command. I have that data stored in mysql database table in a text field. What i want to achieve is that the data should be displayed in the same manner in which i store it in the text field.
for example:
As entered in Mysql table by its Interface One reason people lie is to achieve personal power.
Achieving personal power is helpful for someone who pretends to be more confident than he really is. For example, one of my friends threw a party at his house last month. He asked me to come to his party and bring a date.
Although this lie helped me at the time, since then it has made me look down on myself.
Should be displayed exactly as the above rather than:
One reason people lie is to achieve personal power.
Achieving personal power is helpful for someone who pretends to be more confident than he really is. For example, one of my friends threw a party at his house last month. He asked me to come to his party and bring a date.
Although this lie helped me at the time, since then it has made me look down on myself.
Any ideas/tips on how this can be achieved?
I know that i can manually insert html tags between the text for formatting but i dont want to manually do so. Any way around?
nl2br($foo); will automatically add a <br> tag wherever there is a linebreak in $foo. You can echo nl2br($foo);.
As an alternative, try the <pre> tag. <pre><?php echo $foo; ?></pre>. You many need more styling, but it will preserve whitespace like your linebreaks.
My solution is:
I'm using GWT TextArea textAreaWidget widget.
Before insert the TextArea string to MySQL table I replace all line change and tab characters:
-new line
String toInsert=textAreaWidget.getText().replaceAll(Character.toString((char) 10), "\n\r"));
-tab
String toInsert=textAreaWidget.getText().replaceAll(Character.toString((char) 9), "\t"));
Example:
http://www.tutorialspoint.com/gwt/gwt_textarea_widget.htm

Best way to create an auto-rotating "news" feed on a website?

my client is asking for an auto-rotating news feed type thing on their site. The content will not change, but it will automatically move from item to the next. It will also allow the user to mouse over previous items and hold them in place.
This is best shown by the type of thing you find on Yahoo's homepage:
The four news items will auto-rotate, but when a user puts their mouse over one (as shown), it will stop rotating and just show that one, until they move it away (then it will continue auto-rotating).
I imagine I can do this with a lot of $('item1').fade and $('item2').appear type malarky using Prototype and Scriptaculous, but I was wondering if there was a better way, or an existing bit of code I could use (it seems like quite a common thing, these days).
Thanks for any tips or assistance!
Took a little googling to find one but this looks exactly like your provided example:
http://www.agilecarousel.com/flavor_2.htm
Here are some other, simpler carousels that have been out in the wild for a little longer:
http://sorgalla.com/projects/jcarousel/
http://www.thomaslanciaux.pro/jquery/jquery_carousel.htm
http://www.baijs.nl/tinycarousel/
Hope this helps and good luck!

values not getting stored in the database

I have a image slideshow each image sliding after 4 seconds and a message is displayed at end of each slide. I could record the message when button is clicked but couldn't record the message at the end of each slide if button is not clicked.
Here is my code:
and I also want to display random images without repetition. Can anyone help me with this?
Thank you,
Try to add second parameter to mysql_fetch_array eg:
mysql_fetch_array($result, MYSQL_ASSOC)
or use mysql_fetch_assoc instead.
This is just a general answer, but hopefully it can help you a bit. In your question, you posted a whole bunch of code for us to deduce the problem. This is both a good thing and a bad thing. It is good because you have posted enough information for us to be able to help you and figure out what is going on.
However, it is also bad, not in the sense that you are doing something bad, but in the sense that it is highlighting where you are having your problem solving this issue. Again generalizing, problems with code are usually simple in nature. They become complex because of the complexity surrounding and obscuring them. In order to help you with this problem, and in order to help yourself (both in general and in this case), you should start by narrowing down the scope of where the problem occurs.
For instance, in your question, you say you have an issue recording a message. However then you say "I could record the message when button is clicked. " So you have introduced a new variable into your question without telling us about the button. So we aren't sure anymore if you are having an issue with the button, or with recording the message.
So what I am saying is, narrow down your problem, and nail it down. You should be able to make a solid statement like this: There is a button, that when clicked should record a message. However, when my application moves a slide from one to the next, the button no longer works. In order to do this, you will need to define exactly what behavior you are trying to make happen. Even if this isn't a formal project, you should make a use case (even in notepad is fine) where you exactly describe what functionality you are trying to make happen (implement). You will then be able to exactly describe how your code is not doing what you said you want it to do.

Categories