How to get a single variable attached to the URI? - php

I don't seem to able to acquire a GET variable that is attached to the URI.
The codes are => at the controller
...
parse_str($_SERVER['QUERY_STRING'], $_GET);
....
$data['ti'] = $this->input->get('hamleno');
this->load->view('anasayfa', $data);
The codes are => at the view the link is
...
<div class="row"><?php for ($b=0; $b<=(count($hml)-1); $b++) { ?><?php echo $hml[$b]." "; ?> <?php } ?></div>
The link is working. I have added the
$config['uri_protocol'] = "PATH_INFO";
to the config.php file.
However I am not able to get the $ti variable
if ($ti){
$t=$ti;
}else{
$t = $this->input->post('t');
if (!$t) $t = 0;
if( $this->input->post('ileri') ) {
$t=$t+1;
if($t>($uz-1)){
$t=$uz-1;
}
} // Forward button was pressed;
if( $this->input->post('geri') ) {
$t=$t-1;
if($t<0){
$t=0;
}
} // Back button was pressed;
}

I'm not familiar with codeigniter, but I've always passed GET variables in this manner:
URL = www.site.com/folder/webpage.php?myvariable=myvalue
I would retrieve that value this way:
$x = $_GET['myvariable'];
or with codeigniter: (I think)
$x = $this->input->get('myvariable');
Tailored to your example, I would personally de-obfuscate your loop code just a little and instead of switching from PHP to HTML and back in one line, I would simply echo both from PHP like this:
(I also don't exactly understand the url you're using, so here is my approximate)
<?php
for ($b=0; $b<=(count($hml)-1); $b++)
{
echo '',$hml[$b],' ';
}
?>

I found out how Codeigniter solves the problem =>
$get = $this->uri->uri_to_assoc();
if(isset($get['hamleno'])){
$data['ti'] = $get['hamleno'];
}
This sends the $b assigned to $hamleno together with all the other stuff in $data.
Thank you all for your kind comments

Related

php code only work if files has been changed

The variable in the session only changes if i update the file meaning:
<?php
if(isset($_GET['row']) && isset($_GET['quantity'])) {
if($_GET['quantity'] != 0) {
$_SESSION['basket'][$_GET['row']]['barcode']['quantity'] = $_GET['quantity'];
} else {
unset($_SESSION['basket'][$_GET['row']]);
}
}
?>
Changes the quantity first time and then in other tries doesn't.
If I change it to something like:
<?php
if(isset($_GET['row']) && isset($_GET['quantity'])) {
if($_GET['quantity'] != 0) {
$num = $_GET['quantity'];
$_SESSION['basket'][$_GET['row']]['barcode']['quantity'] = $num;
} else {
unset($_SESSION['basket'][$_GET['row']]);
}
}
?>
I save the file in works once and then it stops changing the quantity.
When echoing the variable in the code in shows that it's changed but in the rest of the site it doesn't. the part where it shows doesn't manipulate the variables only prints them.
It seems as if the code works only if the file's been saved and only for the first time.
Thanks in advance.

joomla pagination not working properly

function display($cachable = false, $urlparams = false){
$lim0 = 0;
$lim = 10;
$db =& JFactory::getDBO();
$db->setQuery('SELECT name,email,id,profile_value from y0sov_users,y0sov_user_profiles where y0sov_users.id=y0sov_user_profiles.user_id and profile_key="profile.department" LIMIT 0,10');
$rL=&$db->loadAssocList();
if (empty($rL)) {
$jAp->enqueueMessage($db->getErrorMsg(),'error'); return;
}
else
{
$db->setQuery('SELECT FOUND_ROWS();');
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
foreach($rL as $r) {
echo '<div id="values">';
echo '<ul>';
echo '<li>'.$r.'</li>';
echo '</div>';
}
echo $pageNav->getListFooter();
}
}
}
?>
The values are not displaying. I am new to Joomla so pardon me if I am missing something really fundamental.
nice try!
This is not the way to do it in joomla.
You do not need to create the ul li structure.
The echo $pageNav->getListFooter(); does it for you.
I assume that the code above belongs to a component.
Place the echo $pageNav->getListFooter();
part inside the appropriate file in the tmpl folder of the view. As far I can see in your code, you only use the view.html.php file?
This is not completely wrong, but you do not use joomla standards and you may face problems on cases such as creating menu items of such a type.
Usually we create the pagination object in the model and we just get it in the view.html.php file. Finally, we echo $pageNav->getListFooter(); in the appropriate file in tmpl.
This tutorial is quite good & easy:
http://www.tutsforu.com/pagination-in-joomla-component.html

