FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP/MySQL challenge, take it if you dare





Mgccl
The 1st challenge:
Given:
1.There are a MySQL table, structured like this
Code:
time*|int

Here time is a datetime data type, and primary key
int is an int(11) data type
2. There are a value, which could change anytime. when ever the value changes, it will be recorded in the database. The time it change will be write to the time field, the new value will write into int field

Code:
Write a function that could recive a value(which is time), and use the database get the value of that time.
hint: Database might not contain a result for that time, because database only have the times that change have occured.

Condition to win:
The person who made the function that could do the job Fastest will win.

Prize:
None....except respect from many people include me

The 2nd Challenge:
Given:
1.There are a MySQL table, structured like this
Code:
foo_id*|bar_id*

-both of the field make up a primary key
-both of their data type is int(11)
-foo_id and bar_id consist of an many 2 many relationship

Code:
Write a function that:
-get top 5 different foo_id(order by foo_id)
hint: a foo_id can be in many rows, so you have to figue out how to get 5 different foo_id out(clearly get the whole database out and than loop though is not an good idea).

Condition to win:
The person who made the function that could do the job FASTEST will win.

Prize:
None....except respect from many people include me
hexkid
Mgccl wrote:
The 1st challenge:

The 2nd Challenge:


Give us the address of your teacher and your name so that we can submit the answers directly to her in your name. That way you learn even less.
hyhy
Mgccl wrote:
Prize:
None....except respect from many people include me


Lol and what is a respect from some random unkown person which doesn't know basics of php. And how can you respect someone if you never seen him and everything you know about him is that he posted code on forums. You cannot be even sure if he has written it himself.
Marston
hexkid wrote:
Mgccl wrote:
The 1st challenge:

The 2nd Challenge:


Give us the address of your teacher and your name so that we can submit the answers directly to her in your name. That way you learn even less.
Question

PS: You're on my computer!?!
hexkid
Marston wrote:
You're on my computer!?!

Is it better than mine? Maybe I'll hop over there for a while Smile
Mgccl
hyhy wrote:
Mgccl wrote:
Prize:
None....except respect from many people include me


Lol and what is a respect from some random unkown person which doesn't know basics of php. And how can you respect someone if you never seen him and everything you know about him is that he posted code on forums. You cannot be even sure if he has written it himself.


random... you sure haven't see me around lately...

so... to prove myself... here is the answer for 1st problem... I think NO one in the world will ever get anything faster than that.
use it like
func_get_var($time)
important the time must be in MySQL datetime format
Code:
<?php
   
function func_get_var($t){
      
$q = 'SELECT int '.
   'FROM data ".
   "WHERE time <= ('".$t."') ".
   'ORDER BY time DESC '.
   'LIMIT 0, 1 ';
 $r = mysql_fetch_array(mysql_query($q));
    return $r['int'];
}

?>


and.... puff... there are no teacher for PHP you know... I don't know any school that ever teach PHP... you gota learn it yourself... like me... who used it over 6 months..
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.