...

View Full Version : Calling things that just don't come?



daralee100
07-22-2007, 08:15 PM
As seen at this url: http://www.phpfreaks.com/forums/index.php/topic,149590.msg644302.html#msg644302

I've been having trouble with a certain script... If you can't see the forum above, I'll repost what I'm having trouble with...

Looking at this site: http://musica.clavis-sama.com/ttcg/members.php

Things aren't showing up how they SHOULD appear...

Basically, it's written so that in one of the table boxes it's a button that links with the info from the database I.E.:


$link = "<a href='$row[siteurl]'><img src='$row[urlbanner]'>";

Should bring up a link with the siteurl from the database as the link and the urlbanner variable as the image... Do these need the single quote around them as well? They're called in by:


$sql = "SELECT username,siteurl,urlbanner FROM exchange";

And used as:


echo "<table border=0 cellspacing=0 cellpadding=2 width=200>";
echo "<tr><td>Site Banner<td>Owner";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "<tr><td>";
printf ("%s $td $link %s $el", $row[0], $row["username"]);

Which also should show the username in the correct area. The full coding is:


<?php
$connection = mysql_connect('sql06.freemysql.net','daralee100','*******');
$db = mysql_select_db('tcglinking', $connection);

$sql = "SELECT username,siteurl,urlbanner FROM exchange";
$result = mysql_query($sql);
$link = "<a href='$row[$siteurl]'><img src='$row[urlbanner]'></a>";
//uncomment $link and $el if you want it linkable
$td = "<td>";
echo "<table border=0 cellspacing=0 cellpadding=0 width=200>";
echo "<tr><td>Site Banner<td>Owner";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "<tr><td>";
printf ("%s $td $link", $row[0], $row["username"]);
}

mysql_free_result($result);
?>

Can anyone help me on this?

daralee100
07-23-2007, 02:36 AM
I have no clue why this topic was moved since it's calling on the wrong things somehow in mysql and so it has to do with mysql, but if anyone had any ideas- this is a bumping post...

whizard
07-23-2007, 02:47 AM
Try

$link = "<a href=\"{$row['siteurl']}\"><img src=\"{$row['urlbanner']}\">";

The escape character, \, is used to tell the parser to ignore the next character, thereby rendering double quotes safe for use.

Associative arrays have single quotes around the name of the array item.

When being echoed out inside double quotes, an array reference should be surronded by {}.

HTH
Dan

CFMaBiSmAd
07-23-2007, 03:15 AM
From the warning messages you previously received from the code, PHP warnings are apparently turned on, however I see at least one coding problem (row[...] elements are being referenced before they have been assigned any value) that would be generating notice messages.

When you are debugging code, it is always best to turn on full PHP error reporting.

Also, all of the mysql_xxxxx() function calls do not have any mysql error checking or error reporting. Your initial problem with the server connection string would have been discovered sooner had the mysql_connect() function call had an "or die('Could not connect to mysql server: ' . mysql_error())" on the end of it. Likewise, your queries could be failing due to a sql syntax error and you would not know it. Your table name issue would have also been known sooner if the queries had an "or die('Query failed: ' . mysql_error())" on the end of them.

Short answer - get PHP and mysql to tell you of problems they are finding during execution through the use of error checking and error reporting in your code.

daralee100
07-23-2007, 04:03 AM
Alright, not to sound rude or anything- but the last post didn't mean anything to me and I'm not quite sure how error messages would have helped me at this point.

That taken care of, I took the first poster's suggestion and fixed some basic coding with html stuff. The coding now is:


<?php
$connection = mysql_connect('sql06.freemysql.net','daralee100','*******');
$db = mysql_select_db('tcglinking', $connection);

$sql = "SELECT username,siteurl,urlbanner FROM exchange";
$result = mysql_query($sql);
$link = "<a href=\"{$row['siteurl']}\"><img src=\"{$row['urlbanner']}\"></a>";
//uncomment $link and $el if you want it linkable
$td = "<td>";
$td2= "</td>";
$tr = "</tr>";
echo "<table border=0 cellspacing=0 cellpadding=0 width=200>";
echo "<tr><td>Site Banner</td><td>Owner</td></tr>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "<tr>";
printf ("$td $link", $td2, "$td {$row['username']}", $td2, $tr);
}

mysql_free_result($result);
?>

And magically, the username that had been calling disappeared and the table still is funky on the page. I would like the final product to look like the attached image. (Though this is a very badly drawn paint document....) Any suggestions for this calling? The banner isn't calling from the spot in the table, not linking to the site in the table, and now not calling the username. Suggestions on this developement? If you have an easier way to achieve the final product as seen in the picture, let me know that too....

daralee100
07-23-2007, 04:51 AM
Bumping randomly waiting for a response...

daralee100
07-23-2007, 05:31 AM
I have scrapped the old member script as crap and have modified and tested my own to be completely accurate. Thanks to those who helped and less than that to those who may have hindered.... Sorry!

Fumigator
07-23-2007, 06:21 AM
Alright, not to sound rude or anything- but the last post didn't mean anything to me and I'm not quite sure how error messages would have helped me at this point.

That is classic-- may I quote you? Error messages are for sissies anyway! :thumbsup: Back in the olden days we had to make sense of a memory dump to find the problem and nowadays you kids have it so easy with these fancy "error messages". Bah, who need em! :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum