...

View Full Version : why won't this loop work



incubo
04-23-2004, 06:05 PM
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();
?>

Mhtml
04-23-2004, 07:04 PM
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.

incubo
04-23-2004, 08:14 PM
Thanks Spookster. appreciate it.

Mhtml
04-23-2004, 08:15 PM
argh..SPOOKSTER??? Where??

sad69
04-23-2004, 09:02 PM
lol, Spookster for President!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum