Re: looping through a database

From: Date: Tue, 17 Jun 2008 00:31:24 +0000
Subject: Re: looping through a database
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-275461@lists.php.net to get a copy of this message
Wolf wrote:
Richard Kurth wrote:
I am looping through a database of files that are numbers 1 through 10 if number 1 is in the database I what to print out the first table below if it is not then print the else section below. Then loop through the database to see if 2 through 10 are there and do the same thing. Of course what I am doing does not work. Should I move it all to an array and then loop through it. Or use a foreach loop. Could you please give me an idea where to start looking while($row=mysql_fetch_array($sql_result)){ if ($row["number"]==1) { <tr> <td> File 1</td> <td>This is the file</td> <td>Delete</td> </tr> }else{ <tr> <td>File1</td> <td></td> <td>Add</td> </tr> } }
What is the query being executed? Seriously, this needs more information. On the upside, it LOOKS like it should work, however... Here's what I use to get 1 random quote from a table I have: ------------------------------------------ $query="select quote from quotes where id=$id"; $query_res = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($query_res) < 1) { //print message $display_block = "<P>Something blew up.</P>"; } else { //get info and build Quote display $Quote = mysql_fetch_array($query_res); echo $Quote['quote']; } It could be as simple as the " not working where you really need ' but that depends on what/how you are doing things. Wolf This is the query being executed
$sql = "SELECT * FROM table WHERE members_id =" . $_SESSION["members_id"]; $sql_result = mysql_query($sql) or die(mysql_error());

« previous php.general (#275461) next »