Page 1 of 1

problems with my function and query...

Posted: Tue Jul 27, 2004 12:28 pm
by Xplosion84
function:

Code: Select all

<?php
 function calldb($query_type) {
  		$dbname = 'maxforcepc'; 
        $link = mysql_connect ('..........', '........', '..........');
        $result = mysql_query ($dbname, $query_type, $link) or die ('Queryproblem');   
        if (mysql_num_rows($result) >= 1) {   
            while ($row = mysql_fetch_array($result)) {   
                echo '<a href="' . $row['Url'] . '">' . $row['Links'] . '</a><br />';    
            }  
        } else {   
            echo 'The query could not be executed!<br />';     
        }   
        mysql_free_result($result);   
} 
?>
calling the function:

Code: Select all

<?php
calldb("SELECT * FROM nav_links WHERE Cat_Links=". $_GET['CatID']);
?>
I'm getting a parse error but my hosting company shut off php errors

feyd | removed host/user/password from db connect

Posted: Tue Jul 27, 2004 12:37 pm
by Xplosion84
oh crap whooops thanks feyd :-)

Posted: Tue Jul 27, 2004 12:59 pm
by liljester

Code: Select all

<?php 
function calldb($query_type) { 
        $dbname = 'maxforcepc'; 
        $link = mysql_connect ('..........', '........', '..........');
        mysql_select_db($dbname, $link);
        $result = mysql_query ($query_type, $link) or die ('Queryproblem');    
        if (mysql_num_rows($result) >= 1) {    
            while ($row = mysql_fetch_array($result)) {    
                echo '<a href="' . $row['Url'] . '">' . $row['Links'] . '</a><br />';    
            }  
        } else {    
            echo 'The query could not be executed!<br />';      
        }    
        mysql_free_result($result);    
} 
?>

Posted: Tue Jul 27, 2004 2:59 pm
by Joe
Should the function call not be:

Code: Select all

calldb("SELECT * FROM nav_links WHERE Cat_Links='". $_GET['CatID']."'");

Re: problems with my function and query...

Posted: Tue Jul 27, 2004 3:47 pm
by penguinboy
Xplosion84 wrote:function:

Code: Select all

<?php
$dbname = 'maxforcepc'; 
$link = mysql_connect ('..........', '........', '..........');
$result = mysql_query ($dbname, $query_type, $link) or die ('Queryproblem');
?>
http://us4.php.net/mysql_query
resource mysql_query ( string query [, resource link_identifier])
Unless it's an undocumented feature;
I don't think you can include the db in the query string.

Try:

Code: Select all

<?php
$dbname = 'maxforcepc'; 
$link = mysql_connect ('..........', '........', '..........');
mysql_select_db($dbname,$link);
$result = mysql_query ($query_type, $link) or die (mysql_error());
?>

Posted: Wed Jul 28, 2004 12:48 pm
by Xplosion84
liljester wrote:

Code: Select all

<?php 
function calldb($query_type) { 
        $dbname = 'maxforcepc'; 
        $link = mysql_connect ('..........', '........', '..........');
        mysql_select_db($dbname, $link);
        $result = mysql_query ($query_type, $link) or die ('Queryproblem');    
        if (mysql_num_rows($result) >= 1) {    
            while ($row = mysql_fetch_array($result)) {    
                echo '<a href="' . $row['Url'] . '">' . $row['Links'] . '</a><br />';    
            }  
        } else {    
            echo 'The query could not be executed!<br />';      
        }    
        mysql_free_result($result);    
} 
?>
Great!! That worked, but the odd thing is it works when it wants too. my syntax to call that function is:

Code: Select all

<?php
calldb("SELECT * FROM nav_links WHERE Cat_Links=". $_GET['CatID']);
?>
It worked when i fixed my coding then i went back to it and i'm getting a parse error

Posted: Wed Jul 28, 2004 1:38 pm
by penguinboy
Try

Code: Select all

$result = mysql_query ($query_type, $link) or die(mysql_error());
Instead of

Code: Select all

$result = mysql_query ($query_type, $link) or die('Queryproblem');

Posted: Wed Jul 28, 2004 9:50 pm
by Xplosion84
penguinboy wrote:Try

Code: Select all

$result = mysql_query ($query_type, $link) or die(mysql_error());
Instead of

Code: Select all

$result = mysql_query ($query_type, $link) or die('Queryproblem');
I'm still getting a blank page, but when i comment out the syntax that calls the function my page layout shows...

Posted: Wed Jul 28, 2004 11:10 pm
by d3ad1ysp0rk

Code: Select all

<?php
function conn(){
    $link = mysql_connect ('..........', '........', '..........');
    mysql_select_db("maxforcepc",$link);
}

function calldb($query_type) {
    $result = mysql_query ($query_type, $link) or die ('Queryproblem');   
    if (mysql_num_rows($result) >= 1) {
       while ($row = mysql_fetch_array($result)) {   
           echo '<a href="' . $row['Url'] . '">' . $row['Links'] . '</a><br />';   
       } 
    } else {   
       echo 'The query could not be executed!<br />';     
    }   
    mysql_free_result($result);
}
?>
Then call it with

Code: Select all

<?php
conn();
calldb("sql");
?>
This will keep the SQL connection alive incase you're making other sql queries.

Also, is this output going to be used on multiple pages? Or just the page you're developing now?
If it's only for one page, it'd probably be easier to include the code from calldb instead of putting it in a function.

Posted: Thu Jul 29, 2004 11:19 am
by Xplosion84
LiLpunkSkateR wrote:

Code: Select all

<?php
function conn(){
    $link = mysql_connect ('..........', '........', '..........');
    mysql_select_db("maxforcepc",$link);
}

function calldb($query_type) {
    $result = mysql_query ($query_type, $link) or die ('Queryproblem');   
    if (mysql_num_rows($result) >= 1) {
       while ($row = mysql_fetch_array($result)) {   
           echo '<a href="' . $row['Url'] . '">' . $row['Links'] . '</a><br />';   
       } 
    } else {   
       echo 'The query could not be executed!<br />';     
    }   
    mysql_free_result($result);
}
?>
Then call it with

Code: Select all

<?php
conn();
calldb("sql");
?>
This will keep the SQL connection alive incase you're making other sql queries.

Also, is this output going to be used on multiple pages? Or just the page you're developing now?
If it's only for one page, it'd probably be easier to include the code from calldb instead of putting it in a function.
I'm using one page but using includes to include other pages on the index.php...

Posted: Fri Jul 30, 2004 7:21 am
by penguinboy
http://us3.php.net/manual/en/function.e ... orting.php

Try setting this at the top of the script.

Code: Select all

error_reporting(E_ALL);