[thelist] mysql help
Mark Mckee
lists at soddengecko.com
Sun Oct 1 15:05:58 CDT 2006
hi Spike
Thanks for the reply.
i have one table with 3 fields, "category" "url" and "title" in a mysql
database. im using php.
each link that is added tot he database is assigned a category. i do not
know what the categories will be as this is going to be used as a
bookmark manager between myself and my colleagues.
so far i have added 5 categories to test with and roughly 6 links per
category. i want all the links assigned to the "misc" category to be
displayed under the heading "Miscellaneous" and so on with each category.
I can do this if i know in advance what the categories will be, but as
the users have the option of creating a category if one for the link
does not exist, i won't know what category will be added.
a while ago i made something that would display a link according to the
day it was added to the database, so i modified the code slightly.
unfortunately it is not returning the results correctly if i try to
format them into a list and seperate each category into a div. listed
them all down the page with no formatting seems to work fine.
the code i am using at present is:
<?php
$sql = "SELECT * FROM info ORDER BY catagory";
$result = mysql_query($sql) or die('There are currently no links in the
database.');
while ($row = mysql_fetch_assoc($result))
{
$catagory = $row['catagory'];
$url = $row['url'];
$title = $row['title'];
if ($catagory != $temp)
echo "</ul>\n</div>\n\n<div class='left'>\n<h1>$catagory</h1>\n<ul>\n";
$temp = $catagory;
echo "<li><a href='$url' target='_blank'>$title</a></li>\n";
}
echo "</ul>\n";
echo "</div>\n\n";
?>
this however returns bad html and does not list the links in
alphabetical order.
any light you can shed on this for me would be brilliant.
kind regards
mark m...
Webadmin - Tenbus wrote:
> Hi Mark!
>
> I've not seen any reply to your posting.
>
> Do you really have four tables, or is it one table with four fields/columns?
>
> How are you displaying the data? PHP? OBDC? etc
>
> Can you give some more details please?
>
> Regards
> - Spike -
>
>
> Mark Mckee wrote:
>
>> hi all,
>>
>> hope you can help with this issue.
>>
>> i have a small databse with 4 tables. "catagory" "url" "title" "target"
>>
>> im having a little trouble displaying the data how i want it. i have 15
>> catagories, so the db looks a little like this when data is entered
>>
>> catagory url title target
>> misc some link some title the target
>> cat2 some link some title the target
>> cat3 some link some title the target
>>
>> each catagory is obviously seperate on the page when viewing, like so
>>
>> mics
>> some link
>>
>> cat2
>> some link
>>
>> cat3
>> some link
>>
>> how do i get the data from the database to display the link under the
>> correct catagory?
>>
>> any and all help is appreciated
>>
>> kind regards
>>
>> mark m...
>>
>>
>
>
>
More information about the thelist
mailing list