Forum Moderators: coopster
Here is the code:
Could someone please tell me why I'm getting "unexpected $end in line ****?
<?php
$table_name='orinth';
$dbh=mysql_connect ("localhost", "****_joetest", "****") or die ('Cannot connect to Database - error: ' . mysql_error () );
mysql_select_db("stegenga_joetest1",$dbh);function make_table_start() {
$content = '<table border="2" cellpadding="0" cellspacing="0" width="540px">';
return $content;
}
function make_table_end() {
$content = '</table>';
return $content;
}
function make_fill_table() {
$sql = $sql = 'SELECT * '
. ' FROM ornith'
. ' WHERE subclass = "audubon"';
$result = mysql_query($sql);
if (!$result) {
print mysql_error() . "ERROR - query failed";
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$content .='<tr>'."\n";
$content .='<td align="center">'."\n";
$content .='<a href="javascript:popImage(\'images/'. $row[picname] . ',' . $tablename . ' '. $row[picname].'\')">'."\n";
$content .='<img src="images/' .$row[thumbname].'" alt="$row[thumbname]"></a></td>';
$content .='<td align="left" style="padding-left:5px">' .$row[itemdesc] . '</td>';
$content .='<td align="left">' .$row[item_qual] . '</td>';
$content .='<td align="center">' .$row[item_height] . '" x "' .$row[item_width] . '</td>';
$content .='<td align="right">'.$row[itemprice] . '</td>';
if ($row[itemstatus]=="1") {$content .='<td align="center">YES</td></tr>';}
else {$content .='<td align="center">HELD</td></tr>';}
return $content;
}
}
print make_table_start();
print make_fill_table();
print make_table_end();
?>
the error line is right at/after?>
HELP
The syntax highligher in PHPedit does not show any syntax problem....
John
$content .= <<<END
Put anything you want here, don't worry about quotation marks.
Use curly brace {$variables} to avoid ambiguity.
END;
//(note: nothing comes after END; not even spaces)
Also,
'" alt="$row[thumbname]"></a></td>'
rob
SO, i define yes/no with a test BEFORE constructing the string within the while loop?
Yes, assign whatever text you wish to appear to an intermediate variable BEFORE you use "<<<" and within the loop.
It looks like you want the variable to be "YES" or "HOLD". Then just substitute it in at the appropriate place. I'm not sure why you said "yes/no" when your code says "YES/HOLD". Just to be clear, I'm talking exlcusively about string variables (not boolean).
You had
......a whole bunch of code here.....
if ($row[itemstatus]=="1") {$content .='<td align="center">YES</td></tr>';}
else {$content .='<td align="center">HELD</td></tr>';}
I'm suggesting:
if ($row[itemstatus]=="1") {$x="YES"}
else {$x="HELD"}$content .= <<<END
......a whole bunch of code here.....
<td align="center">{$x}</td></tr>
END;
I suggest you look at php.net's help on strings (search for "heredoc"). I know more about PHP than I do with CSS or JavaScript, which you've got. I can tell you *how* to substitute a string into another string, but not *what* to substitute.
can i set 2 variables within the context of the if? And would $style be a valid variable in PHP?
I don't know what all the reserved words are in PHP. I haven't heard of "style" being reserved. So, I think it's ok to use. You'll find out when you run it :)
a question for you -
once I've built this array, how do I have buttons, etc, access items in it? For example, how would I build a button in the table row that updated the $row[itemstatus]? How does the program know/remember what is what?
John
but now something in the html construct is not working... i need more coffee.. .if anyone see's what I've screwed up, kindly tell me!
EDIT: Damn quotation mark... now it's working. Need to write my styles and my header-row. Thanks!
John
PS - still have that other question:
how to do a button that will update the status of a field (i.e. a "buy" button)....
John
[edited by: Bigjohn at 1:42 pm (utc) on Feb. 18, 2004]
[edited by: jatar_k at 5:54 pm (utc) on Feb. 18, 2004]
[edit reason] delinked [/edit]