Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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