1
phillipd
Is it possible to do a MySQL query in a block
  • 2004/4/29 1:01

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Is it possible to open a MySQL db connection via php and do a query, in a block? I know you can select PHP or html, but I try this and get no output to the block. Could someone provide some example code that really works, in a block, please?

Also can you mix php AND html in a block?

Thanks, a bunch!

Doug P

2
tl
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 1:19

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


Quote:
Is it possible to open a MySQL db connection via php and do a query, in a block? I know you can select PHP or html, but I try this and get no output to the block. Could someone provide some example code that really works, in a block, please?


Yes, just remeber to inclue
global $xoopsDB;
on top of your block

Also can you mix php AND html in a block?

I don't think you can include php in html block.

3
phillipd
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 1:42

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I try the following code in a block but get no output, what am I missing? Got any sample code???

global $xoopsDB;

mysql_pconnect('localhost', 'douglas', '') or die ("Can't connect to DB");
mysql_query("USE customers");

<table cellpadding=4 border=1><tr><td>id</td><td>userid</td><td>Last</td><td>first</td><td>phone</td><td>ip
</td><td>comment</td></tr>

<?php
$query = "SELECT id,userid,last,first,phone,ip,comment FROM cdata where userid like '%doug%'";

$result = mysql_query($query);

while ($data = mysql_fetch_object($result)) {
echo "<tr>
<td>$data->id</td>
<td>$data->userid</td>
<td>$data->last</td>
<td>$data->first</td>
<td>$data->phone</td>
<td>$data->ip</td>
<td>$data->comment</td>
</tr>";
}
}
?>

</table>
</body></html>

4
tl
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:00

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


mysql_pconnect('localhost', 'douglas', '') or die ("Can't connect to DB");
mysql_query("USE customers");

echo "<table cellpadding=4 border=1><tr><td>id</td><td>userid</td><td>Last</td><td>first</td><td>phone</td><td>ip
</td><td>comment</td></tr>";

$query = "SELECT id,userid,last,first,phone,ip,comment FROM cdata where userid like '%doug%'";

$result = mysql_query($query);

while ($data = mysql_fetch_object($result)) {
echo "<tr>
<td>$data->id</td>
<td>$data->userid</td>
<td>$data->last</td>
<td>$data->first</td>
<td>$data->phone</td>
<td>$data->ip</td>
<td>$data->comment</td>
</tr>";
}



echo "</table>";


You have to echo or print the "html" in php
no need for <? ?> if you set the block to php
global $xoopsDB; is only for connection to XOOPS database. No need here.
why </body></html>? I don't think you want to stop your web rendering after the block?

If you have tested MySQL query to be working. You should be okay.



5
tl
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:06

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


Try to turn debug on while you are trying to get it work.

6
phillipd
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:15

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


That works great! Many thanks. How do you turn on this debug mode I'm hearing about?

Doug P

7
tl
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:19

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


Quote:

phillipd wrote:
That works great! Many thanks. How do you turn on this debug mode I'm hearing about?

Doug P


Glad you got it working.

to turn debug on:
System Admin->Preferences->General Settings
find Debug mode

8
phillipd
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:42

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Where does the log info go?

9
tl
Re: Is it possible to do a MySQL query in a block
  • 2004/4/29 2:46

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


In a popup window. You would have to allow popups if you were using Mozilla or Firefox.

Login

Who's Online

222 user(s) are online (145 user(s) are browsing Support Forums)


Members: 0


Guests: 222


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits