Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP SQL Fetch & Echo Help!!

    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 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)) $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>

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    For future reference it helps to specify what errors you're getting/problems you're having.

    PHP 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 $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>

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply, it's given me a error..

    Code:
    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 Code:
    <?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
    Last edited by ukgoped; 05-03-2006 at 01:41 PM. Reason: Typo error

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers,

    I've just replaced this code:

    PHP 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 Code:
    <?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..

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    what is in the source code?

  • #7
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by ukgoped
    That might make scence to you
    nope.

    try starting with

    this is my code
    this is the error I get.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •