Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Organizing lists from 2 dbs
Old 05-03-2005, 02:26 PM Organizing lists from 2 dbs
Junior Talker

Posts: 1
Trades: 0
Hi, I am a relative newcomer to PHP. I am trying to make a list from 2 dbs.

I would like the list to look like this:

Category 1
Item 1
Item 2
Category 2
Item 3
Item 4

So far I've been able to get these 2 results (code follows each example):
First Try:
Category 1
Item 1
Item 2

Category 2
Item 1
Item 2

Category 1
Item 3
Item 4

Category 2
Item 3
Item 4
Code for this:
$query = "SELECT * FROM test1";

$result = mysql_query($query)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row = mysql_fetch_array($result))

{

$category_name = "";
extract($row);

echo"<p><b>$category_name</b><br>";


$query2 = "SELECT * FROM test1, test2 WHERE test1.ID = test2.ID_parent";

$result2 = mysql_query($query2)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row2 = mysql_fetch_array($result2))
{

$item_name = "";
extract($row2);

echo "<p><b>$item_name</b></p>";
}

}
}

mysql_close($connection);
-----------------------------
Second Try:
category1
item1
category1
item2
category2
item3
category2
item4

here's the code
---------------------
$query = "SELECT * FROM test1, test2 WHERE test1.ID = test2.ID_parent ORDER BY test1.category_name, test2.Item_name";

$result = mysql_query($query)
or die ("Sorry, there is a problem with the web site at this time.");
while ($row = mysql_fetch_array($result))

{

$category_name = "";
$item_name = "";
extract($row);

echo"<p><b>$category_name</b><br><p><b>$Item_name</b></p>";

}

mysql_close($connection);
?>
------------------
Thanks
nantucketer is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-03-2005, 07:24 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
hi nantucketer,

i think this has been discussed in a previous thread, and i'm sure it will help you.
http://www.webmaster-talk.com/showthread.php?t=28577

I'm not sure though because all that code and text has messed with my mind If you could maybe explain what you're trying to do, we might be able to help you more - i think I have a vague idea what you're doing though. Also, do you reckon we could see the database structure?
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by leavethisplace; 05-03-2005 at 07:39 PM..
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Organizing lists from 2 dbs
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.23395 seconds with 12 queries