Jump to content

Article name, with article url as its underlying link not appearing


ger_mac74

Recommended Posts

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!!!
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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 "&nbsp;" but neither work. Is there another system I should use to actually print a space or do I use a differnt function.
Thanks again.
Link to comment
Share on other sites

Since your making an ordered list, you should use the <ol> and <li> HTML tags:
[code]<?php
echo '<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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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