Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Xplosion84
Forum Newbie
Posts: 9 Joined: Wed Jun 16, 2004 1:30 pm
Post
by Xplosion84 » Tue Jul 27, 2004 12:28 pm
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
Xplosion84
Forum Newbie
Posts: 9 Joined: Wed Jun 16, 2004 1:30 pm
Post
by Xplosion84 » Tue Jul 27, 2004 12:37 pm
oh crap whooops thanks feyd
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Tue Jul 27, 2004 12:59 pm
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);
}
?>
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 27, 2004 2:59 pm
Should the function call not be:
Code: Select all
calldb("SELECT * FROM nav_links WHERE Cat_Links='". $_GET['CatID']."'");
penguinboy
Forum Contributor
Posts: 171 Joined: Thu Nov 07, 2002 11:25 am
Post
by penguinboy » Tue Jul 27, 2004 3:47 pm
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());
?>
Xplosion84
Forum Newbie
Posts: 9 Joined: Wed Jun 16, 2004 1:30 pm
Post
by Xplosion84 » Wed Jul 28, 2004 12:48 pm
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
penguinboy
Forum Contributor
Posts: 171 Joined: Thu Nov 07, 2002 11:25 am
Post
by penguinboy » Wed Jul 28, 2004 1:38 pm
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');
Xplosion84
Forum Newbie
Posts: 9 Joined: Wed Jun 16, 2004 1:30 pm
Post
by Xplosion84 » Wed Jul 28, 2004 9:50 pm
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...
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Wed Jul 28, 2004 11:10 pm
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
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.
Xplosion84
Forum Newbie
Posts: 9 Joined: Wed Jun 16, 2004 1:30 pm
Post
by Xplosion84 » Thu Jul 29, 2004 11:19 am
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
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...