Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2012, 03:43:27 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155367 Posts in 21695 Topics by 7729 Members
Latest Member: piset
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Code Section and mySQL query  (Read 577 times)
dezu

Offline Offline

Posts: 4


« on: June 23, 2008, 03:23:58 PM »

Hello, I have a problem with mysql query.
I am just trying to display a simple table with telephone numbers from database.

I paste above code into code section and It doesn't work. I get white screen with no errors or anything.

Code:
<?php
$sql 
mysql_connect('192.168.1.160''dir''l94Qq72')
or die(
'Cannot connect to mysql server: ' mysql_error());
mysql_select_db('asterisk') or die(mysql_error()); 
$result123 mysql_query("SELECT extension,name,directdid FROM users WHERE extension >= 630 AND extension < 680 ORDER BY extension") or die(mysql_error());
echo 
"<br />";
echo 
"<span style=\"border-bottom: 1px dashed;\"><strong>WJ Parking</strong></span><br />";
echo 
"<br />";
echo 
"<table onMouseover=\"changeto(event, '#E2DBCB')\" onMouseout=\"changeback(event, '#F3F0E9')\" border=\"0\" class=\"texts\" width=\"540\"/>";
echo 
"<tr id=\"ignore\" bgcolor=\"#E2DBCB\"><td width=\"20%\"><b>Extension</b></td><td width=\"50%\"><b>Name</b></td><td width=\"30%\"><b>Direct Dial</b></td></tr>";
while(
$wiersz=mysql_fetch_array ($result123)) {
echo 
"<tr bgcolor=\"#F3F0E9\">
<td width=\"20%\">"
.$wiersz['extension']."</td>
<td width=\"50%\">"
.$wiersz['name']."</td>
<td width=\"30%\">"
.$wiersz['directdid']."</td>
</tr>"
;
}
echo 
"</table>";
mysql_close($sql);

?>


Do you know if it's possible to use mysql queries in code section?
If not what is the best way to do mysql queries in website baker.

Regards,
Mike
Logged
dezu

Offline Offline

Posts: 4


« Reply #1 on: June 23, 2008, 03:34:14 PM »

I sorted it out.

The solution is:

add WYSWIG section after code section Smiley.

It's a bit silly but it works Smiley.


Regards,
Mike
Logged
pcwacht
AddOn Development
*
Offline Offline

Posts: 2854



WWW
« Reply #2 on: June 23, 2008, 03:49:21 PM »

The problem lies in opening a connection to the database and NOT restoring the connection WB needs.

Search forum, been covered before

Allso, if the table is in the same database wb uses you could use the functions wb has:
Code:
<?php
$result123 
$database->query("SELECT extension,name,directdid FROM users WHERE extension >= 630 AND extension < 680 ORDER BY extension");
echo 
"<br />";
echo 
"<span style=\"border-bottom: 1px dashed;\"><strong>WJ Parking</strong></span><br />";
echo 
"<br />";
echo 
"<table onMouseover=\"changeto(event, '#E2DBCB')\" onMouseout=\"changeback(event, '#F3F0E9')\" border=\"0\" class=\"texts\" width=\"540\"/>";
echo 
"<tr id=\"ignore\" bgcolor=\"#E2DBCB\"><td width=\"20%\"><b>Extension</b></td><td width=\"50%\"><b>Name</b></td><td width=\"30%\"><b>Direct Dial</b></td></tr>";
if(
$query_users->numRows() > 0) {
  while(
$wiersz $result123->fetchRow()) {
    echo 
"<tr bgcolor=\"#F3F0E9\">
     <td width=\"20%\">"
.$wiersz['extension']."</td>
     <td width=\"50%\">"
.$wiersz['name']."</td>
     <td width=\"30%\">"
.$wiersz['directdid']."</td>
     </tr>"
;
  }
}
echo 
"</table>";
?>


good luck,
John
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
dezu

Offline Offline

Posts: 4


« Reply #3 on: June 24, 2008, 09:19:56 AM »

Thanks a lot John.

That was very useful.
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!