Pass php variable though open.window - php

I'm pretty new to javascript so please excuse this question if it seems pretty nooby. I am writing an online calendar to book engineer's jobs so we need to be able to look at the calendar whilst looking at and editing individual jobs. After much deliberation I decided the best way to do this is by opening the jobs in a new window using window.open. However, I would like to pass the job id via the url in order to pass it to the new window but for love nor money I can't work it out or find a solution. Here is my code so far
function open_win()
{
window.open('job_detail.php', '_blank','toolbar=0,location=no,menubar=0,height=400,width=400,left=200, top=300');
}
<a href="#" onclick="open_win()" ><? echo $row['name']; ?></a>
The $row['name'] is the value of the link and the value I want to pass will be held in $row['id'] or $job_id. I just can't work out where to put it so it passes on.
Any help will be greatly appreciated

As a parameter?
function open_win(id) {
window.open('job_detail.php?id=' + id, '_blank','toolbar=0,location=no,menubar=0,height=400,width=400,left=200, top=300');
}
<? echo $row['name']; ?>

Related

Automatically add id of current page to href

I have a link below as it is found in a particular WordPress plugin:
<a href='".home_url("?p=7&action=get_marks&id=$select_data2->id")."' ></a>
I want to auto detect page_id when I click on it to reload the same page, like:
<a href='".home_url("?p=get_id&action=get_marks&id=$select_data2->id")."'></a>
I don't want to write page id every time I create new page after putting shortcode in.
I'm assuming you are talking about server side
echo ' '
where $id is a variable that has the id
Have you considered JavaScript on the client side?
thanks for your help
i tried several method until i found the solution
here the code
global $post;
echo '<a href='".home_url("?p=$post->ID&action=get_marks&id=$select_data2->id")."'>';
where $post->ID is a variable that has the page id
thanks #user74670 you give me inspiration to solve problem

angularjs ng-click or ng-init? php variables

I'm new in angularjs and after looking in every site and forum without answer, somebody can help me to selve this?
i have this html with php code, and i want to pass php var into angularjs event.
<a ng-init="changeCat=<?php echo $id_cat, $category; ?>" id="cat_<?php echo $id_cat; ?>" class="cat-list" href="#"><?php echo $category->name; ?></a>
thanks in advance!
assuming you have a method changeCat() you can pass it php variables using something like ng-init="changeCat(<?php echo $id_cat; ?>)". I am assuming you want ng-int at this point but it should give you enough to get going with.
also try searching 'pass php to ng' or 'pass php variable to angular controller'... results should be similar.
EDIT:
As #Kevin B said you may want to change the way you are doing things but that said.
If you are to use more that one variabel then have a look at this:
Laravel/Angular: passing data within php page to angularjs

Make variables available inside of a function.(PHP)

Im building an application to track certain information about the clients we deal with like name/date/hrs worked/phone number etc. This information is stored in a db. Because we have different departments like SEO/WEB/Sales etc, and different people within these teams, the app provides different ways to filter the information depending on the filter button pressed.
When someone presses a "filter button", in this example, lets say they pressed the "view by department" button, it takes them to actual hardcoded pages.
As an example:
viewSeoAccs.php
viewWebAccs.php
ViewSalesAccs.php
And in these pages i have queries which pull the information based on the filter pressed but the html is the same. Now here comes the problem.
I have many different pages(based on filters) and every time there is an edit to be made to the html, i have to go into EVERY PHP page to implement the changes.
What i want to do is create a function that spits out the html for me. I have gotten about half way and i know the problem, just cant seem to find a solution.
Here is some code.
In my functions.php file, i have a function called "htmlBlockTEST" that has this code.
EXAMPLE: (code chopped for easy reading)
<?php
function htmlBlockTEST(){
echo '' ?>
<h2 class="accName fl"><?php echo $row['company_name']; ?></h2>
<div class="<?php echo $row['acc_risk']; ?>"> Risk Level. </div>
//ALOT MORE CODE goes here lol.
<?php
}
?>
This is in the header and bought in via "include_once('functions.php').
Under this, i have specific variables that pull in the queried data. (example below)
$pullAllAccounts = "SELECT * FROM tlm_accounts ORDER BY company_name ASC;";
$pullAllAccountsDoIt = mysqli_query($c2d, $pullAllAccounts) or die ("could not pull WEB team data" . mysqli_error($c2d));
?>
now i loop through the db and display the information like so:
<?php
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
$compName = $row['company_name'];
?>
<?php htmlBlockTEST(); ?>
<?php
}
?>
In this code directly above, where the function call "htmlBlockTEST" is, is where the problem is. Since The variables which hold the queries are outside the function, I'm assuming that they aren't being passed into the function. I dont want to put them inside the function because the HTML is the same throughout all the pages, but not ALL data.
I need the variables that hold for example $row['company_name'] to be also available inside the function so that it doesn't throw "undefined variable" errors.
How can i make this happen? What is the best way to get these variables in the while loop(or otherwise) to be available inside the function???
PS, ive google and found things like $GLOBALS['x'] etc but from what ive read, its not the best way or easiers and overall im confused on how to even use it.
Any help is greatly appreciated.
Thanks in advanced.
Option 1:
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
htmlBlockTEST($row);
}
Option 2:
global $row;
while($row = mysqli_fetch_array($pullAllAccountsDoIt)){
$compName = $row['company_name'];
htmlBlockTEST();
}
//and in your htmlBlockTEST() function just right this:
function htmlBlockTEST(){
global $row; ?>
<h2 class="accName fl"><?php echo $row['company_name']; ?></h2>
<div class="<?php echo $row['acc_risk']; ?>"> Risk Level. </div>
<?php
//ALOT MORE CODE goes here lol.
}
?>
You have some more options of course.

How to create a dynamic link?

I'm trying to create a link that takes the user to two different pages depending is the user logged or not. Problem is I'm still new to programming and this is quite big bite for beginner like me but its something I have to do. I created something like this so far but either way I suck at searching or there just isnt specific information for what I need
<?php if($userLogged){
echo '<a href="index.php" class="stylelink">';
}
else
{
echo '<a href="index1.php" class="stylelink">';
}
echo "Etusivu</a>";
?>
I'm also using Dreamweaver's login function that creates the MM_Username session and such, and Im not sure how to make the condition. userLogged is still an empty variable. Id appreciate any advice.
Thanks
-John
well, instead of using echo statements in the php tag you can write html and use php for outputting the value of the page like this
Etusivu
The $_SESSION['MM_Username'] works if you have included session_start(); at the beginning of the page and you can use the condition as above instead of $userLogged.

Returning multiple results from mysql to separate jQuery modals

I am creating a PHP search page that searches a MySQL database and returns results into separate jQuery modals.
Goal: When a user searches a term, the results found for ClassName are displayed from the database via separate links (these links being scripted to open jQuery modals) and once a link is clicked the modal opens displaying the rest of the information related to that ClassName in said database.
What Is Working: The different ClassName(s) are displayed properly as separate links.
What Is Not Working: No matter what ClassName link you click on, once the modal opens, it only displays the information relating to the very first ClassName result in the database.
Any help correcting this error is greatly appreciated.
The only rows in the database I am using for results are: ClassName, ClassInformation, and imagePath.
PHP Select Statement:
<?php
$raw_results = mysql_query(
"SELECT * FROM classes
WHERE (`ClassName` LIKE '%".$query."%') OR
(`ClassInformation` LIKE '%".$query."%')"
) or die(mysql_error());
?>
Link:
echo "<a href=".$results['ClassName']
. " data-reveal-id='myModal'><h2>"
. $results['ClassName']
. "</h2></a>";
Modal:
echo "<div id='myModal' class='reveal-modal'
style='background-image: url(ResultBackground.png);
border: 1px solid black;'><h2>".$results['ClassName']."</h2>
<div id='image'>".$results['imagePath']."</div></br >
<h3>".$results['ClassInformation']."</h3>
<a class='close-reveal-modal'>×</a></div>";
I apologize for the code not formatting correctly I don't really understand how to use the code blocks on this site yet. But thank you for any and all help offered.
A similar question was asked by someone 2 months ago here related question but the way his code was written threw me off completely as I'm new to PHP and only know the messy way I've taught myself from online tutorials. I attempted to format the code similar to the way suggested by the person who answered the linked question but I just keep breaking my code.
$i=0;
while($row=mysql_fetch_array($raw_results)){
echo "<a href=".$results['ClassName']. " data-reveal-id='myModal_".$i."'><h2>".$results['ClassName']. "</h2></a>";
echo "<div id='myModal_".$i."' class='reveal-modal'>......restcode";
$i++;
}
You have to use unique ids fro each link .here you have used same data-reveal-id="myModal" for every link,and every modal div has same id "myModal". So when you click on any link,it checks for first element with id 'myModal' and displays it .
Use different data-reveal-ids for each link and give the same id to the corresponding modal divs

Categories