Jump to content

Not Retrieving Database Information


JayLewis

Recommended Posts

I want to display information from my database. The code i am currently using does not work...

 

any help would be appreciated.

 

 

<?
    $usr = "ktmc_jay";
    $pwd = "123456";
    $db = "ktmc_jay";
    $host = "localhost";

    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>
<HTML>
<HEAD>
  <TITLE>Display Link</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" >

<?
    $category = "Local Docs";

    # setup SQL statement
    $SQL = " SELECT * FROM links ";
    $SQL = $SQL . " WHERE category = '$category' ";

    # execute SQL statement
    $retid = mysql_db_query($db, $SQL, $cid);

    # check for errors
    if (!$retid) { echo( mysql_error()); }
    else {

        # display results
        echo ("<P><DT><B>$category</B><BR>\n");
        while ($row = mysql_fetch_array($retid)) {
            $siteurl = $row["siteurl"];
            $sitename = $row["sitename"];

            echo ("<DD><A HREF='$siteurl'>$sitename</A></DD>\n");
        }
        echo ("</DT></P>");
    }
?>

</BODY>
</HTML>

Link to comment
Share on other sites

Your query should be like so:

 

<?php
# setup SQL statement
    $SQL = " SELECT * FROM links WHERE category = '$category' ";
?>

 

And try changing part to this in the while loop:

 

<?php
# display results
        echo ("<P><DT><B>$category</B><BR>\n");
        while ($row = mysql_fetch_array($retid)) {
            $siteurl = " . $row['siteurl'] . ";
            $sitename = " . $row['sitename'] . ";
?>

 

Also, I believe those ( ) around your echo statements could be why they aren't printing. Personally i've not seen echo statements start or end with anything but quotes. They may be ok and that may be allowed syntax but if the display still isn't working then try removing them and just having them like this:

 

echo "<DD><A HREF='$siteurl'>$sitename</A></DD>\n";

 

 

 

Link to comment
Share on other sites

Heh..ok, at least we're getting something :)

 

Please post your whole new code so I can see line 35. If it's the variables then just change them back to how you had them.

 

while ($row = mysql_fetch_array($retid)) {

            $siteurl = $row["siteurl"];

            $sitename = $row["sitename"];

 

 

Link to comment
Share on other sites

Okay... I have got rif of the error message, but its still not showing me the data i want to see?

 

<?
    $usr = "ktmc_jay";
    $pwd = "123456";
    $db = "ktmc_jay";
    $host = "localhost";

# connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    mysql_select_db($db) or die(mysql_error());
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>
<HTML>
<HEAD>
  <TITLE>Display Link</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" >

<?
    $category = "Local Docs";

# setup SQL statement
    $SQL = " SELECT * FROM links WHERE category = '$category' ";

    # execute SQL statement
    $retid = mysql_db_query($db, $SQL, $cid);

    # check for errors
    if (!$retid) { echo( mysql_error()); }
    else {

        # display results
        echo ("<P><DT><B>$category</B><BR>\n");
        while ($row = mysql_fetch_array($retid)) {
            $siteurl = $row["siteurl"];
            $sitename = $row["sitename"];

            echo ("<DD><A HREF='$siteurl'>$sitename</A></DD>\n");
        }
        echo ("</DT></P>");
    }
?>

</BODY>
</HTML>

 

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.