Variable in page title? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a page that contains a DB query, If there is a county in the URL then I run another query.
<head>
<title>Query results in $county</title>
</head>
...
if (isset($county)) {
// If county is set
$sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND County = :county");
} else {
// Run another query
}
I want to add the county in the page title if the county is set. Is this possible?

if (isset($county)) {
echo "<title>Query results in $county</title>\n";
} else {
echo "<title>Some other title</title>\n";
}

Absolutely. Just make sure your php that sets $county comes before the start of your html, then change your title tag to this:
<title>Query results in <?php echo $county;?></title>
Edit: Although j08691's answer is more comprehensive.

Related

How to state 2 or more different consequences if an if statement condition is true? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I would like to have 2 things happen if an if statement condition is met. If isset is true the variable $value will equal 1. The problem is that I also want the value of a session variable $_SESSION['counter'] to increment by 1, but I am unsure of the syntax.
<?php
session_start();
$_SESSION ['counter']=0;
function checkbox_boolean ($name){
if (isset($_POST[$name])) $slot1 = '1'; $_SESSION['counter']++; else $slot1='0';
}
This will work and its a better solution:
<?php
session_start();
$_SESSION['counter']=0;
function checkbox_boolean ($name){
$slot1=0;
if(isset($_POST[$name])){
$slot1 = 1;
$_SESSION['counter']++;
}
}
?>

how to post SQL variable through session and get it in next page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to post $dataHeadArr value through session and get it in next page.
<?php
if(isset($_POST["search"]))
{ $storename=$_POST["StoreName"];
$dataHeadArr=$db->query("SELECT *FROM `opening_stk`");?>
On for the page you have posted put
<?php
if(isset($_POST["search"])){
session_start();
$storename=$_POST["StoreName"];
$dataHeadArr=$db->query("SELECT * FROM `opening_stk`");
while($row=mysql_fetch_assoc($dataHeadArr)){
$allRows[]=$row;
}
$_SESSION['dataHeadArr']=$allRows;
}
?>
For the page that you want to retreive the variable put
<?php
session_start();
$dataHeadArr=$_SESSION['dataHeadArr'];
//This mysql result been parsed already, so you should be
//able to access values when you loop through it from here
for($i=0;$i<count($dataHeadArr); $i++){
echo "Printing row ".$i."</br>";
foreach($dataHeadArr[$i] as $key=>$item){
//Prints out all value for the row
echo $item[$key]."</br>";
}
echo "</br>";
}
?>
You may just set it in the POST or SESSION array and then retrieve it on next page. For ex-
$_POST['dataHeadArr']=$dataHeadArr;
To store...
$_SESSION['dataHeadArr'] = 'Whatever';
Then to retrieve simply..
if(isset($_SESSION['dataHeadArr'])){
echo $_SESSION['dataHeadArr'];
}
Make sure to call session_start(); at the top of every page.

File name as variable+.txt [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
session_start();
$user = $_SESSION['username'];
if( isset($_POST['subm_btn']) ) {
incrementClickCount();
}
function getClickCount()
{
return (int)file_get_contents($user.".txt");
}
function incrementClickCount()
{ $count = getClickCount() + 1;
file_put_contents($user.".txt", $count);
}
User register on my site, then he click on button (name="subm_btn"). I want count clicks and add number of clicks in file with name "username.txt"
I guess you are looking for something like this:
$file=$user.'.txt';
incrementClickCount($file);
function incrementClickCount($file){
$count = getClickCount($file) + 1;
file_put_contents($file, $count);
}
function getClickCount($file) {
return (int)file_get_contents($file);
}
If you want the variable to be available inside a function you either make it global or pass it as an argument (which is better).
You define $user, and then access $user1. That would be my guess as to why it doesn't work. Also, using $file might be a better idea anyway.

Creating custom ahref links in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How do you create a custom links in ahref using php as shown below
link from : http://www.top10bestwebsitehosting.com/visit.php?site=iPage
goes to : http://www.ipage.com
Perhaps something like this:
$sites = array(
'iPage' => 'http://www.ipage.com/',
'Google' => 'http://www.google.com/',
);
$key = $_GET['site'];
if(isset($sites[$key])) {
header('Location: ' . $sites[$key]);
exit;
}
echo 'Sorry, no such site.';
There is redirect, if you open in firefox developer tools and after open a link, and pressing escape key(else you will be redirected) you can see the next url:
http://naturaltracking.com/redirect.php?url=http%3A%2F%2Fwww.ipage.com%2Fjoin%2Findex.bml%3FAffID%3D638751%26amp%3BLinkName%3D&uid=6344b6a239bb&sid=374eaa4bb6d2&hukc=1&nicid=00004ZQNza&nivkey=FiiRIhiDHa
It was most likely done in this way:
have an internal list of what $_GET['site'] can be
read $_GET['site']
redirect to the corresponding website
This is an example:
<?php
// visit.php
$pages = array('iPage'=>'www.ipage.com','google','www.google.com');
if (in_array($pages,$_GET['site']))
{
// do some internal logging or whatever
header("Location: ".$pages[$_GET['site']]);
}
?>
The way top10bestwebsitehosting does is, it keeps the urls in the database. So then it does something similar to the below:
$name = mysql_real_escape_string($_GET['site']); //check for escapes etc.
$query = mysql_query('select * from `websites` where `name` = {$name} limit 1');
$row = mysql_fetch_row($query);
header('Location: '.$row['url']);

Dropdown variable script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have the following code:
echo "<td><textarea wrap='soft' class=tarea3 name='inston[]'>".$r['inston']."</textarea></td>\n";
I'd like to use that inston variable to associate with a dropdown list. I have working code for the dropdown list:
<tr><td class="tdt">
<?php te('Hosting Server');?>:</td> <td title='Select server'>
<select validate='required:true' class='mandatory' name='manufacturerid'>
<option value=''>Select</option>
<?php
foreach ($agents5 as $a) {
$dbid=$a['id'];
$atype=$a['label']; $s="";
if (isset($manufacturerid) && $manufacturerid==$a['id']) $s=" SELECTED ";
echo "<option $s value='$dbid' title='$dbid'>$atype</option>\n";
}
echo "</select>\n";
?>
</td></tr>
and a sql query for the above mentioned dropdown script,
$sql="SELECT * FROM items where itemtypeid=32 OR itemtypeid=44 order by label";
$sth=db_execute($dbh,$sql);
while ($r=$sth->fetch(PDO::FETCH_ASSOC)) $agents5[$r['id']]=$r;
How can we use the code above to associate inston variable?
Your question isn't clear and from what i understood, is suppose the answer to be this
First of all , use an id for the select tag and textarea and use an onChange function like this:
<textarea wrap='soft' class=tarea3 name='inston[]' id='inston'>".$r['inston']."</textarea>
<select validate='required:true' class='mandatory' name='manufacturerid' id='manufacturerid' onChange='setInston()'>
and the use this javascript function :
function setInston() {
var x = document.getElementById("manufacturerid").value;
document.getElementById("inston").innerHTML= x+"
";
}

Categories