PHP & MySQL question

Hello,

I have a functions.php file, which has a function called connectDatabase(). I also run this function among with session_start(); on top of each php file that requires both.

But, in some other files I also have
include(‘functions.php’). So my question is, does including a php file trigger functions that are initially ran by included file?

My next question is mysql related, I get results by:

function getSearchHistory($email)
{
if($email){
	$sqlRequest = "SELECT * FROM gvntools_history WHERE email='$email' ORDER BY timestamp";
	$result = mysql_query($sqlRequest);
	if($result){
	$rows = mysql_num_rows($result);
	if($rows > 0){
		for($i=0; $i<$rows; $i++){
			$timestamp = mysql_result($result, $i, 'timestamp');
			$searchID = mysql_result($result, $i, 'searchid');

			echo "Search $searchID | $timestamp | <a href=\\"search/$searchID.txt\\" target=\\"_blank\\">Open</a><br>";	
		}
	}}}	
}

But I get them printed out from oldest to newest, while I would like to from newest to oldest. One way would be to change for statement to:
for($i=$rows; $i>0; $i–) but I am wondering if there is any other way with ORDER command in mysql query.

Side note/addendum - As guido said, the code is -executed- as soon as you include the file - it is equivilant to copy/pasting the code into the file. Your original post indicated that the file in question includes a call to some of those functions… in which case those calls WILL be executed when the file is included.

sure, that is very good, so now I know so I wont call same functions twice and save a bit on performance.

thank you :slight_smile:

Not too sure about your php question, but if functions.php just includes function definitions, then including the file won’t run the functions.

MySQl question, use: ORDER BY timestamp DESC
…which will give results in DESCending order of timestamp. The default is ASC(ending).

The moment a php file gets included, the code inside gets executed. Except for functions, which are executed only when called.

But I get them printed out from oldest to newest, while I would like to from newest to oldest.

ORDER BY fieldname DESC

sorry, my bad, forgot that 0 is mysql result too so:

for($i=$rows-1; $i >= 0; $i--)