Page 1 of 1

Refining MySQL query as script executes

Posted: Tue Jul 05, 2005 12:44 pm
by bb
I have a small application that categorizes information from a numerical field.

Currently I have nearly 30 database queries each one selecting a different category.

This creates quite a mass of unnecessary code because I am repeating variable definitions and conditional logic for each query.

What I would like to do is have one query that selects the entire table then echo the results broken up into categories separately, because the result is an HTML table and each category has a unique section header.

What would be great is to have it be something like "echo where category = 1"

Thanks in advance to anyone who has any ideas

my work so far for one of the categories:

Code: Select all

<?php
	$linkID = @mysql_connect("location", "user", "password") or die("could not connect");
	@mysql_select_db("fundingopportunities") or die("Could not select");
//Category 1 Agriculture	
	$query = 'SELECT * FROM `opportunities` WHERE `category` = 1 ORDER BY `dateadded` DESC;';
	$result = mysql_query($query);
	while($row = mysql_fetch_assoc($result)) {
	$program = $row['program'];
	$description = $row['description'];
	$funder = $row['funder'];
	$duedate = $row['duedate'];
	$nofa = $row['nofa'];
	$guide = $row['guide'];
	$application = $row['application'];
	
//Tests if there is a NOFA, if so prints NOFA in the html else it prints nothing	
		if (strlen($nofa) > 0) {
		$nofavalue = "\n\r		<a href=\"http://www.mywebsite.com/files/$nofa\">NOFA</a><br /><br />";
	} else {
		$nofavalue .= "";
	}
	
//Tests if there is a Guide, if so prints Guide in the html else it prints nothing		
		if (strlen($guide) > 0) {
		$guidevalue = "\n\r		<a href=\"http://www.mywebsite.com/files/$guide\">Guide</a><br /><br />";
	} else {
		$guidevalue .= "";
	}
//Tests if there is a application, if so prints Application in the html else it prints nothing		
		if (strlen($application) > 0) {
		$applicationvalue = "\n\r		<a href=\"http://www.mywebsite.com/files/$application\">Application</a><br /><br />";
	} else {
		$applicationvalue .= "";
	}	
//Prints Agriculture Section	
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
?>

Posted: Tue Jul 05, 2005 4:25 pm
by pickle
What you've got seems pretty straightforward. Just make the actual category id (in your example, '1'), dynamic based on form input. The elements returned in the query will be the same regardless of the query, so you can write the result set handler (in this example, all your if/else statements and table output) once and it will apply to all categories.

Posted: Tue Jul 05, 2005 5:29 pm
by bb
Sorry if I wasn't clear, but this page does not have any dynamic elements. It displays all categories at once but broken up into categories.

for example

Category 1 (embeded HTML)
cat 1 description (from database)
cat 1 files (from database)

Category 2 (embeded HTML)
cat 2 description (from database)
cat 2 files (from database)


What the full code looks like is what you see in my first post but repeated 30 times with embeded HTML table headers

so after

Code: Select all

$query = 'SELECT * FROM `opportunities` WHERE `category` = 1 ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    $program = $row['program'];

//etc...
comes

Code: Select all

$query2 = 'SELECT * FROM `opportunities` WHERE `category` = 2 ORDER BY `dateadded` DESC;';
    $result2 = mysql_query($query2);
    while($row = mysql_fetch_assoc($result2)) {
    $program2 = $row['program'];
//etc...
repeated 30 times ($query3, $query4 etc...)
it seems like this could be greatly reduced if I could either create a table heading each time the category changed or specify what category it should select from as the script goes on.

It does *work* the way it is now, I'm just looking for a more elegant solution to speed up load time

Posted: Tue Jul 05, 2005 6:06 pm
by pickle
Ah, ok - gotcha.

You're right - the best way is to get it all in one big query. Sort it by category as well.

Then, you can loop through the result set and when the category changes, output a header:

Code: Select all

$current_category = -1;
while(looping through each row in the result set)
{
  if(category in row != $current_category)
  {
    output_header()
  }
  output_row();
  $current_category = category in row;
}

Posted: Wed Jul 06, 2005 12:03 am
by bb
Thanks for all your help so far, but I can't quite get your example to work (still learning PHP... slowly)

I see where you are going with that script but any clarification with how I would incorporate that with my own script would be awesome

thanks again.

Posted: Wed Jul 06, 2005 10:38 am
by pickle
Well, your query could be something like: "SELECT * FROM opportunities ORDER BY category DESC, dateadded DESC;".

Then, loop through the result set. During each iteration of the loop, do all your assignments (such as $program = $row['program'], etc.), do your "if(strlen($nofa) > 0)" type logic, and output the table row.

After the loop is done, close the table and you're done!

Posted: Fri Jul 08, 2005 1:24 am
by bb
man... I guess I need to learn more PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.lt)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td&gt;$funder&lt;/td&gt;
&lt;td>$duedate</td&gt;
&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n&quote;;
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.o code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.nd could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your hile($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td&gt;$funder&lt;/td&gt;
&lt;td&gt;$duedate&lt;/td&gt;
go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td&gn your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalueeed to learn more PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
ng, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guidevalue$applicatio84]
$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\d holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	&ding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.ent_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td&gt;
&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n";
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.sking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td&aly hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	&ampu tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks` DESC;';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td&gt;$funder&lt;/td&gt;
&lt;td&gt;$duedate&lt;/td&gt;
&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n&quote;;
}
$current_category = category in row;


I know your example was just psuedo code, but I;amp;lt;/td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td& while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td& really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category M `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
&amp
$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was jmp;amp;lt;/tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
}
$current_category = category in row;
[/php:1:81ith the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue&lt;/td>
</tr>\n";
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.ind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n&quote;;
	}	
PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td&gt * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td&ally hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
&a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&ame PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$gui learn more PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n&quote;;
	}	
$current_category = category in row;
I know your example was just psuedo code, but hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&amp code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guidevalue$applicationvalue&lt;/td&gt;
&lt;/tr&gt;\n&quote;;
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to chp]
$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td&gt;$funder&lt;/td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td&gt;
&lt;/tr&gt;\n&quote;;
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.eed to learn more PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on. in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.eed to learn more PHP, but I'm having a really hard time plugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again rry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know you]
$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td>
</tr&g
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on. to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&aplugging in your code. Sorry if I'm asking for too much hand holding, but if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
	echo &quote;	
&lt;tr&gt;
	&lt;td&gt;$program&lt;/td&gt;
	&lt;td&gt;$description&lt;/td&gt;
	&lt;td&gt;$funder&lt;/td&gt;
	&lt;td&gt;$duedate&lt;/td&gt;
	&lt;td&gt;$nofavalue$guit if you wouldn't mind could you tell me where I am going wrong?

Code: Select all

$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)) {
    //All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
    if(category in row != $current_category){
//echo the header with the correct category title    
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
	echo "	
<tr>
	<td>$program</td>
	<td>$description</td>
	<td>$funder</td>
	<td>$duedate</td>
	<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
	}	
$current_category = category in row;
I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.DESC;';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '&lt;tr&gt;
&lt;td&gt;$category&lt;/td&gt;
&lt;/tr&gt;';
}
//echo the results
echo &quote;
&lt;tr&gt;
&lt;td&gt;$program&lt;/td&gt;
&lt;td&gt;$description&lt;/td&gt;
&lt;td&gt;$funder&lt;/td&gt;
&lt;td&gt;$duedate&lt;/td&gt;
&amp
$query = 'SELECT * FROM `opportunities` ORDER BY `dateadded` DESC;';
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
//All of my SQL variables and conditional logic would go here as above.

//your if test to see if category in row !=$current_category
if(category in row != $current_category){
//echo the header with the correct category title
echo '<tr>
<td>$category</td>
</tr>';
}
//echo the results
echo "
<tr>
<td>$program</td>
<td>$description</td>
<td>$funder</td>
<td>$duedate</td>
<td>$nofavalue$guidevalue$applicationvalue</td>
</tr>\n";
}
$current_category = category in row;


I know your example was just psuedo code, but I'm having a hard time adapting it. Thanks again for all your help. Sorry I'm slow to catch on.

Posted: Fri Jul 08, 2005 9:50 am
by pickle
Before your while loop, you need to declare $current_category.

In the if statement then, check $current_category against $row['category'] (rather than category in row (which really should be a variable)).

You're then going to need to transfer all the $row elements to your variables (such as $category, $program, etc). You did this step originally.

Finally, set $current_category to $row['category'] at the end of the while loop. You've done this (kind of) already, but "category in row" is going to give you errors, so just change that to $row['category'].

Posted: Fri Jul 08, 2005 1:10 pm
by bb
ahh i see i was having trouble trying to figure out what you meant by "category in row"

Thank you so much, you got it to work.

Posted: Fri Jul 08, 2005 2:55 pm
by pickle
Good to hear