JayLewis Posted February 25, 2007 Share Posted February 25, 2007 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> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 25, 2007 Share Posted February 25, 2007 You need to add the database statement: <? # connect to database $cid = mysql_connect($host,$usr,$pwd); mysql_select_db($db) or die(mysql_error()); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 25, 2007 Author Share Posted February 25, 2007 I done that but its still not showing the data ??? http://www.ktmc.basic-hosting.org/jay/view_data.php Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 25, 2007 Share Posted February 25, 2007 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"; Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 25, 2007 Author Share Posted February 25, 2007 now i am getting... Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ktmc/public_html/jay/view_data.php on line 35 Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 25, 2007 Share Posted February 25, 2007 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"]; Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 25, 2007 Author Share Posted February 25, 2007 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! Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 26, 2007 Author Share Posted February 26, 2007 Any other methods apart from the one im using? Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 26, 2007 Author Share Posted February 26, 2007 Help Please Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 26, 2007 Author Share Posted February 26, 2007 anyone? Quote Link to comment Share on other sites More sharing options...
JayLewis Posted February 28, 2007 Author Share Posted February 28, 2007 no? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.