473,513 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

while echo output

I have now spent well over 12 hours on this one problem.

I am pulling data out of a database, the data in the database is categorized by a value (season).
I need to title the first value, then echo the listings that would fall into that category. Once this is completed I need to then label the next value and echo the values that would fall into that category... so on and so forth..

this is concept I have had so far:

include("./include/db.inc.php");
$sql = "SELECT * FROM table WHERE view=1 ORDER BY file";
$result = mysql_query($sql, $dbconn) or die(mysql_error());

while ($newArray = mysql_fetch_array($result)) {
$id = $newArray['id'];
$season = $newArray['season'];
$file = $newArray['file'];
$name = $newArray['name'];
$history = $newArray['history'];
$view = $newArray['view'];

if ($season == "0") {
echo "<b>--- Pre-Season ---</b><br/>";
echo "<a href=\"images/$file.jpg\">$name</a><br/>\n";
}

if ($season == "1") {
echo "<b>--- 1st Season ---</b><br/>";
echo "<a href=\"images/$file.jpg\">$name</a><br/>\n";
}

if ($season == "2") {
echo "<b>--- 2nd Season ---</b><br/>";
echo "<a href=\"images/$file.jpg\">$name</a><br/>\n";
}
}

?>

The output I get from this is:

<b>--- Pre-Season ---</b><br/>
<a href=\"images/value1-file.jpg\">value1-name</a><br/>

<b>--- Pre-Season ---</b><br/>
<a href=\"images/value2-file.jpg\">value2-name</a><br/>

<b>--- Pre-Season ---</b><br/>
<a href=\"images/value3-file.jpg\">value3-name</a><br/>

<b>--- 1st Season ---</b><br/>
<a href=\"images/value4-file.jpg\">value4-name</a><br/>

<b>--- 1st Season ---</b><br/>
<a href=\"images/value5-file.jpg\">value5-name</a><br/>

<b>--- 2nd Season ---</b><br/>
<a href=\"images/value6-file.jpg\">value6-name</a><br/>

<b>--- 2nd Season ---</b><br/>
<a href=\"images/value7-file.jpg\">value7-name</a><br/>
What I was expecting was:

<b>--- Pre-Season ---</b><br/>
<a href=\"images/value1-file.jpg\">value1-name</a><br/>
<a href=\"images/value2-file.jpg\">value2-name</a><br/>
<a href=\"images/value3-file.jpg\">value3-name</a><br/>

<b>--- 1st Season ---</b><br/>
<a href=\"images/value4-file.jpg\">value4-name</a><br/>
<a href=\"images/value5-file.jpg\">value5-name</a><br/>

<b>--- 2nd Season ---</b><br/>
<a href=\"images/value6-file.jpg\">value6-name</a><br/>
<a href=\"images/value7-file.jpg\">value7-name</a><br/>
Thank you for all your help in advance...
(sorry if this doesn't make sense - the past 12 straight hours have been trying to figure this out)
Jul 17 '05 #1
2 2149
Hi,

the only problem you have to solve, ist t oremember the last value of the
variable $session.

Just try this (untested):

$lastseason = ""; // remember last value of season

while ($newArray = mysql_fetch_array($result)) {

$id = $newArray['id'];
$season = $newArray['season'];
$file = $newArray['file'];
$name = $newArray['name'];
$history = $newArray['history'];
$view = $newArray['view'];

if($season != $lastseason){

switch($season){ // better than millions of ifs
case "0":
print "<b>--- Pre-Season ---</b><br/>";
break;
case "1";
print "<b>--- 1st Season ---</b><br/>";
break;
case "2";
print "<b>--- 2nd Season ---</b><br/>";
break;
case "3";
print "<b>--- 3rd Season ---</b><br/>";
break;
default:
print "<b>--- " . $season . "th Season ---</b><br/>";
break;
}

}
echo "<a href=\"images/$file.jpg\">$name</a><br/>\n";
$lastseason = $season;
}

hope this works as you expect!

Greetings
Jul 17 '05 #2
I noticed that Message-ID: <Znr6d.36684$aW5.23906@fed1read07> from Adam
Carolla contained the following:
Thank you for all your help in advance...
(sorry if this doesn't make sense - the past 12 straight hours have been trying to figure this out)


I think I'd do it like this

Run a query to determine the number of distinct seasons

This should give you an array of seasons to work with.

For each season run a separate query and list the results

There are probably more efficient ways, but that would work.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1613
by: Leszek | last post by:
Hi. Could you help solve the problem: i have a file that has two includes: //my script <?php include(.'/prog1.php'); include(.'/prog2.php'); ?>
6
1611
by: joe | last post by:
I have a system where include files puts generated HTML into a variable ( $output ). In one of the pages I have a function that executes SQL queries and return nice arrays. The command to...
14
2647
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
25
3085
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
2
2731
by: sakat | last post by:
<?php $dbhost = 'unix.lsbu.ac.uk'; $dbuser = 'lrc3'; $dbpass = 'dietdft_'; $dbname = 'lrc3'; // This is an example open a db $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error...
15
5959
Markus
by: Markus | last post by:
What i want to do: Get urls from the database and echo them out into a multiple columned table i.e. 4 pictures per row (recently uploaded table) MY problem is: I have, in my MySQL database,...
3
1517
by: robin1983 | last post by:
I have a problem while loop of the following program. The problem is that, it showing the output that i wished to show, but the other remaining HTML portion afer the while loop is not showing in my...
5
3465
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() -...
3
2196
by: redcodeheaven | last post by:
Hello my teacher gave me an exercise to enter my name and 2 numbers the output must show the sum and the product of these 2 numbers and keep repeating the same procedure using a while loop till i...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.