Welcome to WebmasterWorld Guest from 18.208.159.25

Forum Moderators: open

Message Too Old, No Replies

Not displaying query how I want

     
10:19 pm on May 12, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2008
posts:45
votes: 0


I have a php script that is supposed to select name and period from two tables (schedule and classes) where a bunch of different things happen and order by name desc. Anyway it's all in the script below if that didn't make since. Now the problem is that when it prints "name" it is supposed to echo everything that meets the requirements. For some reason it is only echoing the first name that meets the requirements and I am sure that there is more than one name that meets the requirements. It is as if there is a limit on the select but there isn't.

<?php
$searchclass = $_POST['searchclass'];
$classperiod = $_POST['classperiod'];
include 'login.php';
$query = "SELECT name,
period
FROM schedule, classes
WHERE ((first='$searchclass' AND period='$classperiod') OR (second='$searchclass' AND period='$classperiod') OR (third='$searchclass' AND period='$classperiod') OR (fourth='$searchclass' AND period='$classperiod') OR (fifth='$searchclass' AND period='$classperiod') OR (sixth='$searchclass' AND period='$classperiod') OR (seventh='$searchclass' AND period='$classperiod') OR (eighth='$searchclass'AND period='$classperiod'))
ORDER BY name DESC";
$result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error());
while($data = mysql_fetch_array($result, MYSQL_ASSOC))
{
$name = $data['name'];
}
{
echo "$name";
}
?>

Thanks in advance!

8:46 am on May 13, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 6, 2005
posts:863
votes: 0


You've actually closed the while loop here

while($data = mysql_fetch_array($result, MYSQL_ASSOC))
{
$name = $data['name'];
}
{
echo "$name";
}

Try changing it to this

while($data = mysql_fetch_array($result, MYSQL_ASSOC))
{
$name = $data['name'];
echo "$name";
}

8:31 pm on May 13, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2008
posts:45
votes: 0


Thanks! that worked!