"Cato Larsen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Just to have said it... Im green in both PHP4 and MySQL.
> Can anyone say what I've been doing wrong here, and how to fix it, or even
> better. Debug the whole shit! =)
First, make sure PHP is actually running.
Try this:
<?php
$str = "PHP is not running!";
echo substr($str, 0, 7) . substr($str, 11);
?>
For one thing, trying to echo unescaped double-quotes
won't work, ie
echo "<table leftmargin = "0">"; // no good!
Use ' or \" instead.
Second, all this variable-renaming seems like a waste
of effort; just use the array directly.
> $cid = mysql_connect($host,$usr,$pwd);
> if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
If the connection fails, your script prints an
error message, then continues trying to query...
if (!$cid) {
echo "Error: ".mysql_error();
exit;
}
... or redirect them back to a different page.
> # setup SQL statement
> $SQL = " SELECT * FROM memberinfo ";
> $SQL = $SQL . " WHERE prof = '$prof' ";
$sql = "SELECT * FROM memberingo "
."WHERE prof='$prof' ";
> echo ("<P><DT><B>Members who are $prof s</B><BR>\n");
<dt> should only occur in <dl>...</dl>
> $apperiance = $row["apperiance"];
'appearance'
> $prof = $row["prof"];
? you already know prof; why query for it?
First thing to do is write a couple of
functions to take care of the formatting
for you:
// Generic tag-formatting routine
// Ensures all tags are closed properly;
// Also forces you to think about tag-clause formatting
// so the final result is readable.
function clause($preopen, $tag, $opts, $pretext, $text, $preclose) {
return "$preopen<$tag $opts>$pretext$text$preclose</$tag>";
}
function table($contents) {
return clause("\n", "table", "style='margin-left: 80px;'>", "",
$contents, "\n");
}
function row($contents) {
return clause("\n\t", "tr", "style='margin-top: 30px;'", "",
$contents, "\n\t");
}
function cell($text, $width=0) {
if ($text == "") // check for empty str
$text = " ";
$opts = ($width > 0 ? "style='width: $widthpx;'" : "");
return clause("\n\t\t", "td", $opts, "", $text, "");
}
function bold($text) {
return clause("", "b", "", "", $text, "");
}
I would simplify your table, too, at least until
you get it working; play with it after that.
$contents = row(cell("", 150) . cell("", 200) . cell("", 200));
while ($row = mysql_fetch_array($retid))
$contents .= row(
cell("<img src='{$row["picurl"]}'>")
.cell(
bold(
"{$row["tit"]} {$row["charname"]} "
.""{$row["charnick"]}""
."{$row["charsname"]}"
)."<br>"
.bold("Contact: ").$row["email"]."<br>"
.bold("Level: ").$row["lvl"]."<br>"
.bold("Breed: ").$row["breed"]."<br>"
.bold("Profession: ").$prof."<br>"
.bold("Location: ").$row["loc"]."<br>"
.bold("AIM: ").$row["aim"]."<br>"
.bold("ICQ: ").$row["icq"]."<br>"
.bold("MSN: ").$row["msn"]."<br>"
.bold("Yahoo!: ").$row["yahoo"]."<br>"
)
.cell(
"<br>"
.bold("Born: ").$row["born"]."<br>"
.bold("Appearance: ").$row["appearance"]."<br>"
.bold("Position: ").$row["posn"]."<br>"
.bold("Characteristics: ").$row["charac"]."<br>"
.bold("Strengths/weaknesses: ").$row["streng"]."<br>"
.bold("Bio: ").$row["bio"]."<br>"
)
);
echo table($contents);
(Note: this approach builds the whole table in memory, in order
to print it out using the clause() function; it might be worth breaking
that out and printing the table a row at a time if there are
many rows in the table.)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]