Show user his products - php

This is my first year with HTML, PHP, JAVASCRIPT and mysql!
And i am having a problem, im making a website that users can only see them products.
For example: Admin created a product for MARTA, when MARTA log in she can see her product.
I have created the table USER_EQUIPMENT but i don't know how can i use it like i want.
I made something like this:
function getEquipment($name)
{
$query = "select * from equipments where name = '$name'";
$this->connect();
$res = $this->execute($query);
$this->disconnect();
return $res;
}
and then i called it like:
$name = $_SESSION['name'];
include_once('DataAccess.php');
$da = new DataAccess();
$res = $da->getEquipment($name);
But i doesn't get the equipment by the name.
Little help please?
Thanks.

Related

How to add Distinct function to a array or return only unique values

How to add distinct function so that the result is not repetitive?
Any help is much appreciated.
$yearnow=$_POST['yearnow'];
$stmts = $db->query("select * from tblgencol where year='$yearnow'");
while($row= $stmts->fetch(PDO::FETCH_OBJ)){
$pdf->Row(Array($row->busname,$row->business));
}
}
Here is the output of my code:
I'm using fpdf to display my data from database. And its working fine. Its just that the name is repeating.
This is what I want to achieve:
or what if i want to display this?
option 2
To achieve your desired result, you need to check if the current business name is the same as the last displayed one, and if so, not output it:
$yearnow=$_POST['yearnow'];
$stmts = $db->query("select * from tblgencol where year='$yearnow'");
$busname = '';
while ($row = $stmts->fetch(PDO::FETCH_OBJ)) {
$thisbusname = ($row->busname != $busname) ? $row->busname : '';
$pdf->Row(array($thisbusname,$row->business));
$busname = $row->busname;
}

How to create multidimensional array based on ID from each row (in same View) Codeigniter

I am new in codeigniter both php, I am beginner. Could anyone help me how to show a data from another table based on ID in each row in same View in codeigniter, i just include a file(that is a form with data from another table) im not sure.. how the method should be.. dont know what to do plz ! thx
CONTROLLER
$this->load->model('m_work_order');
$this->load->model('m_srv_product');
$data['items'] = $this->m_work_order->show_items()->result();
$id=0; // dont know what to do with this ID
$data1['record'] = $this->m_srv_product->show_data($id)->result_array();
$data['form'] = $this->load->view('work_order/form_file', $data1, TRUE);
$this->load->view('work_order/form_input',$data);
MODEL m_work_order
function show_items(){
$query = "SELECT *
FROM work_order_items
WHERE item_status='0'";
return $this->db->query($query);
}
MODEL m_srv_product
function show_data($id)
{
$query= "SELECT a.srv_pr_id,a.srv_vol,a.srv_n,
b.srv_name,c.prod_cat_name,c.prod_cat_id
FROM srv_pr_use as a,service as b, prod_category as c
WHERE a.srv_id = b.srv_id and
a.prod_cat_id = c.prod_cat_id and
a.srv_id = $id ";
return $this->db->query($query);
}
VIEW
foreach ($items as $t){
echo "
<tr>
<td>$no</td>
<td>$kode</td>
<td>$t->item_name</td>
<td>$t->item_qty</td>
<td>".$form."</td>
</tr>"
}

SocialEngine 4 Calculate days left in membership

What I am trying to do is show a small widget on the home page to let a user know when their membership expires. Here is my current code
$subExpire = Engine_Api::_()->getDbtable('subscriptions', 'payment');
$db2 = $streamTable->getAdapter();
$stmt2 = $db2->query("select * from engine4_payment_subscriptions where `user_id`='$user_id'");
$arr2 = $stmt2->fetch();
if ($arr2['expiration_date']=="NULL")
{
$exp = "NEVER";
}
echo $exp;
I think the major issue has to do with Engine_Api::_()->getDbtable('subscriptions', 'payment');
Ultimately once it comes back with a date I would like to calculate how many days left in the membership from the current date.
Any suggestions?
PS, $user_id is defined and does return a numeric value
One more thing, the actual table name is engine4_payment_subscriptions
That´s a strange way of making the query in social engine, try this:
$table = Engine_Api::_()->getDbtable('subscriptions', 'payment');
$select = $table->select()->where('user_id = ?', $user_id);
$arr2 = $table->fetchAll($select);
if ($arr2['expiration_date']=="NULL")
{
$exp = "NEVER";
}
echo $exp;

(Redbean) Unable to access linked table values

I am testing out the Redbean ORM. I like how it works, less work for me :) I am using the redbean books example, from their website. I have been able to create new books with authors and titles, and display them to the page with no problem. I added another dimension to learn how to link pages to my books.
I am able to add an entry into the book table, as well as add an entry into the page table using the following code:
----------- dbmgmt.php ---------------------------------
function AddNewBook($FORMINFO){
$newBook = R::dispense('book');
$newBook->title = $FORMINFO['title'];
$newBook->author = $FORMINFO['author'];
$newBook->create_date = R::isoDateTime();
$newPage = R::dispense('page');
$newPage->pagetext = $FORMINFO['pagetext'];
$newBook->ownPage = $newPage;
$id = R::store($newBook);
return R::load('book', $id);
}
Both tables show the proper entries (new ids and populated fields). However, I am having a hard time accessing the pagetext field from the page table. This is the code I have been using for that:
----------- dbmgmt.php ---------------------------------
function GetBooks($id){
if($id == ""){
return R::find('book');
}
else{
return R::find('book','id = ?', array($id));
}
}
----------- GetBooks.php ---------------------------------
$id = "";
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$books = GetBooks($id);
$booklist = "";
foreach($books as $book){
$pagetext = "";
foreach($book->ownPage as $page){
$pagetext .= $page->pagetext; //Errors with "Notice: Trying to get property of non-object"
}
$booklist .= "<tr id='$book->id'><td><a class='linkEdit' href='edit.php?id=$book->id'><img src='http://cdn1.iconfinder.com/data/icons/ledicons/page_white_edit.png' /></a> <span class='book-title'>$book->title</span></td><td><span class='book-author'>$book->author</span></td><td><span class='page-text'>$pagetext</span></td></tr>";
}
echo $booklist;
------------------------------------------------------------
When I print_r($book->ownPage), I don't even see the page entry that I can clearly see in the page table via phpmyadmin. I have tried many different ways of accessing the pagetext field via my script above, but can't get anywhere with it.
Any insight would be most welcome. Otherwise I will have to try a different, albeit bigger and more cumbersome, ORM.
Thanks in advance.
I am not 100% sure as I haven't encountered this problem yet myself, but I am almost positive, $book->ownPage needs to be an array:
$newPage = R::dispense('page');
$newPage->pagetext = $FORMINFO['pagetext'];
$newBook->ownPage[] = $newPage;
$id = R::store($newBook);

MySQL PHP - How to remove unnecessary php echo text when mysql field is null?

I've got a client who wants me to format a list of businesses on a website page using data from a mysql database and putting it on the web page using php.
The client wants each piece of data to be identified, like this:
Contact Person: Sue Smith
Website: greatwebsite.com
Here's the problem:
Some of the businesses don't have a website. So I do NOT want the business listing to show up like this:
Contact Person: Sue Smith
Website:
I do NOT want the Website line to show up at all if there is no website.
Here's what I've done so far - which does NOT solve the problem (truncated for brevity):
$result = mysql_query("SELECT * FROM businesses ORDER BY business");
while($field = mysql_fetch_array($result))
{
echo
"<h3>".$field['business']."</h3>
<p>Website: ".$field['website']."</p>";
}
I need to learn how to delete the "Website" line entirely if there is no website.
A simple if will work fine:
$result = mysql_query("SELECT * FROM businesses ORDER BY business");
while($field = mysql_fetch_array($result))
{
if (! empty($field['business']) )
echo "<h3>".$field['business']."</h3>";
if (! empty($field['website']) )
echo "<p>Website: ".$field['website']."</p>";
}
while($field = mysql_fetch_array($result))
{
echo "<h3>".$field['business']."</h3>";
if ($field['website'] != '') {
echo "<p>Website: ".$field['website']."</p>";
}
}
$result = mysql_query("SELECT * FROM businesses ORDER BY business");
while($field = mysql_fetch_array($result))
{
echo "<h3>".$field['business']."</h3>";
if(!empty($field['website']))
<p>Website: ".$field['website']."</p>";
}

Categories