xoops forums

sarahmx

Quite a regular
Posted on: 2010/2/24 14:14
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#1

add php code and mysql query in any content module editor ?

maybe this a stupid question


How do i properly add my php code or MySQL query to a content module like news or content ...

?

i put my code in basic editor and it is not display correctly in browser..

help

sarahmx

Quite a regular
Posted on: 2010/2/26 23:08
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#2

Re: add php code and mysql query in any content module editor ?

bump

ForMusS

Core Developer
Posted on: 2010/2/26 23:44
ForMusS
ForMusS (Show more)
Core Developer
Posts: 146
Since: 2007/10/19
#3

Re: add php code and mysql query in any content module editor ?

You must use code balise for display code

MusS

sarahmx

Quite a regular
Posted on: 2010/2/27 1:03
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#4

Re: add php code and mysql query in any content module editor ?

i don't want to display the code...

i want to run the code

what i want to do is actually to show a data using query from database

sarahmx

Quite a regular
Posted on: 2010/3/3 13:16
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#5

Re: add php code and mysql query in any content module editor ?

anyone ?

is this even possible ?

kaotik

Just can't stay away
Posted on: 2010/3/3 13:25
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#6

Re: add php code and mysql query in any content module editor ?

Are you tring to add content to a module or to a wysiwyg editor?

For the first:
Yes it's possible. There are 2 ways of accomplishing this:
1- Without use of smarty templates
In this case open the corresponding php file (for ex: article.php), perform your db query and output the result [echo $var;]. Be advised that this method could break ajax functionality if it exists in the module.
2- With smarty templates
This method stats the same as method 1, but instead of using an "echo" you will insert a new smarty var. This requieres changes in 2 files; the php file and smarty template.

sarahmx

Quite a regular
Posted on: 2010/3/3 15:21
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#7

Re: add php code and mysql query in any content module editor ?

i dont understand kaotik..im new to php and i think i should explain myself again..sorry my english sucks

what i really want to do is to post an article using the content module by formuss..

in the article i want to show a table ..the data in the table is from my db


example of my query
<?php
global $xoopsDB;
$result mysql_query("SELECT * FROM ".$xoopsDB->prefix("section_info")." WHERE Unit='Pharmacy' ORDER BY senioriti");

$count =1;
echo 
"<table><tr class='head'>";
echo 
"<td>No</td>";
echo 
"<td>Name</td>";


$style=0;

while(
$row mysql_fetch_array($result))
{
$my_id=$row['my_id']; 

echo 
'<tr class="', ++$style 'even' 'odd''">'
echo 
"<td>"
echo 
$count++;
echo 
"</td>";
echo 
"<td><b>" $row['name'] . "</b></td>";
echo 
"</tr>";
}
 echo 
"</table>";echo "";
  
?>


so how can i use the code above to post it in my content ?

sarahmx

Quite a regular
Posted on: 2010/3/5 16:44
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#8

Re: add php code and mysql query in any content module editor ?

bump

frankblack

Just can't stay away
Posted on: 2010/3/5 16:54
frankblack
frankblack (Show more)
Just can't stay away
Posts: 830
Since: 2005/6/13
#9

Re: add php code and mysql query in any content module editor ?

You cannot execute PHP when you paste it into any content module. But you can use jquery/Ajax to do this for you. You "just" have to write an Ajax to pull some information from the database and load into a div or something else.

Should work? One obstacle could be, that - depending on the used editor - javascript might be filtered. But tinymce or tinyeditor (others I don't know) can be configured that way, that javascript is allowed.

sarahmx

Quite a regular
Posted on: 2010/3/5 16:59
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#10

Re: add php code and mysql query in any content module editor ?

thanks for the idea....frankblack

will learn ajax asap..and try this soon.......will post here for update and problem