SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: while uses

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    while uses

    Can you put a while loop inside another while loop?

    I have a while loop putting items into the array and then printing them to the screen. But i want to run another while loop or connect to another DB to pull another set of data.

    For instance... I have table1 that pulls x and y from a database and prints out in the while loop. I have table2 that has y and z. I want to print z with x and y but I cant seem to pull the data in a while loop inside DB1s while loop.

    Any ideas or suggestions?

    Ben
    Last edited by B1011011; Mar 18, 2002 at 13:44.

  2. #2
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, it is possible to put on while loop inside another
    hmm...

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres code

    <?
    $dbuser = 'fiesty';
    $dbhost = 'localhost';
    $dbpass = '******';
    $dbname = 'fiesty';
    $dbtable = 'lookCat';
    $mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);
    $column = mysql_list_fields($dbname,$dbtable,$mysql_link);
    $sql = "SELECT IDref FROM $dbtable where Category = $IDcat";
    $result = mysql_db_query($dbname,$sql);

    while($value = mysql_fetch_array($result))
    {
    $cat = $value["Category"];
    $idref = $value["IDref"];
    print "<font face=\"Arial, Helvetica, sans-serif\"><a href=\"cimages.php?id=$idref\"> $idref </a></font><br>";
    }

    $dbuser = 'fiesty';
    $dbhost = 'localhost';
    $dbpass = '*******';
    $dbname = 'fiesty';
    $dbtable = 'pictures';
    $mysql_link = mysql_connect($dbhost,$dbuser,$dbpass);
    $column = mysql_list_fields($dbname,$dbtable,$mysql_link);
    $sql = "SELECT * FROM $dbtable where ID = $idref";
    $result = mysql_db_query($dbname,$sql);

    while($value1 = mysql_fetch_array($result))
    {
    $desc = $value1["description"];
    print "<font face=\"Arial, Helvetica, sans-serif\"><a href=\"cimages.php?id=$idref\"> $desc </a></font><br>";

    }
    ?>

    So see. I want to put desc from pictures in the same line as the print out from lookCat.

  5. #5
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?PHP

    $dbuser 
    'fiesty'
    $dbhost 'localhost'
    $dbpass '******'
    $dbname 'fiesty'
    $dbtable 'lookCat'

    $db = @mysql_connect("$dbhost""$dbuser""$dbpasswd");
    if (!@
    mysql_select_db("$dbname",$db))
        die(
    "An Error Occured");

    $sql "SELECT IDref FROM $dbtable where Category = $IDcat"
    $result mysql_query($sql); 

    while(
    $value mysql_fetch_array($result)) { 

       
    $cat $value["Category"]; 
       
    $idref $value["IDref"]; 

       print 
    "<font face=\"Arial, Helvetica, sans-serif\"><a href=\"cimages.php?id=$idref\"> $idref </a>"

       
    $sql "SELECT * FROM $dbtable where ID = $idref"
       
    $result2 mysql_query($sql); 

       while(
    $value1 mysql_fetch_array($result)) {

          
    $desc $value1["description"];

          print 
    " <a href=\"cimages.php?id=$idref\"> $desc </a></font><br>"

    }



    ?>
    i think that should work
    Last edited by CHeeSeBLiND; Mar 18, 2002 at 14:24.
    hmm...

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it!. Thanks!
    Last edited by B1011011; Mar 18, 2002 at 14:42.

  7. #7
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result2 mysql_query($sql); 

       while(
    $value1 mysql_fetch_array($result)) { 
    should be
    PHP Code:
    $result2 mysql_query($sql); 

       while(
    $value1 mysql_fetch_array($result2)) { 
    You smell something?

  8. #8
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh yeah, hehe
    hmm...


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
  •