I have 2 tables:
TABLE users (id, name, image, user_group_id)
TABLE user_groups (id, name, menu)
column menu value contains something like this:
<img src="../images/employees/'.$row_UserDetails['Image'].'" alt="">
Now at img src its creating a problem.
'.$row_UserDetails['Image'].'
This doesn't display the value.
Why is that and how do we fix this?
I want to display results from recordset UserGroup like this:
Now the value coming from php mysql is: <img src="../images/employees/'.$row_UserDetails['Image'].'" alt="">
you see .$row_UserDetails['Image'].
This value must be abc.jpg which comes from Recordest UserDetails:
On this php page if i want to display user name, i use php echo like this: <?php echo $row_UserDetails['Name'];?>
When using echo in php you will need to escape the quotes as they cause problems.
<header id=\"header-navbar\" class=\"content-mini content-mini-full\"> <ul class=\"nav-header pull-right\"> <li> <div class=\"btn-group\"> <button class=\"btn btn-default btn-image dropdown-toggle\" data-toggle=\"dropdown\" type=\"button\"> <img src=\"../images/employees/\"" .$row_UserDetails['Image']. "\" alt=\"\"> <span class=\"caret\"></span> </button> <ul class=\"dropdown-menu dropdown-menu-right\"> <li> <a tabindex=\"-1\" href=\"my-profile.php\"> <i class=\"si si-user pull-right\"></i> My Profile </a> </li> <li> <a tabindex=\"-1\" href=\"../logout.php\"> <i class=\"si si-logout pull-right\"></i>Log out </a> </li> </ul> </div> </li> </ul>
</header>
You say you echo $row_UserDetails['Image'], but I don't see an echo statement anywhere. Also, if that PHP code is really in your database like that, I believe you are on the wrong track.
Much better would be to use some sort of placeholder, and replace that by your desired database value when rendering that menu.
Something like this:
// assume something like "... <img src="../images/employees/%{image}"> ..."
// in the menu column, where '%{image}' serves as a placeholder
echo str_replace('%{image}', $row['image'], $row['menu']);
You need to echo your tag or echo your data inside the src attribute to use the value return by $row_UserDetails['Image'].
If you have done so, this may be the problem.
You have a issue with cocatenation. Your code should be like this
<?php echo "<img src='../images/employees/".$row_UserDetails['Image']."' alt='test'/>"; ?>
This article mat help you : https://teamtreehouse.com/community/why-do-we-use-concatenation-when-outputting-this-img-tag-with-php
Best regards !
Related
I have a URL that looks like:
example.com/profile.php?id=1
I want to dynamically generate the URL by taking username from the form input in the database's id field. Like :
example.com/profile.php?id=username
This link give errors.If I use below link than it works
example.com/profile.php?id="username"
But , I am facing problem in anchor tag.My Code :
<a href="contributor-profile.php?id=<?PHP echo "$data['id']";?>">
<h4 class="contributor-name">
<?PHP echo $data ['name'];?>
</h4>
</a>
I have also used urlencode fuction but it is not working.
<a href="profile.php?id=<?PHP echo urlencode($data['id']);?>">
<h4>
<?PHP echo $data ['name'];?>
</h4>
</a>
I'm making a website where users can post stories etc and they get put into the MySQL database and the front page pulls the top-rated stories from the database and fills in the HTML template I made to display.
So I pull the top rated post and put it inside the article tags that I've made inside my HTML. The question is when it displays it displays outside of the box. Like so
The actual display is supposed to look like this
How do I format the PHP code, Or is there some better way to go about doing this?
<article class="post featured">
<header class="major">
<span class="date">April 25, 2017</span>
<h2>
And this is a<br />massive headline
</h2>
<?php echo '<p>' . htmlspecialchars($row['post'], ENT_QUOTES, 'UTF-8') . '</p>'; ?>
</header>
<img src="images/pic01.jpg" alt="" />
<ul class="actions special">
<li>Full Story</li>
</ul>
<span class="tags badge-pill badge-primary">Otero</span>
<span class="tags badge-pill badge-info">SCR</span>
<span class="tags badge-pill badge-success">Class of '22'</span>
<span class="tags badge-pill badge-danger">Male</span>
</article>
EDIT: Here is the HTML spot I'm talking about
Ok, It`s easy to solve. First your string has only one word (because doesn´t have spaces) an second, when you have a paragraph, the tag that wrap content has an autoalignement.
Maybe you can try adding some css rules for your parent div?
You may check this : https://stackoverflow.com/a/3367759/8186765
<li class="list-group-item">
<a href="/user/Michael" class="thumb-sm pull-left m-r-sm">
<img src="http://www.gravatar.com/avatar/8b7a9ba3cbf958009080f6da12a55029?&d=mm&r=g?&d=mm&r=g&s=215" class="img-circle">
</a>
<a href="user/Michael" class="clear">
<strong class="block">
<?php include '/includes/connection.php';?>
<?php echo $products['Title'] ; ?>
</strong>
<?php include '/includes/connection.php';?>
<small><?php echo $products['Followers'] ; ?> Followers </small>
</a>
</li>
<li class="list-group-item">
<a href="/user/Steven" class="thumb-sm pull-left m-r-sm">
<img src="http://www.gravatar.com/avatar/a5fb2decd550cdf33cbb8ce7566ba772?&d=mm&r=g?&d=mm&r=g&s=215" class="img-circle">
</a>
<a href="/user/Steven" class="clear">
<strong class="block">
<?php include '/includes/connection.php';?>
<?php echo $products['Title'] ; ?>
</strong>
<small><?php echo $products['Followers'] ; ?> Followers</small>
</a>
</li>
do i need to manually insert for every content?
I have over 100 contents how can i automatically insert in every line like content 1 display row 1 followers and content box 2 display row 2 followers and so on
The trick here is to make a loop within the code. This means you have to generate all content from out of the database or it's not gonna work. Let me show you an example:
<ul>
<?php
$sql = "SELECT ProjectId, ProjectTitel, ProjectExpertise
FROM project";
$stmt1 = mysqli_prepare($con, $sql);
mysqli_stmt_execute($stmt1);
mysqli_stmt_bind_result($stmt1,$ProjectId,$ProjectTitel,$ProjectExpertise);
while (mysqli_stmt_fetch($stmt1)){
?>
<li class="wow fadeInLeft" data-wow-offset="30" data-wow-duration="1.5s" data-wow-delay="0.15s">
<a href="inc/elements/project.php?id=<?php echo $ProjectId; ?>" class="meer">
<img src="img/portfolio/<?php echo $ProjectId; ?>/thumbnail/1.jpg" alt="<?php echo $ProjectTitel; ?> project">
<div class="project-info">
<div class="project-details">
<h5 class="witte-text blauwe-streep-onder">
<?php echo $ProjectTitel; ?>
</h5>
<div class="details witte-text">
<?php echo $ProjectExpertise; ?>
</div>
</div>
</div>
</a>
</li>
<?php
}
?>
</ul>
I start an UL outside of the PHP code and then I start my PHP query, as you see, i select the items i need from the database. Here i create a while loop and run through my setup of the list element. As you see, i use my items within the project id link (the link is an ajax call to another page), the thumbnail needed to show the picture, the title and the expertise i used.
In your case, the while loop you need requires more than just the the title and followers. I think you need as well an userid / username so you can take in account which user it is. Your loop would now proces all on the same user, since its staticly defined in your code. Also the avatar picture is staticly defined. Let me try to resolve some for you.
<?php
include '/includes/connection.php';
$sql = "SELECT products.title, products.followers
FROM products"; // as example query
$stmt1 = mysqli_prepare($con, $sql);
mysqli_stmt_execute($stmt1);
mysqli_stmt_bind_result($stmt1,$title, $followers);
while (mysqli_stmt_fetch($stmt1)){
?>
<li class="list-group-item">
<a href="/user/Michael" class="thumb-sm pull-left m-r-sm"> <!-- make the username also to be pulled out of a database. -->
<img src="http://www.gravatar.com/avatar/8b7a9ba3cbf958009080f6da12a55029?&d=mm&r=g?&d=mm&r=g&s=215" class="img-circle">
</a> <!-- you should save the avatar link into a database as well -->
<a href="user/Michael" class="clear"> <!-- make the username also to be pulled out of a database. -->
<strong class="block">
<?php echo $title; ?>
</strong>
<small>
<?php echo $followers; ?>
Followers
</small>
</a>
</li>
<?php
}
?>
This as example. As you see, i added notitions behind some code, to explain this should also be dynamic, since it will help you Remember. being a programmer is to find shortcuts on how you display your information. Code that repeats itself constantly with a changing variable should always be looped, to make sure you dont type unneccesairy code.
Since I dont know how your database is made, i can only guess, Michaels name is probably linked to an ID in the same table your products are, which you can use then in to pull out of the database, by searching in your user table. I hope I make sense here. For instance, your products.userid should be as well in your user table as user.userid. Most likely the userid will have a name linked to it in the user table.
$sql = "SELECT products.title, products.followers, products.userid, user.userid, user.username
FROM products, user
WHERE user.userid = product.userid";
So now you have in each row as well the name of the person of who's title it is. And that you can echo out again in the code i put up. (make sure you bind the result in the same order as you pulled them up)
Writing code is all about making it easier to display your information. Loops is and stays the keyword here, as NadirDev explains.
I hope I helped you getting on the right track.
I've already been searching for a couple of hours for a solution. What I want to do is make icons that don't got a value (in the php) not show up.
Here's an image of what I currently have.
So for instance if only twitter and facebook got values, they should only appear on the screen.
Below is the code, and I hope someone got a solution for this.
Cheers!
<ul class="social-buttons">
<div class="wrapping">
<a class="social" href="http://twitter.com/<?php echo $profile_data['twitter']; ?>" target="_blank"><li class="twitter"></li></a>
<a class="social" href="http://facebook.com/<?php echo $profile_data['facebook']; ?>" target="_blank"><li class="facebook"></li></a>
<a class="social" href="skype:<?php echo $profile_data['skype']; ?>?chat"><li class="skype"></li></a>
<a class="social" href="http://instagram.com/<?php echo $profile_data['instagram']; ?>"><li class="instagram"></li></a>
<a class="social" href="http://dribbble.com/<?php echo $profile_data['dribbble']; ?>"><li class="dribbble"></li></a>
<a class="social" href="http://linkedin.com/in/<?php echo $profile_data['linkedin']; ?>"><li class="linkedin"></li></a>
</div>
</ul>
You need to use the if statement with !empty(). The !empty() checks if a variable is NOT empty. Than proceed with the code. Like the example given here:
<?php
if(!empty($profile_data['twitter'])){
?>
<a class="social" href="http://twitter.com/<?php echo $profile_data['twitter']; ?>" target="_blank"><li class="twitter"></li></a>
<?php
}
?>
If the variable is empty, it wont give the outputed code, in your case the <a> with the icon.
i think you can do like:
<ul class="social-buttons">
<div class="wrapping">
<?php if $profile_data['twitter'] {?>
<a class="social" href="http://twitter.com/<?php echo $profile_data['twitter']; ?>" target="_blank"><li class="twitter"></li></a>
<?php } ?>
....
</ul>
Imo, a probably better way to do this is to perform a pre-processing of the data i.e. $profile_data, before you use it in your view so the view would no longer need to handle the processing logic. After which, the view can output your links by using a more concise construct e.g. for loop, that does not use any conditional branching.
To create an editable pane in C5 I use the following between div tags so the user can simply use the content editor to add text. This works quite well:
<div class="myWrapper">
<?php
$a = new Area('WelcomeText');
$a->display($c);
?>
</div>
But what do I do when the mark-up is a little complicated? I would like to get user to update the 2 images and respective links themselves. Eg picture: http://i48.tinypic.com/4jma8p.png
What is the easiest way for non-code literate users to do this?
<ul class="Gal_2">
<li class="Frst">
<a href="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG2.jpg" rel="group">
<img src="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG2.jpg" width="224" height="150" alt="Island Rab" align="left" />
</a>
</li>
<li>
<a href="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG1.jpg" rel="group">
<img src="<?php echo $this->getThemePath(); ?>/Images/TEMP_IMG1.jpg" width="224" height="150" alt="Island Rab - Lopar beach" align="right" />
</a>
</li>
</ul>
Thanks in advance...
PC
Create a custom block with the free Designer Content addon: http://www.concrete5.org/marketplace/addons/designer-content
The block you create will have two image fields that link to other pages, and then use "static html" fields to surround the images with your <ul> and <li> tags.
This is actually a perfect use case for Designer Content, so it should be fairly self-explanatory. But if you run into problems, post a message to the support forum (or just email me directly at concrete#jordanlev.com).