Jump to content

Sort SQLSRV_Fetch_Object by PHP variable.


laural

Recommended Posts

<?php

/* Define the Transact-SQL query. Use question marks (?) in place of  the parameters to be passed to the stored procedure */
$tsqlNavDiv_callSP = "{call sp_services_content_navigation_module( ?, ?, ?, ?, ?, ?, ?, ?, ?)}";

/* Define the parameter array. By default, the first parameter is an INPUT parameter. The second parameter is specified as an OUTPUT parameter. To ensure data type integrity, output parameters should be initialized before calling the stored procedure, or the desired PHPTYPE should be specified in the $params array.*/

$opt_out_eap = $_SESSION['id_eap'];
$opt_out_company = $_SESSION['id_company'];
$content_languages_list = $_SESSION['id_language'];
$publish = 'public';
$id_eap = $_SESSION['id_eap'];
$today=(date("Y-m-d"));
$total='';
$id_module='';

$paramsNavDiv = array(
	array($opt_out_eap, SQLSRV_PARAM_IN),
	array($opt_out_company, SQLSRV_PARAM_IN),
	array($content_languages_list, SQLSRV_PARAM_IN),
	array($publish, SQLSRV_PARAM_IN),
	array($id_eap, SQLSRV_PARAM_IN),
	array($today, SQLSRV_PARAM_IN),
	array($id_division, SQLSRV_PARAM_INOUT),
	array($total, SQLSRV_PARAM_OUT),
	array($id_module, SQLSRV_PARAM_OUT)
);

/* Execute the query. */
$stmtNavDiv = sqlsrv_query( $conn, $tsqlNavDiv_callSP, $paramsNavDiv);

if( $stmtNavDiv === false )
{echo "Error in executing statement 3.\n";
	die( print_r( sqlsrv_errors(), true));}


	$i='120'; 
	$i <= '141';
	while ($obj=sqlsrv_fetch_object($stmtNavDiv)) {
	// SET PARAMETERS
	$total= $obj->total;
	$id_division= $obj->id_division;
	$id_module= $obj->id_module;
	$i++;

if ($total > 0) { 
			echo "<li><a href=\"".$_SESSION['pwfurl']."/p_module.php?id_division=".$id_division_menu."&id_module=m".$id_module."\">".$_SESSION['m'.$id_module]."</a></li>";

}
	}


/*Free the statement and connection resources. */
sqlsrv_free_stmt( $stmtNavDiv);
?>

I pull a menu back in my website that has an id number (300, 305, 302, 303, 304, 301, 306) -This number is stored in SQL.  Each of the menu numbers is associated with a slot number (121, 122, 123, 124, 125, 126, 127) These are not in SQL.  Right now, my stored procedure is ordering by the id number instead of the slot number.  So my question is, once I pull back my records, can I re-order the array by my PHP slot numbers? 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.