unitedintruth Posted March 26, 2009 Share Posted March 26, 2009 Okay, so I'm more of a newbie today than most days, just when you think you are figuring it out. I am trying to make a links directory, I got my form working to insert the data into the database, now I am trying to get the results to layout in a table. My only fields are Name, Description, and URL and I can't seem to get it to layout. Can someone please help me a little bit? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/ Share on other sites More sharing options...
MadTechie Posted March 26, 2009 Share Posted March 26, 2009 Have you tried echo ? it works well for me Can you post some code Part about fetching and echoing it Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794657 Share on other sites More sharing options...
unitedintruth Posted March 26, 2009 Author Share Posted March 26, 2009 The part about fetching and echoing it is what I don't have. I have connected to the db. And once I select * from links WHERE approved = Approved I am stuck. Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794659 Share on other sites More sharing options...
KPH71 Posted March 26, 2009 Share Posted March 26, 2009 Change the connection to how you like it as well as the query and the table styles <?php mysql_connect($host, $user, $pass); mysql_select_db($database); $query = mysql_query("SELECT * from tablename", $con) or die(mysql_error()); echo '<table border="0">'; echo '<tr><th>Link</th><th>Description</th></tr>'; while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td><a href="'.$row['URL'].'">'.$row['Name'].'</a></td>'; echo '<td>'.$row['Description'].'</td>'; echo '</tr>'; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794661 Share on other sites More sharing options...
unitedintruth Posted March 26, 2009 Author Share Posted March 26, 2009 The only things I changed was the host, user, password database and the tablename in the select statement and I am getting the following error Warning: mysql_query(): 7 is not a valid MySQL-Link resource in /home/garrett/public_html/links.php on line 155 line 155 is $query = mysql_query("SELECT * from links", $con) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794688 Share on other sites More sharing options...
KPH71 Posted March 26, 2009 Share Posted March 26, 2009 The variable $con should be your connection to mysql. Check that it is or replace it with your real connection. If you only have one connection you can just remove it. (My fault I should have mentioned to change that - its just become habit for me to put it in) Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794690 Share on other sites More sharing options...
unitedintruth Posted March 26, 2009 Author Share Posted March 26, 2009 Thank you very much, works like a charm now. Quote Link to comment https://forums.phpfreaks.com/topic/151277-solved-layout-sql-results/#findComment-794701 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.