1
ibetino
How to access a xoopsDatabase
  • 2006/11/10 8:30

  • ibetino

  • Just popping in

  • Posts: 1

  • Since: 2006/11/10


Hi,

I want to do a HTML file with a single searchform that access a new table of my XOOPS database, but I don´t know how to do it:

INDEX.HTML
<FORM ACTION="SEARCH.PHP" METHOD="POST">
Input a code: <INPUT NAME="code"><INPUT TYPE="submit">
</
FORM>

SEARCH.PHP
include("CONECTION.PHP");
include(
"FUNC.PHP");

$sql = "SELECT * FROM xoops_tablecodes WHERE code =  '$code'";

If (
$res=send_sql($db,$sql))  {
   echo 
"OK. <br> Results: <br>";
}
tab_out($res);

CONECTION.PHP
$link=mysql_connect("localhost","user","passw");
$db ="Database name";

FUNC.PHP
function send_sql($db, $sql) 
    {
         if (! 
$res=mysql_db_query($db, $sql))
    {
           echo 
mysql_error();
           exit;
    }
           return 
$res;
    }


function 
tab_out($result) 
    {
        
$cant=mysql_num_fields($result);
        
$ancho=100/$cant."%";
        echo 
"<table width=100% border=0 cellpadding='2' cellspacing='2'>";
        echo 
"<tr bgcolor=#D0D0D0>";
        for (
$i=0;$i<$cant;$i++)
    {
    echo 
"<th width='$ancho'><font size='1'> ";
    echo 
mysql_field_name($result,$i);
    echo 
"</font> </th>";
    }
    echo 
"</tr>";
    echo 
"<tr>";
    
    
$num = mysql_num_rows($result);
    for (
$j = 0; $j < $num; $j++) 
    
    {
        
$row = mysql_fetch_array($result);
        echo 
"<table width=100% border=0 cellpadding='2' cellspacing='2'>";
        echo 
"<tr bgcolor=#00FFFF>";
        for (
$k=0;$k<$cant;$k++)
    {
        
$fn=mysql_field_name($result,$k);
        echo 
" <td width='$ancho'> <font size='1'> $row[$fn] </font> </td> " ;
    }
        echo 
"<tr>";
        echo 
"</tr>";
    }
        echo 
"</table>";
    }


I need to do this in XOOPS and using de xoopsdatabase!!!!

Thanks and sorry by my english!!!

2
hervet
Re: How to access a xoopsDatabase
  • 2006/11/22 12:44

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Hello,

the minimum, in your php script, is to write this :
<?php
include_once '../../mainfile.php';

?>
use the search of this site and try to find the "empty module".