It's not what you think.
Okay, heres the situation. I have about 1,000 rows of articles in a MySQL database. Bad part, they were not inserted in the order that they appear. So for example:
1 | How To Program PHP | 4/20/2000
2 | Discovering Java | 8/15/1998
3 | Take Up Yoga | 4/19/2000
The first column is the ID, the second the title of the article, the third the date. In Cold Fusion I managed to do a SQL statement that got the ID's of the articles and put them in chronlogical order for me. Making the articles list like so:
2 | Discovering Java | 8/15/1998
3 | Take Up Yoga | 4/19/2000
1 | How To Program PHP | 4/20/2000
I turned the results of the ID into a comma delimited list:
EDITORIAL_LIST = 2,3,1
Now here's the tricky part. If the user was on article ID 3, both NEXT and PREV buttons will appear. If the user is on article ID 2, only the NEXT button would appear. If the user is on article 1, on the PREV button would appear.
First I did the query which I named PAGING_DAILYHIPHOPNEWS. Then I used the VALUELIST function to get all of the EDITORIALID's in the result and put comma's inbetween it.
For this example let's say we're on a page that the EDITORIALID is set to 2. So basically the LISTFIND function, says FIND 2 in this list. Then it sets the numbers for NEXT and PREV by a negative or a postive - depending on the situation. Keep in mind, that it's not ADDING or SUBTRACTING this number. Its getting the next number in the comma-delimited row.
Here's the code in Cold Fusion:
<CFQUERY NAME="PAGING_DAILYHIPHOPNEWS" DATASOURCE="#DATASOURCE#"
SELECT TBL_EDITORIAL.EDITORIALID,
TBL_EDITORIAL.SUBSECTIONID,
TBL_EDITORIAL.LIVE,
TBL_EDITORIAL.GOLIVE,
TBL_EDITORIAL.GODOWN,
TBL_SUBSECTIONS.SUBSECTIONID,
TBL_SUBSECTIONS.SECTIONID,
TBL_SECTION.SECTIONID
FROM TBL_EDITORIAL,
TBL_SUBSECTIONS,
TBL_SECTION
WHERE TBL_EDITORIAL.SUBSECTIONID = TBL_SUBSECTIONS.SUBSECTIONID
AND TBL_SUBSECTIONS.SECTIONID = TBL_SECTION.SECTIONID
AND TBL_EDITORIAL.SUBSECTIONID = 1
AND TBL_EDITORIAL.LIVE = 1
AND TBL_EDITORIAL.GOLIVE < #TODAYIS#
AND TBL_EDITORIAL.GODOWN > #TODAYIS#
ORDER BY TBL_EDITORIAL.GOLIVE DESC,
TBL_EDITORIAL.EDITORIALID DESC
</CFQUERY>
I'd like to accomplish the same thing in PHP. I'm sure it can be done but I'm just not figuring out the right PHP functions.
This is what I have so far:
<?php
require("../application.php");
$db = "sohh";
include("../application_db_connect.php");
$query = "SELECT * FROM tbl_writers WHERE writerID = $writerID";
$result = mysql_query($query);
if (!$result) {
echo "<B>Error performing query/B> " . mysql_error();
exit;
}
$querylist = "SELECT writerID FROM tbl_writers";
$resultlist = mysql_query($querylist);
$recordcount = mysql_num_rows($resultlist);
$count = 0;
while($row = mysql_fetch_array($resultlist)) {
$writerID = $row["writerID"];
if ($count<$recordcount) {
$writerIDstr .= $writerID . ",";
} else {
$writerIDstr .= $writerID;
}
$count++;
}
$editoriallist = $writerIDstr;
?>
I'm not getting any errors with this but I'm not getting the results I want either.
Steven
<Edited by ibeblunt on 01-12-2001 at 09:35 AM>



/B> " . mysql_error();


Bookmarks