Page 1 of 1

Php and mysql can someone help me out?

Posted: Tue Sep 27, 2005 11:20 pm
by toddkjr
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php
   require('db_connect.php');
$db_object->setFetchMode(DB_FETCHMODE_ASSOC);

   $result = mysql_query( "SELECT on_sale FROM productinfo" )
	     or die("SELECT Error: ".mysql_error());
   $result1 = mysql_query( "SELECT product_image FROM productinfo" )
	     or die("SELECT Error: ".mysql_error());
  
echo "<table border=\"1\">"; 
while ($get_query = mysql_fetch_row($result)){
	while ($get_query1 = mysql_fetch_row($result1)){ 
	echo "<tr>"; 
	foreach ($get_query as $rows){
		
		foreach ($get_query1 as $rows1){
			if ($rows == 1) {
				echo "<td>$rows1</td>";
			}
		}
	}
		
	} 
	echo "</tr>"; 
} 
echo "</table>"; 



$db_object->disconnect();
?>
i cant seem to figure out why this wont work i am trying to compare two rows in my data base like......example my tables values are 'john' 'jane'
cool 1
nice 0
how do i make so that if jane=1 then echo cool then go to the next row and check the same thing??


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Sep 27, 2005 11:30 pm
by feyd
you'll need to either use a seek() to get back to the initial record in the inner loop, or (recommended) you cache the results of the inner loop first into an array which you can endlessly loop over without much issue (RAM providing)

Thank you....Do you think you could show me a basic example?

Posted: Tue Sep 27, 2005 11:34 pm
by toddkjr
It would help if you gave me a basic example i would appreciate it....if not thanks anyways......you mean like use a tempvar or something like that?

Posted: Wed Sep 28, 2005 12:12 am
by feyd
the first path referred to mysql_data_seek().

The second, to cache the data you create a loop, just like any other mysql result set loop, but save each record into an array. I couldn't find an example quickly, so here's the basic idea behind caching:

Code: Select all

$rows = array();
while($rows[] = mysql_fetch_assoc($result));
array_pop($rows);




print_r($rows);

Got it!!!

Posted: Wed Sep 28, 2005 12:23 am
by toddkjr
Thanx makes alot of sense..