SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
May 10, 2001, 05:47 #1
- Join Date
- Mar 2001
- Location
- the Netherlands
- Posts
- 519
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
At this moment I have the following code:
PHP Code:$page = mysql_fetch_array (mysql_query("SELECT * FROM pages WHERE subcat=$subcatid"));
$rubr = split (",", $page["rubrieken"]);
print "<TABLE width='600' border=0>";
print "<TR>";
if (count($rubr) > 1) {
for($i=0;$i<count($rubr);$i++) {
$tit=mysql_result(mysql("$dbname","SELECT titel FROM rubrieken WHERE id=$rubr[$i]"),0,0);
print "<TD valign='top'><B>$tit</B></TD>";
}
print "<TR>";
for($i=0;$i<count($rubr);$i++) {
print "<TD valign='top'>\r";
$result = mysql_query ("SELECT id,link FROM links WHERE rubrieken=$rubr[$i] ORDER BY id");
while ($row = mysql_fetch_array ($result)) {
print " ". $row ["link"] . "<BR>\r";
}
print "</TD>";
}
print "</TR></TABLE>\r\r";
}
?>
Rubriek 1 and Rubriek 2.
The first rubriek (section) has the Links: link 1, link 3, link 5
the second rubriek has the Links: link 2, link 4, link 6
This would produce the following output:
(without the dashes)
Rubriek 1---------Rubriek 2
--Link 1------------Link 2
--Link 3------------Link 4
--Link 5------------Link 6
But what I want is:
Rubriek 1
--Link 1
--Link 3
--Link 5
Rubriek 2
--Link 2
--Link 4
--Link 6
Could someone help me rewrite the code, so I get the output in the way that I want?
-
May 10, 2001, 06:56 #2
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is my go at it.
PHP Code:$page*=*mysql_fetch_array*(mysql_query("SELECT***FROM*pages*WHERE*subcat=$subcatid"));
$rubr*=*split*(",",*$page["rubrieken"]);
for($i=0;$i<count($rubr);$i++)*{
$tit=mysql_result(mysql("$dbname","SELECT*titel*FROM*rubrieken*WHERE*id=$rubr[$i]"),0,0);*
print*"<BR><B>$tit</B><BR>\r";
$result*=*mysql_query*("SELECT*link*FROM*links*WHERE*rubrieken=$rubr[$i]*ORDER*BY*id");*
while*($row*=*mysql_fetch_array*($result))*{
print*$row*["link"]*.*'<BR>\r';
}
}
Note that the if statement if*(count($rubr)*>*1) is redundant (and 1 should have been 0). The for condition for($i=0;$i<count($rubr);$i++) is sufficient.
Hope that is of help
-
May 10, 2001, 07:18 #3
- Join Date
- Mar 2001
- Location
- the Netherlands
- Posts
- 519
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanx a lot, Freakysid...
it's actually what I meant... and it works.
However......
Sometimes, there are no 'rubrieken'. In other words;
pages.rubrieken can be empty.
When I use your code:
PHP Code:$page = mysql_fetch_array (mysql_query("SELECT * FROM pages WHERE subcat=$subcatid"));
$rubr = split (",", $page["rubrieken"]);
print "<TABLE width='600' border=0>";
print "<TR>";
for($i=0;$i<count($rubr);$i++) {
$tit=mysql_result(mysql("iclon","SELECT titel FROM rubrieken WHERE id=$rubr[$i]"),0,0);
print "<BR><B>$tit</B><BR>\r";
$result4 = mysql_query ("SELECT link FROM links WHERE rubriek=$rubr[$i] ORDER BY id");
while ($row = mysql_fetch_array ($result4)) {
print $row ["link"] . '<BR>';
}
}
Warning: Supplied argument is not a valid MySQL result resource in C:\...\showrubr.php on line 91
Warning: Supplied argument is not a valid MySQL result resource in C:\...\showrubr.php on line 95
line 91:
PHP Code:$tit=mysql_result(mysql("iclon","SELECT titel FROM rubrieken WHERE id=$rubr[$i]"),0,0);
PHP Code:while ($row = mysql_fetch_array ($result4)) {
Any tips?
-
May 10, 2001, 07:39 #4
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well that's why I enjoy hanging around this forum. I get to gain from your pain
I just went and read the manual on function split() as I have never used it. http://www.php.net/manual/en/function.split.php Here is the first user contributed comment on that page:
kietscia@yahoo.com
22-Mar-2000 03:49
Here's a little unexpected gem.
<?php
$x = split(":","");
print "There are " . count($x) . " items";
?>
Suprisingly enough (or maybe not), this prints:
There are 1 items
I would expect this to be 0 since the string is empty.
So a fix could be (you would have to test this):
PHP Code:if $page["rubrieken"] { // test that the rubrieken field is not null
$rubr*=*split*(",",*$page["rubrieken"]);
}
-
May 10, 2001, 07:48 #5
- Join Date
- Mar 2001
- Location
- the Netherlands
- Posts
- 519
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It does work... !!!!
I added '(' and ')' otherwise the if-statement doesn't work.
PHP Code:if ($page["rubrieken"]){
$rubr = split (",", $page["rubrieken"]);
}
gr. Jasper
Bookmarks