Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why won't this loop work

    For some reason my loop won't work. I'm new to php and am following a developers guide but my loop only seems to pull up the last record unless I specify an id in my sql. I've been searching the posts and this seems like a rudimentary problem but I keep getting the error - 'Call to a member function on a non-object' on the line containing the MoveNext() function. I have tried using the PHPLIB to extend the MySQL db class as well but still only get the last or specified record.

    Please, I need help, and thank you in advance.


    <?php

    $aDBLink = mysql_connect("localhost", "robin", "******");

    if (!empty( $aDBLink))
    {
    if (mysql_select_db("artsdb", $aDBLink) == True)
    {
    $aSQL = "select * from tblartist";
    $aQResult = mysql_query($aSQL, $aDBLink);

    if ($aQResult == True)
    {
    while( $aRow = mysql_fetch_array($aQResult))
    {
    $aID = $aRow["artist_id"];
    $aFname = $aRow["fname"];
    $aLname = $aRow["lname"];
    $aPhone = $aRow["phone"];
    $aEmail = $aRow["email"];
    $aMusic = $aRow["music"];
    $aGdesign = $aRow["gdesign"];
    $aLit = $aRow["lit"];
    $aPhoto = $aRow["photo"];

    }
    mysql_free_result($aQResult);
    }
    else
    {print("query failed");}
    }
    else
    {print("unable to select DB");}
    }
    else
    {print("unable to connect to DB");}
    ?>

    <body>

    <div id="title">
    <h1><span>For Art Sake</span></h1>
    </div>

    <table align="center">
    <th colspan="2"><u>Artist</u></th>
    <th></th>
    <th colspan="7"><u>Category</u></th>
    <?php while (!$aQResult->EOF) {

    print ("<tr>");
    print ("<td>$aFname</td>");

    print ("<td>$aLname</td>");

    print ("<td width=\"100\"></td>");

    print ("<td>");

    if ($aMusic == "1")
    print("<a href=\"music.php?artist_id=$aID\">Music</a>");
    else
    print("n\a");

    print ("</td>");

    print ("<td width=\"75\"></td>");

    print ("<td>");

    if ($aGdesign == "1")
    print("<a href=\"gdesign.php?artist_id=$aID\">Graphic Design</a>");
    else
    print("n\a");

    print ("</td>");

    print ("<td width=\"75\"></td>");

    print ("<td>");

    if ($aLit == "1")
    print("<a href=\"lit.php?artist_id=$aID\">Literature</a>");
    else
    print("n\a");

    print ("</td>");

    print ("<td width=\"75\"></td>");

    print ("<td>");

    if ($aPhoto == "1")
    print("<a href=\"photo.php?artist_id=$aID\">Photography</a>");
    else
    print("n\a");

    print ("</td>");
    print ("</tr>");

    $aQResult->MoveNext();

    }
    $aQResult->Close();
    ?>

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well, it is working. It's looping through and assigning the value to each of the variables again and again such that when it finishes they have the last values.

    You need to put your print() stuff in that while loop.
    Omnis mico antequam dominus Spookster!

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Spookster. appreciate it.

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    argh..SPOOKSTER??? Where??
    Last edited by Mhtml; 04-23-2004 at 08:18 PM.
    Omnis mico antequam dominus Spookster!

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol, Spookster for President!


  •  

    Posting Permissions

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