Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling things that just don't come?

    As seen at this url: http://www.phpfreaks.com/forums/inde...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.:

    Code:
    $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:

    Code:
    $sql = "SELECT username,siteurl,urlbanner FROM exchange";
    And used as:

    Code:
    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:

    Code:
    <?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?

  • #2
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <?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....
    Attached Thumbnails Attached Thumbnails Calling things that just don't come?-member.jpg  

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bumping randomly waiting for a response...

  • #7
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #8
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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! 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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •