Forum Moderators: coopster
$query = "SELECT * FROM jokes ORDER BY genre";// Probably change query to one the ones you suggested
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$genre = $row['genre'];
$title = $row['title'];
$joke = $row['jokes'];
$rating = $row['rating'];
for($something //Have no idea how to make a for loop
){
$display_joke = displayJoke('$genre', '$title', '$joke');//my function
echo "<a name=\"$genre\"><span class=\"titlebar\">$genre</span>";
//Create under title(jokes in the genre):echo "<p class=\"jl\"><a href=\"$display_joke\">$title</a></p>";
}
Is there any way to accomplish this?
electricocean
The first is much easier, as you have to just call a function
function genre($genre){$sql = "SELECT jokes FROM table WHERE genre='$genre';//and spit it out
}
$sql = "SELECT DISTINCT genre FROM table ORDER BY genre";
//query and
while($row = mysql_fetch_assoc($query)){//write genre and some text
genre($row["genre"]);//call function
}
$sql = "SELECT jokes, genre FROM table ORDER BY genre";
...
while($row = mysql_fetch_array($query))
{
if(!$old) //do the first row stuff - write beginning and first joke
else
{
//check if $row has different genre than $old. If no then write the joke, if yes then write the genre and the joke
if($row["genre"] == $old) //write the genre and the joke
else //write the joke
}
$old = $row["genre"];//write genre to $old to remember last written genre
}
//So when there's no $old you write first genre: $old = null;
Jokes on MAX:
//and first joke
joke1
//Then you remeber in old the genre: $old = max
//Next joke has the same genre, so you just write it:
joke2
//Next joke has different genre than in $old, so you have to write the genre:
Jokes on POLICE
//And write the joke as well:
joke3
//And put the genre in $old = police
That's it
Hope it cleares things a bit for you
Best regards
Michal Cibor
mysql_fetch_array($ans, MYSQL_BOTH): [1] => "bla", ["bla"] => "bla"
mysql_fetch_array($ans): [1] => "bla", ["bla"] => "bla"
mysql_fetch_row($ans): [1] => "bla"
mysql_fetch_assoc: ["bla"] => "bla"
There's more to mysql_fetch_array. You can read about it at [php.net...]
Best regards
Michal Cibor