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
https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/
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";

 

 

 

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"];

 

 

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.