|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I really appreciated the article "Building A Dynamic MySQL Paging Class With PHP" from Joe O'Donnell. After modifiying it for my own use I still have one question.
Where in the code can I modify the data I retrieve from the database?? For instance I only want to show the year information from a date field. I know what PHP function to use but not where to put it in the code. Regards TheMike |
|
#2
|
|||
|
|||
|
Hi,
For that you'd use the date() function. So for example, if $theDate was the date, you'd output its year in the format of 2002 like this: echo date("Y", $theDate); |
|
#3
|
|||
|
|||
|
or you could just format the date how you want it in the mysql query using the date_format() function:
eg: SELECT date_format(datefield,'%Y') FROM yourtable |
|
#4
|
|||
|
|||
|
I have just found this article that is ideal for what I need to acheive for a site I am developing. Unfortunately the support material URL on page 2 is no longer there.
I have tried the link http://www.devarticles.com/files/class.recnav.php.txt but no page is available. Does anyone have the original file ?? |
|
#5
|
|||
|
|||
|
Firstly, welcome to the forums, nice having you hear
craigyk: Unfortunally we lost some files during a server crash on our old host. The file that you are asking about has its suport file missing because of that crash, and we are unable to retrive it again Sorry for the Inconvience |
|
#6
|
|||
|
|||
|
Thats OK, I have gone thorugh the article and managed to piece it together from another forum post and it works great
|
|
#7
|
|||
|
|||
|
I have just stumbled into a slight problem. The records that I want to produce are going to be based on a random selection (ORDER BY RAND()) The problem with this is that when i navigate between pages, the results keep randomising, Does anyone have any suggestions on how to keep the original records produced in tact?
|
|
#8
|
|||
|
|||
|
Ben:
I will check my computer at home tonight I think I still have this file, if you want me to mail it so you can fix the url I will. |
|
#9
|
|||
|
|||
|
At the portion of the code below:
for($i = 0; $i < mysql_num_fields($result); $i++) { $newRow = str_replace("<| row" . $i . " |>", $row[$i], $newRow); } You need to make your change here. Something like this should work: for($i = 0; $i < mysql_num_fields($result); $i++) { if ($i == $dateField) { $row[$i] = date(); } $newRow = str_replace("<| row" . $i . " |>", $row[$i], $newRow); } $dateField would of course be the array index that would hold your date value (column number in you SQL table). Hope that helps |
|
#10
|
|||
|
|||
|
Quote:
Hey if you could find it and send it to either me or mytch, that would be great, just email to URL craigyk: Randomizing your code could be a bit hard, what you would have to do is, create a query that randomizes ALL the rows in the table, then print out that the primary keys into something like this 1,6,3,4,8,9,2,5,7 something like that, then you would have to send that to each page, explode it, and do something like this then on each page, go thought the ids, and somehow limit which ones are printed out. If you could also explain why you want to randomize the query, that would be helpful, as there may be a easier way |
|
#11
|
|||
|
|||
|
The reason for the randomising is because it is going to be used for a directory listing.
I am tryig to be unbiased towards the entries in there, I don't want to order them alphabetically because people would just use names begining with a or numbers. I don't want to order them by ID either because it is not fair towards the top/end of the list. The point for randomising is to create a fair output. ope this has made sense. Craig |
|
#12
|
|||
|
|||
|
I can forshadow the future and managed to save the file.
PHP Code:
Please shower me with praise and I may help devArticles.com when it is in need again in the future. ![]() |
|
#13
|
|||
|
|||
|
Oh thank you, O wise one!
ehehh thx Ben Rowe |
|
#14
|
|||
|
|||
|
Move class.navrec.php to server?
Hi Using the code Isaaic posted and the html code fr |