Database help

ianh41399

New Member
Messages
4
Reaction score
0
Points
0
Hey guys I am having trouble with how my website pops up. You will see the problem when you go to it.
Here is the code I am using:

<?
mysql_connect(localhost,'xxxxxx','xxxxxx');
@mysql_select_db('xxxxxx');


$result = mysql_query("SELECT * FROM xxxxxx");
$numofrows = mysql_num_rows($result);
$height=240*ceil($numofrows / 3);
?>
<center>
<div id="games">
<?
$i=$numofrows-1;
while($i > -1){
$k = $i;
$linkname = mysql_result($result,$i,'nameofgame');
$linkhref = mysql_result($result,$i,'URL');
$linkpic = mysql_result($result,$i,'picurl');
$sidedecider = $i % 3;
if($sidedecider == 0){
$align = "left";
}
if($sidedecider == 1){
$align = "center";
}
if($sidedecider == 2){
$align = "right";
}
?>
<a href="javascript:;" onclick="javascript:document.getElementById('<? echo $linkname; ?>').submit();">
<img align="<? echo $align; ?>" src="<? echo $linkpic; ?>" class="game"></a>
<form id="<? echo $linkname; ?>" action="game.php" method="post">
<input type="hidden" name="gameurl" value="<? echo $linkhref; ?>">
</form>


<?
$i--;
}


$otherresult = mysql_query("SELECT * FROM xxxxxx");
$othernumberofrows = mysql_num_rows($otherresult);


$j=0;
?>
</div>
</center>

my website is at http://mpm.x10.mx
please help
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You will see the problem when you go to it.
You should state the problem in your post rather than directing people to the site. Always describe what you expect to happen and what actually happens, including any error messages. Without the former, we can't tell what's wrong. You should include a link to the specific page (not site) that has the problem not for descriptive purposes but for testing purposes.

Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code. In addition to improving readability, the colorizing can catch certain simple errors.

In general, [url=http://sscce.org/]sample code[/url] should be complete and concise–just enough code to reproduce the problem. Your sample may already be minimal; since you haven't stated the problem, I can't tell how much extraneous code there is.

[quote="ianh41399, post: 872453"][php]
<?
[/QUOTE]
Don't rely on short tags. Use the full <?php opening tag.

PHP:
mysql_connect(localhost,'xxxxxx','xxxxxx');
@mysql_select_db('xxxxxx');

The mysql extension is outdated and on its way to deprecation. Instead, use PDO, which has many useful improvements, such as prepared statements and support for the Traversable interface, so you can loop over results with foreach. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO".

Database connection creation (including managing the database credentials) should be the responsibility of one class rather than handled separately in each script. The more scripts contain user credentials, the more files there are for you to secure and the greater chance of typos screwing things up. Reduce critical code repetition. See "
PHP:
 MySQL and PHP[/URL]" and "[URL="http://x10hosting.com/forums/programming-help/117523-display-all-would-secret-while-mysql-broken.html#post665590"]Display all that would be secret while Mysql is broken[/URL]" for some partial examples.

[quote="ianh41399, post: 872453"][php]
$result = mysql_query("SELECT * FROM xxxxxx");
[/QUOTE]
[URL="http://stackoverflow.com/questions/321299/what-is-the-reason-not-to-use-select"]Don't use SELECT *
; select only the columns you need.


PHP:
$numofrows = mysql_num_rows($result);
$height=240*ceil($numofrows / 3);

The web isn't print. Fixed layouts can't account for differences in screen dimensions. Search the web for "fluid layout" and "elastic layout". A List Apart in particular is know for quality articles.

PHP:
?>
<center>

<center> is presentational, not semantic, and shouldn't be used. Use CSS instead.

PHP:
<div id="games">

<div> is semantically neutral; it's an element of last resort. Since you're producing a list of games, use a list element.

PHP:
<?
$i=$numofrows-1;
while($i > -1){
By starting with the last row in the result set, your script must wait until all results are available. It's better to start with the first row. If you need the results in a specific order, use an ORDER BY clause.

PHP:
    $k = $i;
    $linkname = mysql_result($result,$i,'nameofgame');
    $linkhref = mysql_result($result,$i,'URL');
    $linkpic = mysql_result($result,$i,'picurl');

From the PHP manual page for mysql_result:
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.


PHP:
    $sidedecider = $i % 3;
    if($sidedecider == 0){
        $align = "left";
    }
    if($sidedecider == 1){
        $align = "center";
    }
    if($sidedecider == 2){
        $align = "right";
    }
    ?>
    <a href="javascript:;" onclick="javascript:document.getElementById('<? echo $linkname; ?>').submit();">

The "javascript:" scheme is considered poor practice. Instead, use a real link and a click handler. One advantage is that this will work if JS is disabled or unsupported, such as with search spiders. This also properly applies the hypertext model and semantics for <a>: anchors are to link documents to other documents, not simply as connection points for behavior. These things (structure, presentation, behavior) are built up; don't ignore one for another.

PHP:
    <img align="<? echo $align; ?>" src="<? echo $linkpic; ?>" class="game"></a>
    <form id="<? echo $linkname; ?>" action="game.php" method="post">
    <input type="hidden" name="gameurl" value="<? echo $linkhref; ?>">
    </form>
The form is unnecessary.
 
Last edited:
Top