Forum Moderators: open

Message Too Old, No Replies

Not displaying query how I want

         

Spiceydog

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

10+ Year Member



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!

wheelie34

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

WebmasterWorld Senior Member 10+ Year Member



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";
}

Spiceydog

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

10+ Year Member



Thanks! that worked!