Php and mysql can someone help me out?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toddkjr
Forum Newbie
Posts: 3
Joined: Tue Sep 27, 2005 11:12 pm

Php and mysql can someone help me out?

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
toddkjr
Forum Newbie
Posts: 3
Joined: Tue Sep 27, 2005 11:12 pm

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

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
toddkjr
Forum Newbie
Posts: 3
Joined: Tue Sep 27, 2005 11:12 pm

Got it!!!

Post by toddkjr »

Thanx makes alot of sense..
Post Reply