Re: [PHP] Probably basic but seems advanced to me, PHP/SQL generation.

2002-02-28 Thread Bas Jobsen

while ($row=mysql_fetch_row($result))
{
echo 1 $row[0]
for($x=1; $xcount($row); $x++) 
if(!empty($row[$x])) 
{
echo $x+1;
echo  .$row[$x];
}
}


Op donderdag 28 februari 2002 14:40, schreef DARCY,MATTHEW 
(Non-HP-UnitedKingdom,ex2):
 Hello PHP'ers.

 First of all - scince joining this list I have got some great help and it
 is really helping my build me site so a BIG thank you to all.

 Now back to the help..

 I have a table with cols, and say 20 rows in this table.


 col: 12   3   4   5   6   7   8   9   10
 row: notnull  stuff   4   testblahduh dud
  notnull  stufblahblahtestduh dud


 as you can see col 1 is ALWAYS populated as it is notnull the rest
 are/aren't populated.

 I want to search on this table (in real life it has hundreds of rows)

 so select * from testable;

 I then want to generate a HTML table in php DEPENDING on how many rows are
 populated

 so for example the table for row 1 would look like this

 1 notnull
 4 stuff
 5 4
 7 test
 8 blah
 9 duh
 10dud

 while row 2 would look

 1 notnull
 3 stuff
 5 blah
 6 blah
 7 blah
 9 duh
 10dud

 I am thinking I would have to do some sort of while loop on an array of all
 fields, but how would I single out the null fields in the array and
 generate everything else 

 thanks

 Matt

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




RE: [PHP] Probably basic but seems advanced to me, PHP/SQL generation.

2002-02-28 Thread DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2)


Hi Baz,

Thanks for mailing back, would you care to explain this a little more so I
understand whats going on and how to use it

I can see that you are fetching the results of select * from - into and
array. and while there is records in the array you are echoing data, but I
am not sure on whats going on, and how to generate the table from these
results.

thanks, 

Matt.


-Original Message-
From: Bas Jobsen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 28, 2002 1:59 PM
To: DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2); [EMAIL PROTECTED]
Subject: Re: [PHP] Probably basic but seems advanced to me, PHP/SQL
generation.


while ($row=mysql_fetch_row($result))
{
echo 1 $row[0]
for($x=1; $xcount($row); $x++) 
if(!empty($row[$x])) 
{
echo $x+1;
echo  .$row[$x];
}
}


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




Re: [PHP] Probably basic but seems advanced to me, PHP/SQL generation.

2002-02-28 Thread Jason Cox

Matt,

Perhaps I could elaborate for you.  When you run a mysql query through php
the function returns a result variable.  This is not unlike a cursor that
you would use in oracle programming.  This result set contains all the rows
returned by the query but you must take it a step further to gather the
values from the result set.  A call to mysql_fetch_row() will return a
different row from the result set each time it is called until it is
empty.  It's commonly placed in a while() loop so the function will continue
to be called until mysql_fetch_row() returns false.  For each interation of
the loop an array is returned into $row my mysql_fetch_result() that is
indexed numerically by row number.  These row numbers will match the order
of the columns as specified in your select clause or by column order in the
database if you did a select *.  An alternative to mysql_fetch_row would be
mysql_fetch_array or mysql_fetch_assoc.  These functions return an array as
well but it is associative meaning the elements can be accessed by column
name.  For example: $row['name'].  I personally prefer this method because
it makes the code a bit easier to read and I don't have to remember the
order of columns.  The numerically indexed arrays are handy for dumping
table structures though because you can loop off the array size and don't
have to change your code if you change your database schema.  This latter
technique is the one used by Bas in his example.

Hope that clears things up a bit.

Jason Cox
- Original Message -
From: DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2) [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, February 28, 2002 6:55 AM
Subject: RE: [PHP] Probably basic but seems advanced to me, PHP/SQL
generation.



 Hi Baz,

 Thanks for mailing back, would you care to explain this a little more so I
 understand whats going on and how to use it

 I can see that you are fetching the results of select * from - into and
 array. and while there is records in the array you are echoing data, but I
 am not sure on whats going on, and how to generate the table from these
 results.

 thanks,

 Matt.


 -Original Message-
 From: Bas Jobsen [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, February 28, 2002 1:59 PM
 To: DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2); [EMAIL PROTECTED]
 Subject: Re: [PHP] Probably basic but seems advanced to me, PHP/SQL
 generation.


 while ($row=mysql_fetch_row($result))
 {
 echo 1 $row[0]
 for($x=1; $xcount($row); $x++)
 if(!empty($row[$x]))
 {
 echo $x+1;
 echo  .$row[$x];
 }
 }


 --
 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