SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why wont this work?

    This code wont work:

    PHP Code:

    <?php


    // create connection
    $connection mysql_connect("127.0.0.1","root","");

    // test connection
    if (!$connection) {
    echo 
    "Couldn't make a connection!";
    exit;
    }

    // select database
    $db mysql_select_db("templates"$connection);

    // test selection
    if (!$db) {
    echo 
    "Couldn't select database!";
    exit;
    }

     
    // create SQL statement
    $sql "SELECT ID, Author, Date, Download, Size, View, Name, Screenshot
    FROM templates
    ORDER BY ID"
    ;

    // execute SQL query and get result
    $sql_result mysql_query($sql,$connection);

    // start results formatting
    echo "<table cellspacing=\"1\" cellpadding=\"1\" border=\"0\">";

    $columns 2;
    $i 0;
    echo 
    "<tr>";
    while (
    $row mysql_fetch_array($sql_result))
    {
      
    $view $row["view"];
      
    $screenshot $row["screenshot"];
      
    $download $row["download"];
      
    $date $row["date"];
      
    $name $row["name"];
      
    $size $row["size"];
      
    $author $row["author"];
      echo 
    "<td valign=\"top\"><table cellspacing=\"0\" cellpadding=\"0\" width=\"100\" border=\"0\"><tr><td colspan=\"2\"><img src=\"$screenshot\" width=\"100\" height=\"75\" border=\"0\"></td></tr><tr><td align=\"center\"><a href=\"$view\" class=\"n\">View</a></td><td align=\"center\"><a href=\"$download\" class=\"n\">Download</a></td></tr></table></td><td valign=\"middle\"><table cellspacing=\"1\" cellpadding=\"1\" border=\"0\"><tr><td valign=\"top\" class=\"text\"><b>Author:</b></td><td valign=\"top\" class=\"text\">$author</td></tr><tr><td valign=\"top\" class=\"text\"><b>Name:</b></td><td valign=\"top\" class=\"text\">$name</td></tr><tr><td valign=\"top\" class=\"text\"><b>File Size:</b></td><td valign=\"top\" class=\"text\">$size</td></tr><tr><td valign=\"top\" class=\"text\"><b>Uploaded:</b></td><td valign=\"top\" class=\"text\">$date</td></tr></table></td>";
      ++
    $i;
      if(
    $i == $columns)
      {
        echo 
    "</tr>\n<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n<tr>";
        
    $i 0;
      }
    }
    echo 
    "</tr>\n</table>";

    ?>


    Heres the sql dump:



    CREATE TABLE templates (
    ID int(11) NOT NULL auto_increment,
    Author text,
    Size text,
    View text,
    Download text,
    Screenshot text,
    Name text,
    Date text,
    PRIMARY KEY (ID)
    ) TYPE=MyISAM;

    I am wracking my brain trying to get this to work

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you didn't say what the problem is. you gotta tell us what's not working.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    eigo hanasemasu ka? Yes. =) ZuulJin's Avatar
    Join Date
    Dec 2001
    Location
    Japan
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, why are you putting each array key into a variable? Why not use the array?

    Second, what is the error your getting?

    [Z]
    U.S. DoD Member in Japan?
    Choose your base. Buy|Sell. Easy
    @ APO Ads.



  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where the $blah is in the echo (where the output of the db is sposed to be) is blank

    lemme save the output and upload it...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    eigo hanasemasu ka? Yes. =) ZuulJin's Avatar
    Join Date
    Dec 2001
    Location
    Japan
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might as well make your SQL query:

    PHP Code:
    $sql "SELECT * FROM templates ORDER BY ID"
    Try echoing each variable out to see if they actually contain a value.

    Here is something I always do in my code:

    PHP Code:
    echo "This is some text that contains a " $variable " that can be dynamic."
    You notice the " . before the variable and the . " after the variable. I believe this is the 'right' way to have variables inline with the echo (I'll probably be corrected on that one).

    [Z]
    U.S. DoD Member in Japan?
    Choose your base. Buy|Sell. Easy
    @ APO Ads.



  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not work. I went into phpmyadmin and there is stuff in there... :P But it doesn't work

  8. #8
    eigo hanasemasu ka? Yes. =) ZuulJin's Avatar
    Join Date
    Dec 2001
    Location
    Japan
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this for you query

    PHP Code:
    $sql "SELECT * FROM templates ORDER BY ID";

    $sql_results mysql_query($sql) or die(mysql_error()); 
    Did you try to echo a variable? If they are empty that means your query isn't getting out the values. The above code should produce a mysql error string if the query fails.

    [Z]
    U.S. DoD Member in Japan?
    Choose your base. Buy|Sell. Easy
    @ APO Ads.



  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    theres data in there but its not getting through. I'm not even getting errors

  10. #10
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I can tell you this much. I copied and pasted your echo statement and loaded up the variables with some data and it echoed fine so everything is alright there. Are you positive it's pulling the info from the database?

    kix

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it works for you?

  12. #12
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i spotted the problem. your columns have capital letters in them (e.g. "Author"). but, after you fetch the rows you're referring to them all lowercase (e.g. "author"), and there's no element with those names in the $row array. change 1 of those things and it should work.

    i suggest you ALWAYS use lowercase names for ALL of your columns.

  13. #13
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it worked... thanks . dr pepper you rule

  14. #14
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great! no problem. sorry i didn't spot it the first time. i just didn't bother looking at every bit of the code since you didn't say what was wrong. then, when i came back and saw the other people's replies and looked at your page, i decided to more closely examine the code.

  15. #15
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The nex thing i'm gonna try to do is make it so only 10 pieces of outputn per page.


Bookmarks

Posting Permissions

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