How to make a php variable $_POST upon clicking it?

I'm trying to make $suggestion[$ss_count] become a clickable link that does a $_POST once it is clicked. I'm trying to achieve a query expansion sort of an effect. The word itself of course needs to be the information posted and it needs to be recognized as
if ($_POST['query'])
The code I use for this is:
<?php
if ($_POST['query'])
{
$query = urlencode($_POST['query']);
$s_count = 0;
$ss_count = 0;
$query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'? key=135a6187-af83-4e85-85c1-1a28db11d5da';
$xml = new SimpleXMLIterator(file_get_contents($query));
foreach ($xml -> suggestion as $suggestion[$s_count])
{
$s_count++;
}
if ($s_count > 1)
{
echo ('<h4>Did you mean?</h4>');
while ($ss_count <=$s_count)
{
echo ($suggestion[$ss_count].'<br>');
$ss_count++;
}
}
}
?>

How to convert Meters to Foot using PHP

I have used this code which shows an error:ie if my meters is 175m but when i convert it does'nt show that thing
<?php
function metersToFeetInches($meters, $echo = true)
{
$m = $meters;
$valInFeet = $m*3.2808399;
$valFeet = (int)$valInFeet;
$valInches = round(($valInFeet-$valFeet)*12);
$data = $valFeet."′".$valInches."″";
if($echo == true)
{
echo $data;
} else {
return $data;
}
}
?>
<?php
$feetInches = metersToFeetInches(1.75,false);
echo $feetInches;
?>
This is one of those things you can easily find on Google, but I guess you didn't look further than the first link.
Anyways, you should do it like this.
<?php
function metersToFeet($meters) {
return floatval($meters) * 3.2808399;
}
?>
But why is this better than the code you posted? Well, functions are not supposed to do everything. You should write a function for a certain action, not one big function with everything you can every need. Because if you need to add something to that function or change the order of actions, it's a hell of a lot of work.
Furthermore, your function has an option $echo. But why would you need that? You can add such an option to every function, but PHP has a nice commando for that: echo. So instead, it's way better to write echo metersToFeet(10). Or $value = metersToFeet(10) if you need to save the result in a variable.
<?php
function metersToFeetInches($meters, $echo = true)
{
$m = $meters;
$valInFeet = $m*3.2808399;
$valFeet = (int)$valInFeet;
$valInches = round(($valInFeet-$valFeet)*12);
$data = $valFeet."′".$valInches."″";
if($echo == true)
{
echo $data;
} else {
return $data;
}
}
?>

How to implement this image preloader into my php file?

I want to have my images which are processed via ajax to be preloaded visually rather then the usual loading of images where you see them build up from top to bottom. Please take a look here. What you see there is what I want to have in my php file visually.
The part where the pictures are loaded from the database are the following:
$sql = "SELECT * FROM `fabric`".$filter;
$result=mysql_query("$sql");
//echo $sql;
$data = "";
$ii = 0;
$m = 0;
while($myrow = mysql_fetch_array($result)){
$ii++;
$m++;
if ($m == 1) $data = $data."<div class=\"page current\">";
elseif ($ii == 1) $data = $data."<div class=\"page\">";
$data = $data."<img src=\"".$image_directory.$myrow['thumbnail']."\" width=\"100 px\" height=\"100 px\"><div class=\"fb_name\">".$myrow['name']."</div>\n";
if ($ii == 10) {
$data = $data."</div>";
$ii = 0;
}
}
if ($ii != 10) {
$data = $data."</div>";
}
if (empty($data)) echo "No result";
else echo $data;
?>
I really don't know how to change the php in order to have the effect shown in the demo.
Thank you for all constructive advices and forgive my noobiness :)
You will need javascript for this, you can´t do it in php alone. The basic idea is to hide your images using for example a visibility: hidden and have them fade in when they are completely loaded. And at load-time you position a loading image on top that you remove when you start fading in the image.
As the example you've given, is a plugin, perhaps you can even use that one instead of writing it yourself.

Categories