...

View Full Version : PHP SQL Fetch & Echo Help!!



ukgoped
05-03-2006, 01:11 PM
I want this script to get the contact info from the database and simply display the row i want it to..

My database structure is like this

id contact_key contact_value
1 ContactAddress 123 Test Close

and so on... any help would be appreciated..

My current code looks like this, thanks


<?php
$query = "SELECT * FROM $DB_Contact";
$result = mysql_query($query, $Link) or die('Contact get setup died with error: '.mysql_error());
while($ROW = mysql_fetch_array($result)) $sxContact[$ROW[contact_key]] = $ROW[contact_value];
?>

<table border="0" cellpadding="0" cellspacing="0" class="site_table" align="center">
<tr>
<td width="220" valign="top">
<?PHP echo parseSpecial($sxContact['ContactAddress']); ?></td>
<td width="380" valign="top">
<br/></td>
</tr>
</table>

NancyJ
05-03-2006, 01:27 PM
For future reference it helps to specify what errors you're getting/problems you're having.


<?php
$query = "SELECT * FROM $DB_Contact";
$result = mysql_query($query, $Link) or die('Contact get setup died with error: '.mysql_error());
while($ROW = mysql_fetch_array($result))
{
foreach($row as $key=>$val)
{
$sxContact[$key] = $val;
}
?>

<table border="0" cellpadding="0" cellspacing="0" class="site_table" align="center">
<tr>
<td width="220" valign="top">
<?PHP echo parseSpecial($sxContact['ContactAddress']); ?></td>
<td width="380" valign="top">
<br/></td>
</tr>
</table>

ukgoped
05-03-2006, 01:39 PM
Thanks for the reply, it's given me a error..


Contact get setup died with error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

contact_us.php


<?PHP
ob_start();
session_start();
include("includes/globals.php.inc");
include("includes/functions.php");
include("lang/".$sxSetup['Language'].".php");
include("themes/$THEME_FOLDER/config.php.inc");
include("themes/$THEME_FOLDER/header.php");
?>

<?php
$query = "SELECT * FROM $DB_Contact";
$result = mysql_query($query, $Link) or die('Contact get setup died with error: '.mysql_error());
while($ROW = mysql_fetch_array($result))
{
foreach($ROW as $contact_key=>$contact_value)
{
$sxContact[$contact_key] = $contact_value;
}
?>

<table border="0" cellpadding="0" cellspacing="0" class="site_table" align="center">
<tr>
<td width="220" valign="top">
<?PHP echo parseSpecial($sxContact['ContactAddress']); ?></td>
<td width="380" valign="top">
<br/></td>
</tr>
</table>
<?PHP
include("themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>

Thanks alot,
Chris

NancyJ
05-03-2006, 01:44 PM
echo your query - that will show you what you're passing in, I dont know whats in your includes but $DB_contact isnt set in the code that you've posted here

ukgoped
05-03-2006, 01:51 PM
Cheers,

I've just replaced this code:


<?php
$query = "SELECT * FROM $DB_Contact";
$result = mysql_query($query, $Link) or die('Contact get setup died with error: '.mysql_error());
while($ROW = mysql_fetch_array($result))
{
foreach($ROW as $contact_key=>$contact_value)
{
$sxContact[$contact_key] = $contact_value;
}
?>

With


<?php
$query = "SELECT * FROM CMS__Contact";
$result = mysql_query($query, $Link) or die('Contact get setup died with error: '.mysql_error());
while($ROW = mysql_fetch_array($result))
{
foreach($ROW as $contact_key=>$contact_value)
{
$sxContact[$contact_key] = $contact_value;
}
?>

But now the page actually loads nothing where it should, no errors are given to me though..

NancyJ
05-03-2006, 01:55 PM
what is in the source code?

ukgoped
05-03-2006, 02:06 PM
I've managed to display what i need by swtiching back to my original code with the database name placed there instead of $DB

What i need now is the code to put in my includes to make it make the variable $sxContact

That might make scence to you and it might not, if you need me to explain further then tell me lol

NancyJ
05-03-2006, 02:21 PM
That might make scence to you
nope.

try starting with

this is my code
this is the error I get.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum