Results 1 to 3 of 3

Thread: How would i do this...? [php]/[mysql]

  1. #1

    How would i do this...? [php]/[mysql]

    Ok, im trying to make my footer use a mysql database instead of a text file...

    but im having some problems...
    I am using the code to get the mysql data:
    PHP Code:
    $dbhost 'localhost';
    $dbuser 'designs1';
    $dbpass '*****';

    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql');

    $dbname 'designs1_footer';
    mysql_select_db($dbname);

    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql');
    mysql_select_db($dbname);

    $query  "SELECT * FROM footer ORDER BY RAND() LIMIT 1";

    $result mysql_query($query);

    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {
                 
    $row['comment'];
    }
    mysql_close($conn); 
    That works fine. but i cannot put that into to footer code, it doesnt work if I try:
    PHP Code:
    $string =  while ($row mysql_fetch_array($resultMYSQL_ASSOC))
    {
                 
    $row['comment'];

    it works if I use

    PHP Code:
    $string $array[0]; 
    but it only shows ONE letter from the whole word...

    So does anyone know how to do this?
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

  2. #2
    I didn't even know setting a variable equal to a loop was possible. Anyway, this should work:
    PHP Code:
    $dbhost 'localhost';
    $dbuser 'designs1';
    $dbpass '*****';

    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql');

    $dbname 'designs1_footer';
    mysql_select_db($dbname);
    $query  "SELECT * FROM footer ORDER BY RAND() LIMIT 1";
    $result mysql_query($query);
    $row mysql_fetch_assoc($result);
    $string $row['comment'];
    mysql_close($conn); // you don't actually need this, PHP auto closes it when the script terminates, though if you have multiple connections in one process.. it saves memory 
    got pwnt?

  3. #3
    OMG! what would i do without you helpfull php'ers
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012