Skip to content

Commit

Permalink
new version alligning changes done
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed May 9, 2014
1 parent 7d7de1e commit 837340d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 46 deletions.
23 changes: 14 additions & 9 deletions admin.users.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@
</tr>
</thead>
<tbody>
<?php
$userTools = new UserTools();
$users = $userTools->getAll();
foreach ($users as $user) {
?>
<tr>
<?php
$userTools = new UserTools();
$users = $userTools->getAll();

foreach ($users as $user)


{
?>
<tr>
<td><?= $user->id ?></td>
<td><?= $user->name ?></td>
<td><?= $user->linkedin_id ?></td>
<td><a href="" class="companylink" data-companyid="<?= $user->company_id ?>" data-id="<?= $user->id ?>" ><?= $user->getOrganization()->name ?></a></td>
</tr>
</tr>
<?php
}
?>
Expand Down Expand Up @@ -89,15 +93,16 @@
</div>

<div id="dialog-form" title="Change Company">

<form id="create_form" method="post" action="user.create.php">
<fieldset>
<input id="userId" name="userId" type="hidden" />
<select name="companyId" id="companylist" size="10" style="width:100%" >
<?php
$companyTools = new CompanyTools();
$companies = $companyTools->getAllCompanies();
foreach ($companies as $company) {
foreach ($companies as $company)
{
echo '<option value="' . $company->id . '">' . $company->name . '</option>';
}
?>
Expand Down
108 changes: 73 additions & 35 deletions classes/DB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@ class DB {
protected $db_pass = '';
protected $db_host = 'localhost';



function __construct() {
$this->connect();
}

//open a connection to the database. Make sure this is called
//on every page that needs to use the database.
public function connect() {
$connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
mysql_select_db($this->db_name);
$connection = mysqli_connect($this->db_host, $this->db_user, $this->db_pass, $this->db_name) or die("Error " . mysqli_error($connection));;
//mysqli_select_db($connection,$this->db_name);

return true;
}

public function getConnection(){

$connection = mysqli_connect($this->db_host, $this->db_user, $this->db_pass, $this->db_name) or die("Error " . mysqli_error($connection));;
return $connection;
}
//takes a mysql row set and returns an associative array, where the keys
//in the array are the column names in the row set. If singleRow is set to
//true, then it will return a single row instead of an array of rows.
public function processRowSet($rowSet, $singleRow = false) {
$resultArray = array();
while ($row = mysql_fetch_assoc($rowSet)) {
while ($row = mysqli_fetch_assoc($rowSet)) {
array_push($resultArray, $row);
}

Expand All @@ -34,33 +41,42 @@ public function processRowSet($rowSet, $singleRow = false) {

return $resultArray;
}



//Select rows from the database.
//returns a full row or rows from $table using $where as the where clause.
//return value is an associative array with column names as keys.
public function select($table, $where) {
$sql = "SELECT * FROM $table WHERE $where";
$result = mysql_query($sql);
if (!$result) {
return false;
} else {
//if (mysql_num_rows($result) == 1) {
// return $this->processRowSet($result, true);
//}
return $this->processRowSet($result);
}

$sql = "SELECT * FROM $table WHERE $where";
$result = mysqli_query($this->getConnection(),$sql);
if(!$result) {
die(mysqli_error($this->getConnection()));
} else {
return $this->processRowSet($result);
}

}

//This is more complex select query
public function select2($columns, $table, $where, $group_by, $order_by) {
$group_by != "" ? $group_by = ' GROUP BY ' . $group_by : $group_by = "";

$group_by != "" ? $group_by = ' GROUP BY ' . $group_by : $group_by = "";
$order_by != "" ? $order_by = ' ORDER BY ' . $order_by : $order_by = "";
$sql = "SELECT $columns FROM $table WHERE $where $group_by $order_by";
$result = mysql_query($sql);

$result = mysqli_query($this->getConnection(),$sql);
//if (mysql_num_rows($result) == 1)
// return $this->processRowSet($result, true);

return $this->processRowSet($result);
if(!$result) {
die(mysqli_error($this->getConnection()));
} else {
return $this->processRowSet($result);
}

}

/**
Expand All @@ -69,14 +85,16 @@ public function select2($columns, $table, $where, $group_by, $order_by) {
* @param type $sql
*/
public function execute($sql) {
mysql_query($sql) or die(mysql_error());

mysqli_query($this->getConnection(), $sql) or die(mysqli_error($this->getConnection()));
}

/*
* Function to execute a custom sql command and get the results
*/
public function query($sql){
$result = mysql_query($sql);

$result = mysqli_query($this->getConnection(), $sql) or die(mysqli_error($this->getConnection()));
return $this->processRowSet($result);
}

Expand All @@ -86,9 +104,10 @@ public function query($sql){
//and the values are the data that will be inserted into those columns.
//$table is the name of the table and $where is the sql where clause.
public function update($data, $table, $where) {
foreach ($data as $column => $value) {

foreach ($data as $column => $value) {
$sql = "UPDATE $table SET $column = $value WHERE $where";
mysql_query($sql) or die($sql." : ".mysql_error());
mysqli_query($this->getConnection(),$sql) or die($sql." : ".mysqli_error());
}
return true;
}
Expand All @@ -98,7 +117,10 @@ public function update($data, $table, $where) {
//and the values are the data that will be inserted into those columns.
//$table is the name of the table.
public function insert($data, $table) {
$columns = "";



$columns = "";
$values = "";

foreach ($data as $column => $value) {
Expand All @@ -109,10 +131,10 @@ public function insert($data, $table) {
}

$sql = "insert into $table ($columns) values ($values)";
mysql_query($sql) or die($sql." : ".mysql_error());
mysqli_query($this->getConnection(),$sql) or die($sql." : ".mysqli_error());

//return the ID of the user in the database.
return mysql_insert_id();
return mysqli_insert_id();
}

/**
Expand All @@ -122,15 +144,21 @@ public function insert($data, $table) {
* @param string $table
*/
public function delete($ids, $table) {
$commaList = implode(', ', $ids);



$commaList = implode(', ', $ids);
$sql = "delete from $table where id in ($commaList)";
$result = mysql_query($sql);
$result = mysqli_query($this->getConnection(),$sql);
return $result;
}

public function deleteWhere($table, $where) {
$sql = "delete from $table where $where";
$result = mysql_query($sql);



$sql = "delete from $table where $where";
$result = mysqli_query($this->getConnection(),$sql);
return $result;
}

Expand All @@ -145,13 +173,16 @@ public function deleteWhere($table, $where) {
* @return boolean
*/
public function innerJoinOrderBy($table1, $table2, $table1Index, $table2Index, $where, $order_by,$results = 0) {
$sql = "SELECT * FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where ORDER BY ".$order_by;



$sql = "SELECT * FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where ORDER BY ".$order_by;
if ($results == 1) {
$sql = "SELECT $table1.* FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where ORDER BY ".$order_by;
} else if ($results == 2) {
$sql = "SELECT $table2.* FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where ORDER BY ".$order_by;
}
$result = mysql_query($sql);
$result = mysqli_query($this->getConnection(),$sql) ;
if (!$result) {
return false;
} else {
Expand All @@ -162,13 +193,15 @@ public function innerJoinOrderBy($table1, $table2, $table1Index, $table2Index, $
}
}
public function innerJoin($table1, $table2, $table1Index, $table2Index, $where,$results = 0) {
$sql = "SELECT * FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where";


$sql = "SELECT * FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where";
if ($results == 1) {
$sql = "SELECT $table1.* FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where";
} else if ($results == 2) {
$sql = "SELECT $table2.* FROM $table1 INNER JOIN $table2 ON $table1.$table1Index=$table2.$table2Index WHERE $where";
}
$result = mysql_query($sql);
$result = mysqli_query($this->getConnection(),$sql);
if (!$result) {
return false;
} else {
Expand All @@ -189,8 +222,11 @@ public function innerJoin($table1, $table2, $table1Index, $table2Index, $where,$
* @param string $where
*/
public function naturalJoin($columns,$table1,$table2,$where){
$sql = "SELECT $columns FROM $table1 LEFT JOIN $table2 WHERE $where";
$result = mysql_query($sql);



$sql = "SELECT $columns FROM $table1 LEFT JOIN $table2 WHERE $where";
$result = mysqli_query($this->getConnection(),$sql);
if (!$result) {
return false;
} else {
Expand All @@ -202,8 +238,10 @@ public function naturalJoin($columns,$table1,$table2,$where){
}

public function leftJoin($columns,$table1,$table2,$where,$leftCol, $rightCol){
$sql = "SELECT $columns FROM $table1 LEFT JOIN $table2 ON $table1.$leftCol= $table2.$rightCol WHERE $where";
$result = mysql_query($sql);


$sql = "SELECT $columns FROM $table1 LEFT JOIN $table2 ON $table1.$leftCol= $table2.$rightCol WHERE $where";
$result = mysqli_query($this->getConnection(),$sql);
if (!$result) {
return false;
} else {
Expand Down
2 changes: 1 addition & 1 deletion classes/SponsorshipTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getAllOpenSponsorships(){
$wherePedicate = "taken_by IS NULL AND date > '".$currentDate."'";
$results = $this->db->innerJoin("sponsorships", "events", "event_id", "id", $wherePedicate, 1);

foreach($results as $result){
foreach($sponsorships as $result){
array_push($sponsorships, new Sponsorship($result));
}

Expand Down
5 changes: 4 additions & 1 deletion students.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$batch = "level_1";
} else if (isset($_GET['batch']) && $_GET['batch'] == "level_2") {
$students = $studentTools->getStudents($settingsTools->getLevelTwoId());

$batch = "level_2";
} else if (isset($_GET['batch']) && $_GET['batch'] == "level_3") {
$students = $studentTools->getStudents($settingsTools->getLevelThreeId());
Expand Down Expand Up @@ -71,7 +72,9 @@
Passionate in dynamic field of Computer Science & Engineering and to explore new technology, new perceptions and diverse thinking patterns. Yet, but passionate in experiencing diverse fields and people. Proven myself to be successful in team work and leadership.
</p>
<div id="accordion">
<?php echo getHtmlForStudents($students); ?>
<?php echo getHtmlForStudents($students);
echo "*************";
?>
</div>
</div>
</div> <!-- END List Wrap -->
Expand Down

0 comments on commit 837340d

Please sign in to comment.