+ Reply to Thread
Results 1 to 3 of 3

Thread: Database help

  1. #1
    ianh41399 is offline x10Hosting Member ianh41399 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    4

    Database help

    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

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Database help

    Quote Originally Posted by ianh41399 View Post
    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, sample code 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 Originally Posted by ianh41399 View Post
    PHP Code:
    <?
    Don't rely on short tags. Use the full <?php opening tag.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    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" and "Display all that would be secret while Mysql is broken" for some partial examples.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    $result mysql_query("SELECT * FROM xxxxxx"); 
    Don't use SELECT *; select only the columns you need.


    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    $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.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    ?>
    <center> 
    <center> is presentational, not semantic, and shouldn't be used. Use CSS instead.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    <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.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
    <?
    $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.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
        $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.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
        $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.

    Quote Originally Posted by ianh41399 View Post
    PHP Code:
        <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 by misson; 11-23-2011 at 05:57 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    lslhsys14 is offline x10Hosting Member lslhsys14 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: Database help

    You are really help. thanks everyone.

+ Reply to Thread

Similar Threads

  1. Replies: 6
    Last Post: 09-06-2011, 01:10 AM
  2. Replies: 2
    Last Post: 07-28-2010, 12:26 AM
  3. Replies: 5
    Last Post: 04-25-2010, 04:02 PM
  4. Replies: 1
    Last Post: 04-17-2010, 12:26 PM
  5. HOWTO: Auto-backup database | transfer database (with pics)
    By galaxyAbstractor in forum Tutorials
    Replies: 3
    Last Post: 02-21-2010, 03:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers