Simple code to open window and print some info from dbase
Moderator: General Moderators
Hey Roja,
Thanks for your comments. But perhaps you have not read me previous mail.
Sure, always willing to learn, but in my situation it is a bit hard, as I wrote, I am leaving on a 8 year trip in two months, tons of things to do, and leaning a programming language is very timeconsuming. And al that for perhaps 4 lines of code which I need.
Anyway, your friendly words upt me to try once more.
Can you please give me some constructive help? Comments ment for ´real´ programmers are not what i am looking for.
Ok, I have this lines :
echo '<td class="border" style="font-size:9px;">'.$row[opmerking].'</td>';
echo '<a href="#" onclick="window.open('simpleRoutine.php?thisRecord='.$row['id'].'>','window name'); return false">Go!</a> </td> ;
(line 115 and 116)
its the line 116 which was the advise from here and gives the error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in ..../public_html/nuke/modules/waarbenik/index.php on line 116
I have trie all possibilites of quotes and /` but I probably forgot one haha
What do you think? If you need more info, just let me know
thanks
Casper
Thanks for your comments. But perhaps you have not read me previous mail.
Sure, always willing to learn, but in my situation it is a bit hard, as I wrote, I am leaving on a 8 year trip in two months, tons of things to do, and leaning a programming language is very timeconsuming. And al that for perhaps 4 lines of code which I need.
Anyway, your friendly words upt me to try once more.
Can you please give me some constructive help? Comments ment for ´real´ programmers are not what i am looking for.
Ok, I have this lines :
echo '<td class="border" style="font-size:9px;">'.$row[opmerking].'</td>';
echo '<a href="#" onclick="window.open('simpleRoutine.php?thisRecord='.$row['id'].'>','window name'); return false">Go!</a> </td> ;
(line 115 and 116)
its the line 116 which was the advise from here and gives the error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in ..../public_html/nuke/modules/waarbenik/index.php on line 116
I have trie all possibilites of quotes and /` but I probably forgot one haha
What do you think? If you need more info, just let me know
thanks
Casper
I'd be surprised if that was the code... Anyway, with a decent editor, the errors becomes clear quite easily... I'll leave it to you to spot it :p (btw, notice that i change something in line 115 too)ctjansen wrote: echo '<td class="border" style="font-size:9px;">'.$row[opmerking].'</td>';
echo '<a href="#" onclick="window.open('simpleRoutine.php?thisRecord='.$row['id'].'>','window name'); return false">Go!</a> </td> ;
Since you have string between single quotes ' ' all the single quotes in there have to be escaped, \'
Code: Select all
echo '<td class="border" style="font-size:9px;">'. $row['opmerking'] .'</td>';
echo '<a href="#" onclick="window.open(\'simpleRoutine.php?thisRecord='.$row['id'].'\',\'window name\'); return false">Go!</a> </td>';Well, I have partially solved the problem myself, just one question left.
(the link has changed to this by the way)
http://ctjansen.nl/nuke/modules.php?name=waarwasik
what i am now doing is calling another php program. in the url with the link, i am passing the variables to the new program like this:
echo "<td class='border' style='font-size:11px;'><a href=http://www.ctjansen.nl/xxx/waarbenik/ma ... beg_plaats]." > meer info ";
now in this new program map.php : how do i put the send varaibles (datum and beg_plaats) in a variable so the program can open a new popup window and echo the contents of the variable to this wiindow?
Casper
(the link has changed to this by the way)
http://ctjansen.nl/nuke/modules.php?name=waarwasik
what i am now doing is calling another php program. in the url with the link, i am passing the variables to the new program like this:
echo "<td class='border' style='font-size:11px;'><a href=http://www.ctjansen.nl/xxx/waarbenik/ma ... beg_plaats]." > meer info ";
now in this new program map.php : how do i put the send varaibles (datum and beg_plaats) in a variable so the program can open a new popup window and echo the contents of the variable to this wiindow?
Casper
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
feyd | Please use
Then I set up the table, also no problem:
Then i start printing the table:
NOW, after this last line, i need a button , when clicked, the user gets a popup wit some more information from this same dbase. I cannot use javascript, because i am inside a php loop. Can somebody give me a working example... PLEASE
Casper
ps, the link where you can see what it looks like up to now you can find in the first message
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok. let me be a little more specific, here is what i have so far:
I connect to MYSQL, then read the whole logbook , so far no problem:Code: Select all
$query = "SELECT * FROM log_new ORDER BY datum DESC, beg_km DESC ";
$result = mysql_query($query);
?>Code: Select all
<table style="text-align:center; empty-cells:show; border-collapse: collapse; width: 100%;">
<tr>
<td style="background-color: transparent; text-align:center; padding:0px 0px 0px 0px; ">
<TABLE bgcolor="lightgrey" border="2" width="100%">
<th class="border">Datum</th>
<th class="border">Land</th>
<th class="border">Plaats</th>
<th class="border">Weer</th>
<th class="border" >Km gereden</th>
<th class="border" colspan="2">Mijn positie</th>
<th class="border" >Opmerking</th>
<th class="border" >meer</th>
</tr>
<?php
while ($row=mysql_fetch_array($result))
{
$breedte_deg = $row[end_b_deg];
$breedte_deg += 0;
$breedte_deg = round($end_b_deg);
$breedte_min = $row[end_b_min];
$breedte_min += 0;
$breedte_min = round($end_b_min);
$breedte_sec = $row[end_b_sec];
$breedte_sec += 0;
$breedte_sec = round($end_b_sec);
$lengte_deg = $row[end_l_deg];
$lengte_deg += 0;
$lengte_deg = round($end_l_deg);
$lengte_min = $row[end_l_min];
$lengte_min += 0;
$lengte_min = round($end_l_min);
$lengte_sec = $row[end_l_sec];
$lengte_sec += 0;
$lengte_sec = round($end_l_sec);Code: Select all
/*echo '<tr>';*/
$km = $row[end_km] - $row[beg_km];
$date = Dateconvert($row[datum],2);
echo '<td class="border" style="font-size:11px;">'.$date.'</td>';
echo '<td class="border" style="font-size:11px;">'.$row[land].'</td>';
echo '<td class="border" style="font-size:11px;">'.$row[end_plaats].'</td>';
echo '<td class="border" style="font-size:9px;">'.$row[end_weer].'</td>';
/*echo '<td class="border" style="font-size:11px;">'.$row[end_temp].'ºC</td>';*/
echo '<td class="border" style="font-size:11px;">'.$km.'</td>';
echo "<td class='border' style='font-size:11px;'><a href=http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=latlong&latlongtype=degrees&latdeg=".$breedte_deg."&latmin=".$breedte_min."&latsec=".$breedte_sec."&longdeg=".$lengte_deg."&longmin=".$lengte_min."&longsec=".$lengte_sec."&zoom=2 target=_blank>".$row[N_S]." ".$row[breedte_deg]."º ".$row[breedte_min]."' ";
echo $row[breedte_sec].'"</a></td>';
echo "<td class='border' style='font-size:11px;'><a href=http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=latlong&latlongtype=degrees&latdeg=".$breedte_deg."&latmin=".$breedte_min."&latsec=".$breedte_sec."&longdeg=".$lengte_deg."&longmin=".$lengte_min."&longsec=".$lengte_sec."&zoom=2 target=_blank>".$row[E_W]." ".$row[lengte_deg]."º ".$row[lengte_min]."' ";
echo $row[lengte_sec].'"</a></td>';
echo '<td class="border" style="font-size:9px;">'.$row[omschr_dag].'</td>';Casper
ps, the link where you can see what it looks like up to now you can find in the first message
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
First of all, every array index you reference in that php code is missing quotes
PHP runs on the server, when you request a PHP page by its URL the PHP is excuted and only what the PHP script echos reaches the browser. The result contains no PHP, and as far as the browser is concerned no loop ever occured. You can include JavaScript into your page by leaving PHP mode ( ?> ) and that JavaScript will also hit the browser.
Anyway I don't think we should use JavaScript here because that would involve AJAX and that's too complex for a forum reply.
SOOOoooo its time for another PHP script.
I'm using this imaginary database structure for this, sorry for any mistakes:
because I cannot possibly hope to apply this correctly to your project.
artists.php (the summary file)
paintingsByArtist.php (the detail file)
btw be warned, I literaterally wrote this as fast as I could type.
Hope that helps
Code: Select all
$array = array('foo'=>1,'bar'=>2);
echo $array[foo]; // E_WARNING level error, PHP is kind enough to assume you mean the line below
echo $array['foo']; // no error
// you cannot rely on PHP's handling here, so please quote all your array indicesOK.NOW, after this last line, i need a button , when clicked, the user gets a popup wit some more information from this same dbase.
I don't think you understand how PHP works.I cannot use javascript, because i am inside a php loop.
PHP runs on the server, when you request a PHP page by its URL the PHP is excuted and only what the PHP script echos reaches the browser. The result contains no PHP, and as far as the browser is concerned no loop ever occured. You can include JavaScript into your page by leaving PHP mode ( ?> ) and that JavaScript will also hit the browser.
Anyway I don't think we should use JavaScript here because that would involve AJAX and that's too complex for a forum reply.
SOOOoooo its time for another PHP script.
Yes I think I can. What I am going to do is to get your first PHP file (that presumably displays a summary of all the records from a query) to contain a link (easier than a button) to another PHP file that will get more extended information. So do this the first page has to pass over some information to the second detailing what is being requested. This information will normally be some kind of unique identifier orginating from the database.Can somebody give me a working example... PLEASE
I'm using this imaginary database structure for this, sorry for any mistakes:
Code: Select all
CREATE TABLE artist (
ar_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ar_id),
name VARCHAR(255) NOT NULL,
INDEX(name),
born DATE NOT NULL,
died DATE NULL
);
CREATE TABLE painting (
pa_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(pa_id),
artist_id INT UNSIGNED NOT NULL,
FOREIGN KEY (artist_id) REFERENCES artist(ar_id),
title VARCHAR(255) NOT NULL,
paint ENUM('watercolor','oil','acyrilic','other') DEFAULT 'other'
);artists.php (the summary file)
Code: Select all
<?php
$q = 'SELECT * FROM artist';
$result = mysql_query($q);
if($result === false) exit('Query error');
?>
<table id="artists">
<tr>
<th>name</th>
<th>born</th>
<th>died</th>
<th>more</th>
</tr>
<?
while($row = mysql_fetch_assoc($result)) {
echo '<tr>';
// \/ \/ NOT SECURE!!! \/ \/ just an example
echo '<td>'.$row['name'].'</td><td>'.$row['born'].'</td><td>'.$row['died'].'</td>';
// URL constructed using ar_id \/ \/
echo '<td><a href="paintingsByArtist.php?ar_id='.$row['ar_id'].'">View paintings</a>';
echo '</tr>';
}
echo '</table>';
?>Code: Select all
if(!isset($_GET['ar_id'])) exit('ar_id unspecified');
$ar_id = (int)$_GET['ar_id'];
if($ar_id == 0) exit('ar_id invalid');
$q = 'SELECT * FROM painting WHERE artist_id = '.$ar_id;
$result = mysql_query($q);
if($result === false) exit('Query error');
?>
<table id="paintings">
<tr>
<th>title</th>
<th>paint</th>
</tr>
<?
while($row = mysql_fetch_assoc($result)) {
echo '<tr>';
// \/ \/ NOT SECURE!!! \/ \/ just an example
echo '<td>'.$row['title'].'</td><td>'.$row['paint'].'</td>';
echo '</tr>';
}
echo '</table>';Hope that helps