I start the page with the:
$selectedMenu = $_GET['selectedMenu'];
Then I have next and previous functions
<?php if ($prev) { ?>
<a href='?AID=<?=$prev?>&selectedMenu=$selectedMenu' style='background-image:url(/images/navDivider.png); background-position:right center; background-repeat: no-repeat; padding-bottom:4px; padding-top:4px;'>back </a>
<?php } else { ?>
<a href='gallery.php?CID=<?=$CID?>&SCID=<?=$SCID?>&selectedMenu=$selectedMenu' style='background-image:url(/images/navDivider.png); background-position:right center; background-repeat: no-repeat; padding-bottom:4px; padding-top:4px;'>back </a>
<?php } ?>
<?php if ($next){ ?>
<a href='?AID=<?=$next?>&selectedMenu=$selectedMenu'> next</a>
<?php } ?>
There is a query that pulls the AID, CID, and SCID
But what happens is that the $selectedMenu won't stay after the fist page even though I am passing it in the url. Any clues why it's dropping out?
Try using a query string management class. For example: https://github.com/kenaniah/insight/blob/master/classes/querystring.php
Example usage:
<?php
$qs = new QueryString;
$qs->CID = $CID;
print "<a href='blah.php".$qs."'>Link</a>";
?>
Try this:
<?php if ($prev) { ?>
back
<?php } else { ?>
back
<?php } ?>
<?php if ($next) { ?>
next
<?php } ?>
It was probably because you had a PHP variable in there without a surrounding PHP start and end tag. Also gave you proper echo statements.
Edit: Damn, realized you already got the answer.
Related
IN PHP I noticed that if we have code like below:
<?php if ( function('parameter')):?>
<?php //do something here ?>
<?php endif; ?>
why can't we write this code like:
<?php if ( function('parameter'))
//do something here
endif; ?>
I am new to PHP, Thanks a lot!!
The PHP code has to be inside <?php ?> and the HTML markup needs to be outside. You can also print out the HTML markup with echo.
Here is an example (much cleaner in my opinion, than example 2). The HTML markup is inside a PHP string. The return value of the_field(), a string, is then concated with .:
<?php
the_post_thumbnail('square');
if(get_field('quote_url')) {
echo '<p class="btn">Request a Quote</p>';
}
if(get_field('rfq_pdf_url')) {
echo '<p class="btn">Download PDF</p>';
}
?>
And here is another valid example (2). You can end the PHP part with ?> and output regular HTML markup and then start the PHP part again with <?php:
<?php
the_post_thumbnail('square');
if(get_field('quote_url')) { ?>
<p class="btn"><a href="
<?php the_field('quote_url'); ?>
">Request a Quote</a></p>
<?php }
if(get_field('rfq_pdf_url')) { ?>
<p class="btn"><a href="
<?php the_field('rfq_pdf_url');?>
">Download PDF</a></p>
<?php }
?>
It would however be redundant to start with <?php on every line and end it then again with ?>.
Another possibility would be:
<?php
the_post_thumbnail('square');
if(get_field('quote_url')) {
?>
<p class="btn"><a href='<?php echo the_field('quote_url'); ?>'>Request a Quote</a></p>
<?php
}
if(get_field('rfq_pdf_url')) {
?>
<p class="btn">Download PDF</p>
<?php
}
?>
I need some help..
I have a line of PHP that is echoing a url for me -
<?php foreach($day as $item) : ?>
<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')"><?php echo $item['show_name'] ?> </br> <?php echo $item['ep_name'] ?></li>
<?php endforeach ?>
The problem I have is that the URL here -
<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')">
Appears to kill the code, so I assume my syntax is wrong, if I remove the "background stuff" the code works and the other 2 variables are mapped ok, i'm now wanting to set the backgroud of each li as per the image being returned from the API call, but I can't get it working..i'm sure someone here will sort it really easily for me..
Thanks
Yes you have syntax error in your code:
Modified Example:
<li style='background: url(<?php echo 'http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid='.$item['tvdbid'];?>)'>
Alternate Solution:
<?php
$url = "http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=".$item['tvdbid'];
?>
<li style='background: url(<?php echo $url; ?>)'>
I have a php file tab.php which is creating tabs.The code of tab.php is:
<ul id="tabs">
<?php
$tab=' ';
if($tab=='') $tab='setup';
//$tab=$_REQUEST['tab'];
if($tab=='setup'){ ?>
<li><b><span>Setup</span></b></li>
<?php
}else{ ?>
<li><span>Setup</span></li>
<?php } ?>
<?php if($tab=='options'){ ?>
<li><b><span>Options</span></b></li>
<?php }else{ ?>
<li><span>Options</span></li>
<?php } ?>
<?php if($tab=='questions'){ ?>
<li><b><span>Questions</span></b></li>
<?php }else{ ?>
<li><span>Questions</span></li>
<?php } ?>
<?php if($tab=='flow'){ ?>
<li><b><span>Flow</span></b></li>
<?php }else{ ?>
<li><span>Flow</span></li>
<?php } ?>
</ul>
<div style="clear:both; background-color:#edcb27; height:0px; overflow:hidden;"></div>
<div style="border:solid 3px #edcb27; background-color:#edcb27; padding:10px; font-family:Verdana, Geneva, sans-serif; font-size:11px;">
<label>Edit Mode</label>
<label>dfhfghj</label>
I have four php files namely setup.php,options.php,question.php and test.php.What I want is when I click on setup tab setup.php should open.When I click on option.php then my option.php should open and so on.Initially setup.php should be visible.So where should I include my all four php files so that particular php file should be open when clicking on tab?
If your page will be refresh each time when you press a tab you can use a switch statement and get tab value from query-string:
$tab = $_GET["tab"];
switch ($tab) {
case "setup":
require "setup.php";
break;
default:
break;
}
to load a YOUR_FILENAME.php.
Other (good) solution is use a asynchronous request with jQuery or other JavaScript libraries.
Cheers
If you are putting all your tab pages in the same folder as this code, this should do the trick
<ul id="tabs">
<?php
$tab='';
if(!isset($_GET['tab'])) $tab='setup';
else $tab = $_GET['tab'];
//$tab=$_REQUEST['tab'];
if($tab=='setup'){ ?>
<li><b><span>Setup</span></b></li>
<?php
}else{ ?>
<li><span>Setup</span></li>
<?php } ?>
<?php if($tab=='options'){ ?>
<li><b><span>Options</span></b></li>
<?php }else{ ?>
<li><span>Options</span></li>
<?php } ?>
<?php if($tab=='questions'){ ?>
<li><b><span>Questions</span></b></li>
<?php }else{ ?>
<li><span>Questions</span></li>
<?php } ?>
<?php if($tab=='flow'){ ?>
<li><b><span>Flow</span></b></li>
<?php }else{ ?>
<li><span>Flow</span></li>
<?php } ?>
</ul>
<div style="clear:both; background-color:#edcb27; height:0px; overflow:hidden;"></div>
<div style="border:solid 3px #edcb27; background-color:#edcb27; padding:10px; font-family:Verdana, Geneva, sans-serif; font-size:11px;">
<label>Edit Mode</label>
<label>dfhfghj</label>
<!-- assuming you are putting the content of the page here -->
require($tab.'.php');
I'd just do it with if(isset($_GET['setup'])) { display setup code } seems the simple solution to me.
I'm designing a web page to show some commodity
results (such Model, price, Comment) for every Commodity is a database
and I call theme to show in each Commodity (it while be shown in a div)
I wanna to set backgrounds for each div (it saved in database and every Commodity have one background-image)
please tell me whats the true syntax for this div s
for example I wrote this code:
<div class="commodities"> <style>.commodities{ background-image:<?php $Images[$i]?>} </style>
<?php
echo "Model:";
echo $Models[$i];
echo "<br><br>";
echo "Price: ";
echo $Prices[$i];
echo "<br><br>";
echo $Comments[$i];
?>
</div>
please help me to fix this part of code: { background-image:}
You have to do this:
<div class="commodities" style="background-image: url('<?php $Images[$i]?>');">
<?php
echo "Model:";
echo $Models[$i];
echo "<br><br>";
echo "Price: ";
echo $Prices[$i];
echo "<br><br>";
echo $Comments[$i];
?>
</div>
If you put < style > tags in the < body > (put it on the < head > tags) you are doing nothing ;)
Instead use style property. ;)
Apart you are forgetting to use url tag on the background-image property. ;)
You are missing two keywords, scoped and url. See e.g. http://www.w3schools.com/tags/att_style_scoped.asp and http://www.w3schools.com/cssref/pr_background-image.asp.
use inline css.
<div style="background-image: url(<?php echo $variable_name; ?>);">
or
use internal css.
<style type="text/css">
.logo {
background: #FFF url(<?php echo $variable_name; ?>);
}
</style>
<?php do { ?>
<?php echo ""; ?><?php echo $row_pageDetails['name']; ?>(<?php echo $row_pageDetails['profile']; ?>) </br>
<?php } while ($row_pageDetails = mysql_fetch_assoc($rspageDetails)); ?>
This gives a clickable link name(profile) but if the profile is empty It shows () how can I improve it so that when the profile record is empty it shows nothing.
You have many unnecessary opening and closing php tags. You should only use one for this whole thing given your code.
And you have a mis-closed </br> tag, should be <br/> and it would be better if you put it after the closing anchor tag.
You can not show the link at all by putting the whole thing in an if statement
<?php
do {
if(!empty($row_pageDetails['profile'])){
echo "<a href=\"$row_pageDetails[website]\">";
echo $row_pageDetails['name'] . "($row_pageDetails[profile])</a><br/>";
}
} while ($row_pageDetails = mysql_fetch_assoc($rspageDetails));
?>
instead of
(<?php echo $row_pageDetails['profile']; ?>)
use ternary operator
<?php echo ($row_pageDetails['profile']) ? '('.$row_pageDetails['profile'].')' : ''; ?>
Your code must be something like this
<?php do {
echo (isset($row_pageDetails['profile']) && !empty($row_pageDetails['profile']))?
''.$row_pageDetails['name'].'('.$row_pageDetails['profile'].')':''; } while ($row_pageDetails = mysql_fetch_assoc($rspageDetails)); ?>