ger_mac74 Posted March 9, 2006 Share Posted March 9, 2006 Hi there I am working on a php script for a webpage that will grab two columns from a database (articlename and articleurl) and then number and display just the article name column. This article name column will hopefully appear as a link and when clicked on, the page will then divert to the articles url. Also I am new enough to php and programming so be easy on me!Here is the code that I have so far:<?php $db = mysql_connect("----", "----", "----"); mysql_select_db("-------", $db); $query = "SELECT articlename articleurl FROM articles"; $result = mysql_query($query) or die("Couldn't execute query");?><?php echo "Current List Of Articles: <br>"; $count = 1; while ($row= mysql_fetch_array($result)){ $artname = $row["articlename"]; $arturl = $row["articleurl"]; echo "$count.) <a href='$arturl'>$artname</a><br>"; $count++; } ?>Can anyone see what I am doing wrong? At the moment the code seems to be counting the number of entries in the database but no articlename links seem to be appearing!!Thanks in advance!!! Quote Link to comment Share on other sites More sharing options...
k4pil Posted March 9, 2006 Share Posted March 9, 2006 have you tried to execute your query in your database.If it is working fine in there then you where to look next. Quote Link to comment Share on other sites More sharing options...
ger_mac74 Posted March 10, 2006 Author Share Posted March 10, 2006 That's great. Working fine now. I had just left out a comma after articlename in my select query. When it is printing out now the article name is beside the number listed. This is what I want but when it gets to number 10.) it is one space further out the page compared to 9.) Is there a piece of code that I could fit in here to fix this and make 1 to 9 appear one space further out? Not too worried about what happens when it gets to 100. Looks like this at the moment:8.) Text......9.) Text......10.)Text......11.)Text......12.)Text......Not as obvious here but after 9 text appears out one space further because of extra digit.Hope you can help me out.Regards... Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 10, 2006 Share Posted March 10, 2006 [code]while ($row= mysql_fetch_array($result)){$artname = $row["articlename"];$arturl = $row["articleurl"];if ($count<10) { echo " "; }echo "$count.) <a href='$arturl'>$artname</a><br>";$count++;}[/code] Quote Link to comment Share on other sites More sharing options...
ger_mac74 Posted March 10, 2006 Author Share Posted March 10, 2006 Thanks for that. I looked at the manual and cant find what to do. I have tried putting in a letter instead of " " and the letter prints out fine which means the loop and count are working ok. It just doesnt seem to want to print an empty space. I also tried echoing "\s" and " " but neither work. Is there another system I should use to actually print a space or do I use a differnt function.Thanks again. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 10, 2006 Share Posted March 10, 2006 Since your making an ordered list, you should use the <ol> and <li> HTML tags:[code]<?phpecho '<ol>';while ($row= mysql_fetch_array($result)){$artname = $row["articlename"];$arturl = $row["articleurl"];echo "<li><a href='$arturl'>$artname</a></li>";}echo '</ol>';?>[/code]This way you don't have to worry about it.Ken Quote Link to comment Share on other sites More sharing options...
ger_mac74 Posted March 10, 2006 Author Share Posted March 10, 2006 Thanks for that. Perfect now. 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.