I am currently working on a school project and appreciate your help.
HTML Code:
LINK 1
LINK 2
LINK 3
Now as I am relatively new to PHP, I need clue wehere to start or which topics are relevant for my solution. I have already searched the Forum here and with google, but unforutenly, didn't find anything, that fits my needs.
What I need, is a PHP-Code, that contains 6 href Links and every Link has a priority. So every time somebody clicks on "LINK 1" on the html file, he gets directed to the PHP-File "change-1.php", where one of the six href Links get activated.
PHP CODE "change-1.php":
<?php
if (condition) {
echo "http://www.someotherwebsite-1.com";
}
elseif (condition) {
echo "http://www.someotherwebsite-2.com";
}
elseif (condition) {
echo "http://www.someotherwebsite-3.com";
}
elseif (condition) {
echo "http://www.someotherwebsite-4.com";
}
elseif (condition) {
echo "http://www.someotherwebsite-5.com";
}
elseif (condition) {
echo "http://www.someotherwebsite-6.com";
}
?>
Perhaps this should help
LINK 1
LINK 2
LINK 3
Just create one change.php file
//to get change
<?php
if ($_GET['change'] == 1) {
echo "http://www.someotherwebsite-1.com";
}
elseif ($_GET['change'] == 2) {
echo "http://www.someotherwebsite-2.com";
}
elseif ($_GET['change'] == 3) {
echo "http://www.someotherwebsite-3.com";
}
elseif ($_GET['change'] == 4) {
echo "http://www.someotherwebsite-4.com";
}
elseif ($_GET['change'] == 5) {
echo "http://www.someotherwebsite-5.com";
}
elseif ($_GET['change'] == 6) {
echo "http://www.someotherwebsite-6.com";
}
?>
Now this is the basic idea. You can manipulate the data however you want.
I hope you got the concept.
Related
I was wondering if it's possible to have an if statement within an echo.
I have if statement which works fine when echoing results through the a while loop... This is the statement:
<div><?php if ($row['image'] == '') {}
else {echo "<img src='data:image/jpeg;base64,".base64_encode($row['image'])."'>";} ?>
<?php if ($row['video'] == '') {}
else {echo "<iframe src={$row['video']}></iframe>";} ?></div>`
So basically it's either a video or an image which works fine but then I implemented an infinite scroll to my blog which echoes the data from the database through and if statement like so:
if ($results) {
while($obj = $results->fetch_object())
{
echo '
<div><h3>'.$obj->headline.'</h3> </div>
<div><img src='data:image/jpeg;base64,".base64_encode('.$obj->image.')."'></div>'
So I wondering if anyone knows if it's possible to transfer that if statement within this echo so that it display an image firstly and then knows whether one is present or when a video is present within the database.
Thanks in advance for any help.
PS: I'm very new to coding/php!
Of course. Just split up the echo into multiple statements:
while($row = $results->fetch_object()) {
echo '<div>';
if ($row['image'] == '') {
} else {
echo "<img src='data:image/jpeg;base64,".base64_encode($row['image'])."'>";
}
if ($row['video'] == '') {
} else {
echo "<iframe src={$row['video']}></iframe>";
}
echo '</div>';
}
Try this one.
//first initialize a variable as a string
$result="";
while($obj = $results->fetch_object()) {
$result.="<div>";
if (!empty($obj['image'])){
$result.="<img src='data:image/jpeg;base64,".base64_encode($obj['image'])."'>";
}
elseif (!empty($obj['video'])){
$result.="<iframe src={$obj['video']}></iframe>";
}else{
//show some notification or leave it
//echo 'not Found';
}
$result.="</div>";
}
//finally you need to print the result variable.
echo $result;
if(count($fetchExperiences) > 0)
{
$i=0;
foreach($fetchExperiences as $fetchExperience)
{
$sqlExperiencedat = $db->createCommand(" code ");
$fetchExperiencesdat = $sqlExperiencedat->queryAll();
$tdyyy=date('YYYY-mm-dd');
if(strtotime($tdyyy)<strtotime($fetchExperience['experience_date']))
{
foreach($fetchExperiencesdat as $fetchExperiencesdatt)
{
if(strtotime($tdyyy)<strtotime($fetchExperiencesdatt['avail_date']))
{
//echo $fetchExperiencesdatt['avail_date'];
$tth=1;
}
}
if($tth==1){
//fetchExperiencesdatt code
}
}
}
if(count($fetchCountExperiences) > 8){
<a class="more_experience" style="clear:both;"><span onclick="getMoreExperiences1('<? php echo count($userResults);?>','<?php echo $_SESSION['user_id']; ?>','8')">More Experiences</span></a>
}
}
}
My question is that I want more button after $fetchexperiences count is greater than 8. It is fine. But in between $fetchexperiences loop there is a loop for $fetchExperiencesdat. by the loop if there is no experince with in availdate it is not shown. so the probelm is more button is display not after 8 because of some $fetchExperiencesdat elements should be hidden. So please give me any solution for this.
Thanking you.
I'm not sure I understand where your count experiences are coming from. However, the problem your code has is that fetchCountExperiences is not given a value.
if(count($fetchCountExperiences) > 8){
<a class="more_experience" style="clear:both;"><span onclick="getMoreExperiences1('<? php echo count($userResults);?>','<?php echo $_SESSION['user_id']; ?>','8')">More Experiences</span></a>
}
Looks like it should be
if(count($fetchExperiences) > 8){
<a class="more_experience" style="clear:both;"><span onclick="getMoreExperiences1('<? php echo count($userResults);?>','<?php echo $_SESSION['user_id']; ?>','8')">More Experiences</span></a>
}
I am editing a part of a script that displays gender of a person but trying to add additional options.
The form that saves the information saves it as a value.
In my lang file this is what i have got related to the part i am trying to change :
$LNG['powner'] = 'Pet Owner';
$LNG['dog'] = 'Dog';
$LNG['cat'] = 'Cat';
$LNG['rabbit'] = 'rabbit';
The part of the code im trying to display is
((!empty($profile['gender'])) ? '<div class="sidebar-list">'.$LNG['ttl_gender'].':
<strong>'.(($profile['gender'] == 1) ? $LNG['powner'] :($profile['gender'] == 2) ?
$LNG['cat'] : ($profile['gender'] == 3) ? $LNG['rabbit'] : $LNG['rabbit']).'</strong>
</div>' : '').'
But it will only display cat or rabbit ...
I am thinking that the code is set to be one or the other because this works :
((!empty($profile['gender'])) ? '<div class="sidebar-list">'.$LNG['ttl_gender'].'
: <strong>'.(($profile['gender'] == 1) ? $LNG['dog'] : $LNG['cat']).'</strong></div>'
: '').
after the code if follows
'.((!empty($profile['website'])) ? '<div class="sidebar-list">'
.$LNG['profile_website'].': <strong><a href="'.$profile['website'].
'" target="_blank" rel="nofllow">'.$LNG['profile_view_site'].'</a>
</strong></div>' : '').'
Your code could be re-written to say:
if(!empty($profile['gender']) {
echo '<div class="sidebar-list">'.$LNG['ttl_gender'];
} else {
echo "<strong>";
if($profile['gender'] == 1) {
echo $LNG['powner'];
} else {
if($profile['gender'] == 2) {
echo $LNG['cat'];
}
else {
if($profile['gender'] == 3){
echo $LNG['rabbit'];
} else {
echo $LNG['rabbit'];
}
}
}
}
As you see the code using shorthand If/Else statements is confusing to read, and can lead to mistakes. Re-write your functionality in more readable way, and you will prevent errors, and confusion with regards to what the actual conditions should be.
I'm assuming that the problem you're having is that the users you're testing this on are either gender 2 or 3, and never 1.
My piece of code.
And problem now are about styling, i just want style page number, wich is open, like a active id, if page open, then that number is in different color or smth else.
I need make a new variable? Or what, i just try to add but its wont work, it only works if at the end i write echo $page; , then it show style on this, but i need on links, numbers.
<?php
if($total_pages > 1){
if($page != 1){
echo ' < ';
}
for($number=1;$number<=$total_pages;$number++)
{
echo ''.$number.'';
}
if($page != $total_pages){
echo ' > ';
}
}
?>
You can do something like this.
$currentPageNumber = $_GET['page'];
for($number=1;$number<=$total_pages;$number++){
$currentPageStyle = '';
if($number == $currentPageNumber){
$currentPageStyle = 'style="color:red"';
}
echo '<a href="?page='.$number.'" '.$currentPageStyle.'>'.$number.'</a>';
}
I have a situation whereby i want two of my pages to look different form the rest but they are not front pages. If they were it would be easy as the code below would do the trick.
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
esle(do something else)
}
?>
In short i want a similar approach but this time, to get the menu by ID/URL. Any ideas?
I got the answer to this...all you need to check is the menu ID then put the code below.
<?php
//This is the code for the page with menu ID 6
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '6')
{
echo '';
}
elseif ($menuID == '2') //This is the HTML for page with menu ID 2
{
echo '';
}
elseif ($menuID == '4') //THis is the html for page with menu id 4
{
echo '';
}
else //This is the HTML code for the rest of the pages
{
echo '';
}
?>
Page ItemId can be obtained using $itemid = JRequest::getInt( 'Itemid' );