Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   PHP Dump issue. (http://www.programmingforums.org/showthread.php?t=15424)

irish Mar 16th, 2008 12:38 PM

PHP Dump issue.
 
I've been trying to dump some info from an SQL Database into a webpage using PHP. My problem is that there is a massive gap appearing at the beginning before the information comes out(see here ignore general appearance, will be fixed afterwards :P), I've tried editing the html etc as much as possible but that doesn't affect it, it's the PHP itself I think. Can you find any reason why this code would present that problem?

:

       
$sql = "SELECT raiders as raiders, spent , earned, balance
        FROM  raidpoints";

$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
        echo '<tr><td width="120" align="center" valign="top">';
        echo $row["raiders"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["spent"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["earned"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["balance"];
        echo '</td></tr><br>';
}


Will also be making the code more efficient afterwards, just need help with the logic of the current code. :)

Jimbo Mar 16th, 2008 1:43 PM

Re: PHP Dump issue.
 
Taking a wild guess, I'd say that you should provide a connection to your MySQL server when you call mysql_query() (unless you have it set so that the default connection works...). Also, as one of my own habits, I tend to verify that the query worked right, e.g:
:

$result = mysql_query($query, $dbLink) or die("MySQL query failed.  Query was:<br />$query");
Of course, the error message should be changed if you actually deploy the website, but it can help for debugging ;)

HTH

irish Mar 16th, 2008 1:47 PM

Re: PHP Dump issue.
 
Ah, sorry for lack of full info hehe. I do have the full code just below :P

:

$conn = mysql_connect("localhost", "<edited to hide username>", "<edited to hide password>");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
 
if (!mysql_select_db("honourbo_raidpoints")) {
    echo "Unable to select honourbo_raidpoints: " . mysql_error();
    exit;
}

$sql = "SELECT raiders as raiders, spent , earned, balance
        FROM  raidpoints";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

        while ($row = mysql_fetch_assoc($result)) {
        echo '<tr><td width="120" align="center" valign="top">';
        echo $row["raiders"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["spent"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["earned"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["balance"];
        echo '</td></tr><br>';
}


This is just the php code, since the HTML plays no part in the errors. I receive no error messages at all. Any ideas?

Dameon Mar 16th, 2008 1:55 PM

Re: PHP Dump issue.
 
The blank space is because of the following.
:

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

I'm going to blame the parts of the file that you didn't paste.

irish Mar 16th, 2008 2:02 PM

Re: PHP Dump issue.
 
Sorry for the hassle so far guys hehe. The code I just started using is taken from the main page of the Gaming Guild, however even when I simply put the PHP into a php file and uploaded it, it still showed the same problem. Full code:

:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <Title>Honourbound - Raid Points Status</Title>
<meta name="description" content="Honourbound, a World of Warcraft guild on Outland EU Realm" />
<meta name="keywords" content="Honourbound, honourbound, world of warcraft, wow, WoW, Outland, outland" />
<meta name="Generator" content="Joomla! - Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved." />
<meta name="robots" content="index, follow" />
        <link rel="shortcut icon" href="http://www.honourbound.net/images/favicon.ico" />
       


        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link rel="shortcut icon" href="http://www.honourbound.net/images/favicon.ico" />

                <link href="http://www.honourbound.net/templates/rt_replicant/css/rokmoomenu.css" rel="stylesheet" type="text/css" />
                <link href="http://www.honourbound.net/templates/rt_replicant/css/template_css.css" rel="stylesheet" type="text/css" />
        <link href="http://www.honourbound.net/templates/rt_replicant/css/header-dark-red.css" rel="stylesheet" type="text/css" />
        <link href="http://www.honourbound.net/templates/rt_replicant/css/rokslidestrip.css" rel="stylesheet" type="text/css" />
        <link href="http://www.honourbound.net/templates/rt_replicant/rokzoom/rokzoom.css" rel="stylesheet" type="text/css" />
        <!--[if lte IE 6]>
        <link href="http://www.honourbound.net/templates/rt_replicant/css/template_ie6.css" rel="stylesheet" type="text/css" />
        <style type="text/css">


        img { behavior: url(http://www.honourbound.net/templates/rt_replicant/css/iepngfix.htc); }
        </style>
        <![endif]-->
        <style type="text/css">
                body {color: #fff;background: #000000 url(http://www.honourbound.net/templates/rt_replicant/images/bg/NewHBbackground.jpg) 50% 0 no-repeat fixed;}
                a { color: #fc0 }       
                .moduletable h3, #horiz-menu, ul#rokslide-toolbar { color: #fff; }
                #horiz-menu a, h3.toggler { color: #fc0; }
                .sections td,#showcase,#mainframe td#left,#mainframe td#right,#mainframe #user1,#mainframe #page,pre {border: 1px solid #364148;}
                #shadow-bottom .padding {        border-top: 1px solid #364148;}
    .style1
    {
        width: 100%;
        height: 6%;
    }
    .style2
    {
            height: 52px;
    }
    .style3
    {
            height: 52px;
      text-align: center;
    }
        </style>       
        <script type="text/javascript" src="http://www.honourbound.net/templates/rt_replicant/js/mootools.js"></script>

        <script type="text/javascript" src="http://www.honourbound.net/templates/rt_replicant/rokzoom/rokzoom.js"></script>
                <script type="text/javascript" src="http://www.honourbound.net/templates/rt_replicant/js/mootools.bgiframe.js"></script>
        <script type="text/javascript" src="http://www.honourbound.net/templates/rt_replicant/js/rokmoomenu.js"></script>
        <script type="text/javascript">
        window.addEvent('domready', function() {
                new Rokmoomenu($E('ul.nav'), {
                        bgiframe: false,
                        delay: 500,
                        animate: {
                                props: ['opacity', 'width', 'height'],
                                opts: {
                                        duration:400,
                                        fps: 100,
                                        transition: Fx.Transitions.Cubic.easeOut
                                }
                        }
                });
        });
        </script>
               
        <script type="text/javascript">
                window.addEvent('load', function() {
                        RokZoom.init({
                                imageDir: 'templates/rt_replicant/rokzoom/images/',
                                resizeFX: {
                                        duration: 500,
                                        transition: Fx.Transitions.Circ.easeOut,
                                        wait: false
                                }
                        });
                });
        </script>
        </head>

        <body id="smoke">
                <div class="surround">
                                                <div class="wrapper">

                                <div id="shadow-top"></div>
                                <div id="shadow-middle" style="text-align: center">

                                        <div class="padding">
                                       
                                                                                <table class="style1" border="1">   
                <tr><td width="120" valign="top" class="style3"><u><b style="text-align: center">Player</b></u><br></td>
            <td align="center" valign="top" class="style2"><u><b>Points Spent</b></u><br></td>
                <td valign="top" class="style3"><u><b>Points Earned</b></u><br></td>
                <td valign="top" class="style3"><u><b>Current Balance</b></u><br></td></tr>

<?php

$conn = mysql_connect("localhost", "<Edited to hide the username>", "<Edited to hide the password");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
 
if (!mysql_select_db("honourbo_raidpoints")) {
    echo "Unable to select honourbo_raidpoints: " . mysql_error();
    exit;
}

$sql = "SELECT raiders as raiders, spent , earned, balance
        FROM  raidpoints";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

        while ($row = mysql_fetch_assoc($result)) {
        echo '<tr><td width="120" align="center" valign="top">';
        echo $row["raiders"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["spent"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["earned"];
        echo '</td>';
        echo '<td width="120" align="center" valign="top">';
        echo $row["balance"];
        echo '</td></tr><br>';
}
?>
</tr>
</table>               
                                </div>
                                        <a href="http://www.honourbound.net" class="nounder">
                                                                                                <div id="pathway"><span id="logo"></span></a>

                                               

                                        </div>
<td id="middle">
                                                                                                                                                                <div id="page">
                                </div>
                                </div>
                                <div id="shadow-bottom">
                                        <div class="padding">
                                                                                                                        </div>

                                </div>
                                <div id="shadow-rocket"><a href="http://www.rockettheme.com/" title="RocketTheme Joomla Template Club" class="nounder"><img src="http://www.honourbound.net/templates/rt_replicant/images/blank.gif" alt="RocketTheme Joomla Templates" id="rocket" /></a></div>
                        </div>
                </div>
                <div id="fgimage"></div>
                <div id="bgimage"></div>
        </body>
</html><!-- 1205653478 -->



All times are GMT -5. The time now is 9:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC