I've got a var that is either empty or not and I want to display nothing when its empty. Code Snippet:
<?php
global $bp;
$user_id = $bp->displayed_user->id;
$user_info2 = get_userdata($user_id);
?>
<div class="meta">
<?php _e('Status','fisa'); ?>: <?php echo fidsa_fpsa_status($user_id); ?>
</div>
If The var is empty it still shows Status: is there someway to change this to not output Status: when the var is empty?
Assign fidsa_fpsa_status($user_id) to a variable, check if the variable is empty - if its not, print the content!
<?php
global $bp;
$user_id = $bp->displayed_user->id;
$user_info2 = get_userdata($user_id);
$fidsa_fpsa_status = fidsa_fpsa_status($user_id);
if (!empty($fidsa_fpsa_status)) {
?>
<div class="meta">
<?php _e('Status','fisa'); ?>: <?php echo $fidsa_fpsa_status; ?>
</div>
<?php
}
I want to have a next button on my Productdetails.php page that would show the next image fetched from the database using while loop. Below is the productdetails.php page shows details of a particular product.
I am using simple php format, How can I go about it? I have come this far at this point.
<div class = "uniqueproduct">
<?php
if (isset($_GET['id']))
{
$id = $_GET['id'];
$query1 = mysqli_query($conn, "select * from products where PRODUCT_ID = $id");
while ($row1 = mysqli_fetch_array($query1)) {
?>
<div class = "singleproduct">
<?php echo '<img src = "data:image/jpeg;base64,'.base64_encode($row1['PRODUCT_IMAGE']).'" alt = "" width = "250px" height ="300px"/>'; ?>
</div>
<div class = "productName">
<?php echo $row1['PRODUCT_NAME']; ?>
</div>
<div class = "productDescription">
<?php echo $row1['PRODUCT_DESCRIPTION'];?>
</div>
<div class = "productPrice">
<?php echo $row1['PRODUCT_PRICE']; ?>
</div>
<?php
}
}
?>
<button class = "btnPicture"> ..............</button>
</div>
how can i add active class to dynamic menu.I use while for my product list.But i cannot understand how can i add to active class.
<div class="col-md-4">
<h3>Products</h3>
<div class="list-group">
<?php
$db = new connection();
$productsor = mysqli_query($db,"select * from products");
while($productcek = mysqli_fetch_assoc($productsor)){ ?>
<?php echo $productcek['products_ad']; ?>
<?php
}
?>
</div>
</div>
You need to check against a previously set _GET parameter and compare it in your while loop
while($productcek = mysqli_fetch_assoc($productsor)){ ?>
<?php $active = (isset($_GET['products_id']) && $productcek['products_id'] == $_GET['products_id']) ? 'active' : null; ?>
<?php echo $productcek['products_ad']; ?>
<?php
}
?>
Im trying to connect to different database in the same page and select two times . but it seems not working and i get just one database and select working! this is my code
<?php
require_once ('../connect_upevent.php');
require_once ('../connect_events.php');
$select_upevent="SELECT * FROM upevent";
$result_upevent=mysqli_query($con,$select_upevent);
$select_events="SELECT img_name , title , LEFT(`content` , 540) as `content`,date, id FROM events";
$result_events=mysqli_query($con,$select_events);
mysqli_close($con);
?>
my while()
<?php while ($row_upevent = mysqli_fetch_array($result_upevent)) { ?>
<li>
<h4><?php echo $row_upevent['title'] ?></h4>
<div class="dt-sc-two-third column first event-index-float">
<img src="images/event/<?php echo $row_upevent['img_name'] ?>" alt="" title="">
<p><?php echo $row_upevent['content'] ?></p>
</div>
<div class="dt-sc-one-third column event-index-float">
<div class="venue">
<h5>location</h5>
<p><?php echo $row_upevent['place'] ?></p>
</div>
<div class="details">
<h5>time</h5>
<p><?php echo $row_upevent['date'] ?></p>
</div>
</div>
</li>
<?php } ?>
my while() #2
<?php while ($row_events = mysqli_fetch_array($result_events)) { ?>
<!--blog starts-->
<div class="dt-sc-one-half column first animate" data-animation="fadeInLeft" data-delay="300">
<article class="blog-entry">
<div class="entry-thumb">
<img src="images/event/<?php echo $row_events['img_name'] ?>" alt="" title="">
</div>
<div class="entry-details">
<div class="entry-title">
<h2><?php echo $row_events['title'] ?></h2>
</div>
<div class="entry-body">
<p><?php echo $row_events['content'].' [ ... ]' ?></p>
</div>
<div class="entry-footer">
read more<span class="fa fa-caret-left"></span>
</div>
</div>
</article>
</div>
<!--blog ends-->
<?php } ?>
so how can i get it work !?
Create two connection with different object
connect_upevent.php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection 1
$con1 = new mysqli($servername, $username, $password);
connect_events.php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection 2
$con2 = new mysqli($servername, $username, $password);
And use these connection like that
<?php
require_once ('../connect_upevent.php');
require_once ('../connect_events.php');
$select_upevent="SELECT * FROM upevent";
$result_upevent=mysqli_query($con1,$select_upevent);
$select_events="SELECT img_name , title , LEFT(`content` , 540) as `content`,date, id FROM events";
$result_events=mysqli_query($con2,$select_events);
mysqli_close($con1);
mysqli_close($con2);
?>
You are connecting successively and have same names for both database instances. You should rather make different connection objects. Just name them differently.
<?php
require_once ('../connect_upevent.php'); // $con_upevent
require_once ('../connect_events.php'); // $con_events
$select_upevent="SELECT * FROM upevent";
$result_upevent=mysqli_query($con_upevent, $select_upevent);
$select_events="SELECT img_name , title , LEFT(`content` , 540) as `content`,date, id FROM events";
$result_events=mysqli_query($con_events, $select_events);
mysqli_close($con_upevent);
mysqli_close($con_events);
?>
or connect to one, make query, connect to second and make query
<?php
require_once ('../connect_upevent.php');
require_once ('../connect_events.php');
$select_upevent="SELECT * FROM upevent";
$result_upevent=mysqli_query($con_upevent, $select_upevent);
$select_events="SELECT img_name , title , LEFT(`content` , 540) as `content`,date, id FROM events";
$result_events=mysqli_query($con_events, $select_events);
mysqli_close($con_upevent);
mysqli_close($con_events);
?>
<?php
// Connect to first DB
require_once ('../connect_upevent.php');
$select_upevent="SELECT * FROM upevent";
$result_upevent=mysqli_query($con,$select_upevent);
mysqli_close($con);
// Connect to second DB
require_once ('../connect_events.php');
$select_events="SELECT img_name , title , LEFT(`content` , 540) as `content`,date, id FROM events";
$result_events=mysqli_query($con,$select_events);
mysqli_close($con);
?>
I need to see the content of the included files:
connect_upevent.php
connect_events.php
But i guess, the problem is the following:
You work with the same instance $con.
So the first time you declare $con in the file "connect_upevent.php" and then it gets overwritten in the file "connect_events.php"
You should make two instances in the included files. Like:
$con_upevent and $con_events.
Otherwise, the $con variable is overwritten by the "connect_events.php" file
I have a file called productFocus.php where I use the GET variable ID: $id = $_GET["id"];
However this page is used in the product.php file in the following manner:
product.php
<?php
$page_content = 'productFocus.php'; // $id = $_GET["id"];
include('master.php');
?>
productFocus.php
<?php
include "db/db.php";
$id = $_GET["id"];
$product = get_product_by_id($id);
?>
<div class="product-focus">
<h3><?php echo $product->name ?></h3>
<img src="/images/products/<?php echo $product->image ?>">
<div id="description">
<h4>Productinformatie</h4>
<p><?php echo $product->description ?></p>
<h4>Partners</h4>
<table>
<?php
foreach($product->partners_obj as $partner) {
?>
<tr>
<td>
<a href=<?php echo $partner->$product_url ?> target="_blank">
<img id="partner" src="/images/partners/<?php echo $partner->image ?>">
</a>
</td>
<td>
<?php $partner->$product_price ?>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
master.php
//HTML code
...
<?php include($page_content);?>
...
//HTML code
When I browse to productFocus.php?id=324324 I can read the GET variable, but when I browse to product.php?id=324324 I do not have access to the GET variable ID.
Is there an elegant way to solve this issue?
You need to check the GET variable before you call the product details in the prodcts.php file before regular page load.
<?php
if (isset($_GET['id'])) {
// GET PRODUCT DATA
}else{
// LOAD PRODUCTS PAGE
}
?>
As for getting the product details, I would suggest writing the separate call to the database, but if you just need to load page content, you are not calling it properly:
$id = $_GET['id'];
$fileurl = 'products.php?id='.$id;
$pagecontent = file_get_contents('$fileurl');