Forum Moderators: coopster

Message Too Old, No Replies

html form + mysql + multiple records > Phatzo

html form returning multiple records from mysql

         

Phatzo

11:50 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



Howdy guys! Im new to webmasterworld.com and new to code forums generally, so lemme know if Im bungling my posting :)

Ok - Im a noob, unashamedly POOR at php & mysql haha. I've got a form that a user can submit to a mysql database (flat, only 1 table). Cool. I can list all records, filter & sort them blah blah blah (cos I've been googling like mad on this stuff!).

Here's the tricky part: I then want to be able to access a different page, and look at all the new submissions, and process all "new" data (ie: data I haven't previously processed). For each record I check, I want to "process", creating a separate text file for each record. For each record, I need to return the name of each field in the record, and the value of each field, delimited with some text (basically, writing a specific XML file).

The closest I've been able to come is this:


$query = "SELECT * FROM $table WHERE SubID = 1 OR SubID = 2";
$result = mysql_query($query) or die(mysql_error());
$record = mysql_fetch_assoc($result);
while (list($key, $value) = each ($record)) {
if ($key!= "SubID" && $key!= "ProducedTF") {
echo "\n{dbFieldName=".$key."}\n<br>&nbsp;&nbsp;&nbsp;&nbsp;{FieldValue}".$value."{/FieldValue}\n<br>{/dbFieldName}\n<BR>";
}
}

In the code above, I have skipped all the database selection stuff...SubID is the mysql ID field. The output will eventually be a var that gets written to a text file, but for now I'd just be happy to print it on a page!

The above code will print a SINGLE record exactly how I want it, but for the life of me, Im too thick to make it do it for multiple records.

Any help would be greatly appreciated. And thanks for letting a noob like me in :)

Cheers,
Phatzo

StupidScript

12:21 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome, Phatzo!

Try modifying your list() loop:

while (list($key, $value) = mysql_fetch_row($result)) {

While accessing the associative array may seem to be the same idea as accessing each row in the array, they're a little different.

Phatzo

12:35 am on Mar 2, 2006 (gmt 0)

10+ Year Member



Thanks for the reply! Tried it, no soap :(

Your code produced:

{dbFieldName=2}
{FieldValue}0{/FieldValue}
{/dbFieldName}

My code (originally) produced:

{dbFieldName=PLF_Name_TE}
{FieldValue}Company Pty Ltd{/FieldValue}
{/dbFieldName}
{dbFieldName=PLF_ACN_MC}
{FieldValue}ACN{/FieldValue}
{/dbFieldName}
etc...rinse & repeat for each field in record (currently 11 fields in each record)

Thanks for the help, I'll keep trying and keep reading the php manual, which presumes I have a clue haha.