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 have a language system written in PHP. It loads phrases from the database to the array and then displays some of them during the page render. Right now it looks simple:
<h1><?=$phrase['phrase_callsign']?></h1>
What I need is to know, what particular keys was used during the page rendering procedure.
I have a special function to count and log phrases, so code looks like this:
<h1><?=$this->model->phrase('phrase_callsign')?></h1>
What I'm asking for, is there are something already built in in PHP instead of the handwritten function to display array keys used? Personally I haven't found anything yet.
Thanks.
If I understand correctly you want to record the keys you are using to retrieve callsigns from the array. I would just define a regular function where you pass in the callsign. It adds it to another array, logs it, and then return the callsign value.
function getCallsign($callsign) {
// log callsign
array_push($callsigns, $callsign);
return $phrase[$callsign];
}
If you want to make a list of all the callsigns that were displayed, just push them onto a variable:
<h1><?php $all_callsigns[] = $phrase['phrase_callsign']; echo $phrase['phrase_callsign']; ?></h1>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm studying someone else's code in order to learn php,html and something I don't understand is this:
if (isset($this->request->post['eid'])) {
$eid = $this->request->post['eid'];
} else {
$eid = '0';
}
How exaclty is the value of the field eid passed to the php file that just opened and how can I use this mechanism to pass values to other files? And secondary..what is different when get is used instead of post at the same statement?
The -> arrow operator is used to get variables and functions that belong to an object.
In this case, $this is an object and you're getting the varible request from that object. That variable contains another object which has a variable post. That variable is an array and you're getting the value with index "eid" from that array using post['eid'].
$this->request->post['eid'] is same as $_POST["eid"] in simple words.
$this->request->post['eid'] is used in the frameworks. $_POST is the array of values which you get on form submission.
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
How can I see the Edit Mode page is the link is written like:
<small><i>Edit Mode</i></small>
In the above case, if I click the Edit Mode button in the homepage, does it mean editz will be assigned a value as 1?
Another question is if I have three php files a.php, b.php and c.php, which all check isset($editz), how can I redirect the page to a.php, rather than file b or c if I click the Edit Mode button?
Sorry maybe my question is too simple a naive, but I am a newbie to php, it is my first time tough php code. Please be kind to share some light:)
Just to give some sort of answer to this, spanning from the comments:
Anything following a ? in a URL is a query string, and the parameters (each separated by &) can be accessed with the $_GET['parameter_name'] function. In this case, $_GET['editz'] was needed.
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
At the moment, I'm working on a small script.
I'm new at PHP, I've got a problem
I have a field in database and the field content is like this
"1","2","3"
When i put these numbers in array
like this
$users=array("1","2","3");
, my code will work , but when i put these codes in a variable and put variable inside the array like this
$users=array($amanj);
it wont.
Please Help me if possible.
Thanks very much.
It sounds like you need to redesign your database because having "1","2","3" is not a good idea if you really need 3 separate values.
But to answer your question, if you need to convert the string "1","2","3" to an array, you can do:
$users = explode(',', $amanj);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am working in codeigniter php. I want to search from database when it match some or one keywords.
But i don't know how to do it. When it match some keywords in database, in user panel it show some keyword related content.
Can anyone tell me how to do it ?
Here: http://goo.gl/yvwKi3
First 3 results tell you how to do it with full source code.
1) input field
2) onkeyup event
3) XMLHttpRequest
4) param "searchkey"
4) php script
5) db connection
6) query "SELECT * FROM table WHERE textfield LIKE '%".$searchkey."%'"
and the whole way back again...
You can use the Jquery "post()" method to post your search input to a php file which in turn runs a mysql query to look for the data in the database.
The php file should "echo" the results back in json format. Use "json_encode()" function for this.
Back in the jquery post() function, parse the json result and display it to the user.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a database of store names, and I want to make it possible that each store has its own personal page.
Would I have to make a separate page for each store or is there a way to have a single page that works as a template that when the user clicks on the store name the information just changes according to the store name.
If so could someone please set me in the right direction.
Thank you very much.
Yes, its possible to do this:
<?php
$store = 'abc'; // here make $store equal the store name out from the database
echo "Welcome to ".$store."'s store!";
?>
You could include further items, or even have images from the stores folder by using the $store variable as well. For example, to show the logo you could do the following:
<?php
echo "<img src=\"http://www.domain.com/".$store."/logo.jpg\">";
?>
At the end of the day, it depends how complex you want it. But as others will say, you'd better learn some of PHP's functionality and database features so you can get the result that you need.