RE: [PHP] looping through a database

2008-06-17 Thread Ford, Mike
On 16 June 2008 21:58, Richard Kurth advised:

 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
 tdThis is the file/td
 tdDelete/td
 /tr
 }else{
 tr
 tdFile1/td
 td/td
 tdAdd/td
 /tr
 }
 
 }

Well, first of you need a few ?php ? tags to make this legal:

  if ($row[number]==1) {
  ?
  tr
  td File 1/td
  tdThis is the file/td
  tdDelete/td
  /tr
  ?php
  }else{
  ?
  tr
  tdFile1/td
  td/td
  tdAdd/td
  /tr
  ?php
  }
  
  }

Of course, some people frown on this and prefer other techniques such as
echo-ing the HTML, or assembling it into a variable which gets echoed at
the end -- but whatever floats your boat...!!

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] looping through a database

2008-06-16 Thread Wolf

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
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/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 = PSomething 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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] looping through a database

2008-06-16 Thread Richard Kurth

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
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/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 = PSomething 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());

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] looping through a database

2008-06-16 Thread Wolf

Richard Kurth wrote:

Wolf wrote:

Richard Kurth wrote:

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
tdThis is the file/td
tdDelete/td
/tr
}else{
tr
tdFile1/td
td/td
tdAdd/td
/tr
}

}



What is the query being executed?

!-- SNIP --




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());


That still pretty much tells me nothing.

Does your table named table exist?
Does your script connect or error?
What DOES output to your screen?
Does the schema for your table contain numbers?

What happens when you use $row['number']?

Or are you just hoping for someone to write your code?

As written, your code will fail due to having PHP interspersed with HTML 
code.  As such, you either need to echo or exit out of the PHP areas and 
then continue.


Wolf


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] looping through a database

2008-06-16 Thread paragasu
i am not sure what u want to do, for this case you need to tell us
about your database table
structure. i quess you have table like this.. assume the table name is
table1 and there are ten
column in it file1..file10 respectively

|table1 |
|member_id |
|file1|
|file2|
|file3|
|   :  |
|file10  |

while($row =  mysql_fecth_array($sql_result))
{
  echo display_file($row['file1']);
  echo display_file($row['file2']);
  :
  echo display_file($row['file10']);

}

function display_file($filename)
{
   if file not exist or null etc
  return   add file here link
  else
  return  display file, delete file

}

this is the idea. of course maybe not what you want, unless you can tell us what
really you want to do or what you got..

On 6/17/08, Wolf [EMAIL PROTECTED] wrote:
 Richard Kurth wrote:
 Wolf wrote:
 Richard Kurth wrote:
 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
 tdThis is the file/td
 tdDelete/td
 /tr
 }else{
 tr
 tdFile1/td
 td/td
 tdAdd/td
 /tr
 }

 }


 What is the query being executed?
 !-- SNIP --


 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());

 That still pretty much tells me nothing.

 Does your table named table exist?
 Does your script connect or error?
 What DOES output to your screen?
 Does the schema for your table contain numbers?

 What happens when you use $row['number']?

 Or are you just hoping for someone to write your code?

 As written, your code will fail due to having PHP interspersed with HTML
 code.  As such, you either need to echo or exit out of the PHP areas and
 then continue.

 Wolf


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php