+ Reply to Thread
Results 1 to 9 of 9

Thread: php mysql help

  1. #1
    jrobert755 is offline x10Hosting Member jrobert755 is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    15

    php mysql help

    this is not working. it should get a list of values from a table, but it never does, and just stops running, displaying whats before it, and thats all (its in an include command on another page) could someone try to fix it?

    PHP Code:
    mysql_connect("localhost""jrobert7""password");
        
    mysql_select_db("jrobert7_testing");
        
    $resultmysql_query("SELECT * FROM articles");
        while(
    $results mysql_fetch_array($result))
        {
            echo 
    "<div class=\"summary\">
                    <div class=\"body\">
                        <h2><u><a href=\""
    .$results['link']. "\">".$results['name']. "</a></u></h2>
                        <p style=\"margin-top:-2px;\">
                        <em>
                        "
    .$results['link']. "<small>(2 hits)</small>
                        </em>
                        "
    $results['description'"<a  class=\"more\" href=\"".$results['link']. "\" style=\"color:#105CB6;\">More...</a>
                        </p>
                        <div class=\"options\">
                            <a class=\"space compick\" href=\""
    .$results['link']. "\">0 comments</a>
                            <a class=\"space share\" href=\""
    .$results['link']. "\">Share</a>
                            <a class=\"space views\" href=\""
    .$results['link']. "\">".$results['views']. "\"views</a>
                        </div>
                    </div>
                    <ul class=\"fav\">
                        <li class=\"favcount\">
                            <a class=\"favcount\" href=\""
    .$results['link']. "\"><strong>".$results['fav']. "</strong><br />
                            <span>favs</span></a>
                        </li>
                        <li class=\"favit\">
                            <a class=\"favit\" href=\""
    .$results['link']. "\">fav it</a>
                        </li>
                    </ul>
                </div>"
    ;
        } 
    Last edited by jrobert755; 01-31-2009 at 01:00 PM.

  2. #2
    blobtech is offline x10Hosting Member blobtech is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    16

    Re: php mysql help

    First of all: its wise to not show your database password to the public.
    You should edit that out =D.

    But.. about your script. It seems fine, no PHP errors in it.
    Are you sure it can succesfully connect to the database (as there is no code to catch the error when it can't)?

    Try altering the lines
    PHP Code:

    mysql_connect
    ("localhost""jrobert7""password");
    mysql_select_db("jrobert7_testing"); 
    To
    PHP Code:

    mysql_connect
    ("localhost""jrobert7""password") or die("Could not connect: " mysql_error());
    mysql_select_db("jrobert7_testing") or die("Could select DB: " mysql_error()); 
    And tell us what output it gave.

    Another error could be that the database is empty, and therefor the while loop never runs because mysql_fetch_array will return false as it can not find a row.

    You can check the number of rows returned by your query with the following function
    and output a message that there are no results when it equals 0:
    PHP Code:

    $num 
    mysql_num_rows($result); 
    Last edited by blobtech; 01-31-2009 at 01:16 PM.

  3. #3
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: php mysql help

    1) Never reveal your password and name to anyone unless you know them completely...

    2) I myself have had errors with using the \" inside "s so try this:


    Code:
    echo ‘<div class=“summary”>
                    <div class=“body”>
                        <h2><u><a href=“’.$results['link']. ‘“>‘.$results['name']. ‘</a></u></h2>
                        <p style=“margin-top:-2px;”>
                        <em>
                        ‘.$results['link']. ‘<small>(2 hits)</small>
                        </em>
                        ‘$results['description'] ‘<a  class=“more” href=“’.$results['link']. ‘“ style=“color:#105CB6;”>More...</a>
                        </p>
                        <div class=“options”>
                            <a class=“space compick” href=“’.$results['link']. ‘“>0 comments</a>
                            <a class=“space share” href=“’.$results['link']. ‘“>Share</a>
                            <a class=“space views” href=“’.$results['link']. ‘“>‘.$results['views']. ‘“views</a>
                        </div>
                    </div>
                    <ul class=“fav”>
                        <li class=“favcount”>
                            <a class=“favcount” href=“’.$results['link']. ‘“><strong>‘.$results['fav']. ‘</strong><br />
                            <span>favs</span></a>
                        </li>
                        <li class=“favit”>
                            <a class=“favit” href=“’.$results['link']. ‘“>fav it</a>
                        </li>
                    </ul>
                </div>‘;
    Last edited by VPmase; 01-31-2009 at 09:45 AM.

  4. #4
    jrobert755 is offline x10Hosting Member jrobert755 is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    15

    Re: php mysql help

    changed my password (copy- paste error ). didn't work, no error and no results

    tested it on a different host that i had before x10 and it works almost perfectly (need to work on css to get layout right though), and it got the data i wanted. its probably a restriction on the php on the server
    Last edited by jrobert755; 01-31-2009 at 01:34 PM. Reason: testing on different host

  5. #5
    blobtech is offline x10Hosting Member blobtech is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    16

    Re: php mysql help

    Just saw a mistake, but I do not understand why PHP does not error.

    There are no dots around
    PHP Code:
    $results['description'// 6th line from the start of `echo` 
    and therefor the strings are not joined.

    I tested a small script with something similar on my server, and it just returns a blank page, so I guess that this is it.
    Last edited by blobtech; 01-31-2009 at 01:35 PM.

  6. #6
    jrobert755 is offline x10Hosting Member jrobert755 is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    15

    Re: php mysql help

    yeah, like i said, uploaded to another hosting site i had before, fixed that problem, and it worked like a charm.

  7. #7
    mephis's Avatar
    mephis is offline x10Hosting Member mephis is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: php mysql help

    try changin this line:
    PHP Code:
    while($results mysql_fetch_array($result)) 
    to this:
    PHP Code:
    while($results mysql_fetch_assoc($result)) 

  8. #8
    blobtech is offline x10Hosting Member blobtech is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    16

    Re: php mysql help

    Actually, mysql_fetch_assoc is almost the same thing.

    PHP Code:
    mysql_fetch_assoc($result); 
    Is the equivelant of calling
    PHP Code:
    mysql_fetch_array($resultMYSQL_ASSOC); 
    However, mysql_fetch_array has as default optional parameter MYSQL_BOTH. That means it will return an associative as well as a numeric array.

    Which is the same as
    PHP Code:
    mysql_fetch_row($result) + mysql_fetch_assoc($result); 
    There is no need for changing that line.

  9. #9
    brunoais is offline x10 Sophmore brunoais is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    111

    Re: php mysql help

    [quote=jrobert755;517229]this is not working. it should get a list of values from a table, but it never does, and just stops running, displaying whats before it, and thats all (its in an include command on another page) could someone try to fix it?

    PHP Code:
    mysql_connect("localhost", "jrobert7", "password");
        mysql_select_db("jrobert7_testing");
        $result= mysql_query("SELECT * FROM articles");
        while($results = mysql_fetch_array($result))
        {
    ?> div class=\"summary\">
                    <div class=\"body\">
                        <h2><u><a href="<?=$results['link'?>"><?=$results['name']?> "</a></u></h2>
                        <p style=\"margin-top:-2px;\">
                        <em>
                        <?=$results['link']?><small>(2 hits)</small>
                        </em>
                        <?=$results['description']?><a  class="more" href="<?=$results['link']?>"
    etc....
    It makes more simple coding and it's less probeble for you to make any mistakes.
    just make a:
    <?=
    befora the variable and
    ?>
    after the variable.
    ;)

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Places to learn php
    By JaWasabi in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 01-13-2009, 02:03 AM
  3. [Cossacks] PHP Wont Load MYSQL DOWN
    By pasacom in forum Free Hosting
    Replies: 0
    Last Post: 08-26-2008, 12:30 AM
  4. PHP MySQL Question..
    By anuj_web in forum Programming Help
    Replies: 7
    Last Post: 04-26-2008, 05:43 AM
  5. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM

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