2

Sorry guys but this is a little broad, I've searched but there are a few things coming up but I wanted a direct answer for my question.

First I am a mechanic at a truck dealership in Dallas, TX. I am writing a web based application that will make it easier for me to organize all my jobs. I'm using this project to teach myself HTML, PHP, PDO, javascript ect. Right now I'm in design and organization phase meaning I'm getting everything I want figured out so when I start the hard coding I know ahead of time where to go.

Now when a tech logs in they will be brought to the tech landing page. I'm going to have a php script that will retrieve all the 20 most recent "active" Ro's (repair orders) assigned to that particular tech. A table will display summary info on a line at the end of each line there will be a button (or I might make the RO # clickable not sure yet.

My question is what is the best way to open a new window and pass the RO# of the clicked option so scripts on the new page can begin populating the detailed RO information from the database??

I'm not necessarily looking for the code but something I can search to narrow down my options.

Thanks

Dwayne B
  • 107
  • 1
  • 13

5 Answers5

1

There are a few ways you could do this.

A simple link with querystring:
-------------------------------
<a href='/repairs.php?mechanic=bob' target='_blank'>Bob's Repair Orders</a>
<a href='/repairs.php?mechanic=curly' target='_blank'>Curly's Repair Orders</a>

A simple link with a javascript function:
-----------------------------------------
<a href='#' onclick='getRepairs('bob')'>Bob's Repair Orders</a>
<a href='#' onclick='getRepairs('curly')'>Bob's Repair Orders</a>

javascript:
function getRepairs(name){
    window.open('/repairs.php?mechanic='+name );
}
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

You can call the following in JavaScript:

window.open("<yourUrl to open>?ro=someValue")

and pass the ro value to the new window as a query paramter (?ro=someValue where someValue will be replaced by the value to pass over and is the url of the page to load in the new window).

In the new window you can retrieve it using:

function getParameterByName(name) {
   name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
   var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
      results = regex.exec(location.search);
   return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var ro = getParameterByName('ro')

Note: getParameterByName is from How can I get query string values in JavaScript?

Community
  • 1
  • 1
Denis Thomas
  • 1,012
  • 1
  • 8
  • 17
0

Like what Uchiha comment is suggesting, you can put your RO# into a link.

In your html you can put something like this:

<a target="_blank" href="ro_table.php?ro_number=RO number here"> RO# </a>

and in your ro_table.php or any php file you prefer to receive the RO# you can get the RO# by: $_GET["ro_number"] and use that to your database query.

VMcreator
  • 833
  • 8
  • 17
0

Use a GET parameter : index.php?ro_id=1

Now this URL should be generated through PHP, where 1 is a variable and is the RO#.

Other solutions told how to open it in a new window, you don't need JS to read $_GET though.

Steve Chamaillard
  • 2,289
  • 17
  • 32
0

You have 2 options to do this:

  1. (Recommended) Pass RO# (id) in address page.php?id=1001 and fetch id using get method on new page. It will be a full page with all bars and every thing enabled.
  2. Collect data in a DIV and open a new page and populate data to it.

Code for Option 1:

Page 1: ROlist.php (Which Contains list of 20 ROs)

<a href="ROdetails.php?id=1001" target="_blank"> RO#1001</a>

Page 2: ROdetails.php (Which will open only id based details)

<?php
$ROid=$_GET['id'];
$result=mysql_query("SELECT * FROM table where id='$ROid'");
if($result)
{
while($list=mysql_fetch_array($result))
{
echo $list['Id'];
echo $list['clientName'];
echo $list['foo'];
echo $list['bar'];
}}
?>
SJSSoft
  • 723
  • 2
  • 10
  • 28