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> Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/ 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193731 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 Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193739 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"; Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193746 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 Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193749 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"]; Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193752 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! Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193908 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? Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-193944 Share on other sites More sharing options...
JayLewis Posted February 26, 2007 Author Share Posted February 26, 2007 Help Please Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-194389 Share on other sites More sharing options...
JayLewis Posted February 26, 2007 Author Share Posted February 26, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-194795 Share on other sites More sharing options...
JayLewis Posted February 28, 2007 Author Share Posted February 28, 2007 no? Link to comment https://forums.phpfreaks.com/topic/40055-not-retrieving-database-information/#findComment-195657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.